mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 13:44:32 +02:00
send a pick ray with HFActionEvent, not x,y
This commit is contained in:
parent
1707025bd0
commit
8d6b041758
7 changed files with 26 additions and 21 deletions
|
@ -177,6 +177,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
_packetsPerSecond(0),
|
_packetsPerSecond(0),
|
||||||
_bytesPerSecond(0),
|
_bytesPerSecond(0),
|
||||||
_nodeBoundsDisplay(this),
|
_nodeBoundsDisplay(this),
|
||||||
|
_cameraScriptableObject(&_myCamera, &_viewFrustum),
|
||||||
_previousScriptLocation(),
|
_previousScriptLocation(),
|
||||||
_applicationOverlay(),
|
_applicationOverlay(),
|
||||||
_runningScriptsWidget(NULL),
|
_runningScriptsWidget(NULL),
|
||||||
|
@ -1116,7 +1117,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
case Qt::Key_Space: {
|
case Qt::Key_Space: {
|
||||||
if (!event->isAutoRepeat()) {
|
if (!event->isAutoRepeat()) {
|
||||||
// this starts an HFActionEvent
|
// this starts an HFActionEvent
|
||||||
HFActionEvent startActionEvent(HFActionEvent::startType(), getViewportCenter());
|
PickRay actionRay;
|
||||||
|
|
||||||
|
HFActionEvent startActionEvent(HFActionEvent::startType(), actionRay);
|
||||||
sendEvent(this, &startActionEvent);
|
sendEvent(this, &startActionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1207,7 +1210,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
|
||||||
case Qt::Key_Space: {
|
case Qt::Key_Space: {
|
||||||
if (!event->isAutoRepeat()) {
|
if (!event->isAutoRepeat()) {
|
||||||
// this ends the HFActionEvent
|
// this ends the HFActionEvent
|
||||||
HFActionEvent endActionEvent(HFActionEvent::endType(), getViewportCenter());
|
HFActionEvent endActionEvent(HFActionEvent::endType(), Application::getInstance()->getCamera()->getPickRay());
|
||||||
sendEvent(this, &endActionEvent);
|
sendEvent(this, &endActionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1301,7 +1304,8 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// nobody handled this - make it an action event on the _window object
|
// nobody handled this - make it an action event on the _window object
|
||||||
HFActionEvent actionEvent(HFActionEvent::startType(), event->localPos());
|
HFActionEvent actionEvent(HFActionEvent::startType(),
|
||||||
|
_cameraScriptableObject.computePickRay(event->x(), event->y()));
|
||||||
sendEvent(this, &actionEvent);
|
sendEvent(this, &actionEvent);
|
||||||
|
|
||||||
} else if (event->button() == Qt::RightButton) {
|
} else if (event->button() == Qt::RightButton) {
|
||||||
|
@ -1335,7 +1339,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fire an action end event
|
// fire an action end event
|
||||||
HFActionEvent actionEvent(HFActionEvent::endType(), event->localPos());
|
HFActionEvent actionEvent(HFActionEvent::endType(),
|
||||||
|
_cameraScriptableObject.computePickRay(event->x(), event->y()));
|
||||||
sendEvent(this, &actionEvent);
|
sendEvent(this, &actionEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3846,9 +3851,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features
|
scriptEngine->setAvatarData(_myAvatar, "MyAvatar"); // leave it as a MyAvatar class to expose thrust features
|
||||||
scriptEngine->setAvatarHashMap(&_avatarManager, "AvatarList");
|
scriptEngine->setAvatarHashMap(&_avatarManager, "AvatarList");
|
||||||
|
|
||||||
CameraScriptableObject* cameraScriptable = new CameraScriptableObject(&_myCamera, &_viewFrustum);
|
scriptEngine->registerGlobalObject("Camera", &_cameraScriptableObject);
|
||||||
scriptEngine->registerGlobalObject("Camera", cameraScriptable);
|
|
||||||
connect(scriptEngine, SIGNAL(finished(const QString&)), cameraScriptable, SLOT(deleteLater()));
|
|
||||||
|
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||||
scriptEngine->registerGlobalObject("SpeechRecognizer", Menu::getInstance()->getSpeechRecognizer());
|
scriptEngine->registerGlobalObject("SpeechRecognizer", Menu::getInstance()->getSpeechRecognizer());
|
||||||
|
|
|
@ -287,8 +287,6 @@ public:
|
||||||
PointShader& getPointShader() { return _pointShader; }
|
PointShader& getPointShader() { return _pointShader; }
|
||||||
FileLogger* getLogger() { return _logger; }
|
FileLogger* getLogger() { return _logger; }
|
||||||
|
|
||||||
QPointF getViewportCenter() const
|
|
||||||
{ return QPointF(_glWidget->getDeviceWidth() / 2.0f, _glWidget->getDeviceHeight() / 2.0f); }
|
|
||||||
glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); }
|
glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); }
|
||||||
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
|
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
|
||||||
NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; }
|
NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; }
|
||||||
|
@ -599,6 +597,7 @@ private:
|
||||||
std::vector<VoxelFade> _voxelFades;
|
std::vector<VoxelFade> _voxelFades;
|
||||||
QReadWriteLock _voxelFadesLock;
|
QReadWriteLock _voxelFadesLock;
|
||||||
ControllerScriptingInterface _controllerScriptingInterface;
|
ControllerScriptingInterface _controllerScriptingInterface;
|
||||||
|
CameraScriptableObject _cameraScriptableObject;
|
||||||
QPointer<LogDialog> _logDialog;
|
QPointer<LogDialog> _logDialog;
|
||||||
QPointer<SnapshotShareDialog> _snapshotShareDialog;
|
QPointer<SnapshotShareDialog> _snapshotShareDialog;
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; }
|
void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; }
|
||||||
void setScale(const float s) { _scale = s; }
|
void setScale(const float s) { _scale = s; }
|
||||||
|
|
||||||
|
PickRay getPickRay() const { return PickRay(getPosition(), getRotation() * IDENTITY_FRONT); }
|
||||||
|
|
||||||
glm::vec3 getPosition() const { return _position + _hmdPosition; }
|
glm::vec3 getPosition() const { return _position + _hmdPosition; }
|
||||||
glm::quat getRotation() const { return _rotation * _hmdRotation; }
|
glm::quat getRotation() const { return _rotation * _hmdRotation; }
|
||||||
const glm::vec3& getHmdPosition() const { return _hmdPosition; }
|
const glm::vec3& getHmdPosition() const { return _hmdPosition; }
|
||||||
|
@ -66,7 +68,7 @@ public:
|
||||||
const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }
|
const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }
|
||||||
const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; }
|
const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; }
|
||||||
float getScale() const { return _scale; }
|
float getScale() const { return _scale; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modeUpdated(CameraMode newMode);
|
void modeUpdated(CameraMode newMode);
|
||||||
|
|
||||||
|
|
|
@ -129,9 +129,7 @@ void JoystickScriptingInterface::update() {
|
||||||
: HFActionEvent::endType();
|
: HFActionEvent::endType();
|
||||||
|
|
||||||
// global action events fire in the center of the screen
|
// global action events fire in the center of the screen
|
||||||
QPointF centerPoint = Application::getInstance()->getViewportCenter();
|
HFActionEvent actionEvent(actionType, Application::getInstance()->getCamera()->getPickRay());
|
||||||
HFActionEvent actionEvent(actionType, centerPoint);
|
|
||||||
|
|
||||||
qApp->sendEvent(qApp, &actionEvent);
|
qApp->sendEvent(qApp, &actionEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
|
|
||||||
#include "HFActionEvent.h"
|
#include "HFActionEvent.h"
|
||||||
|
|
||||||
HFActionEvent::HFActionEvent(QEvent::Type type, const QPointF& localPosition) :
|
HFActionEvent::HFActionEvent(QEvent::Type type, const PickRay& actionRay) :
|
||||||
HFMetaEvent(type),
|
HFMetaEvent(type),
|
||||||
localPosition(localPosition)
|
actionRay(actionRay)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,7 @@ QEvent::Type HFActionEvent::endType() {
|
||||||
|
|
||||||
QScriptValue HFActionEvent::toScriptValue(QScriptEngine* engine, const HFActionEvent& event) {
|
QScriptValue HFActionEvent::toScriptValue(QScriptEngine* engine, const HFActionEvent& event) {
|
||||||
QScriptValue obj = engine->newObject();
|
QScriptValue obj = engine->newObject();
|
||||||
obj.setProperty("x", event.localPosition.x());
|
obj.setProperty("actionRay", pickRayToScriptValue(engine, event.actionRay));
|
||||||
obj.setProperty("y", event.localPosition.y());
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,17 @@
|
||||||
#ifndef hifi_HFActionEvent_h
|
#ifndef hifi_HFActionEvent_h
|
||||||
#define hifi_HFActionEvent_h
|
#define hifi_HFActionEvent_h
|
||||||
|
|
||||||
#include "HFMetaEvent.h"
|
|
||||||
|
|
||||||
#include <qscriptengine.h>
|
#include <qscriptengine.h>
|
||||||
|
|
||||||
|
#include <RegisteredMetaTypes.h>
|
||||||
|
|
||||||
|
#include "HFMetaEvent.h"
|
||||||
|
|
||||||
class HFActionEvent : public HFMetaEvent {
|
class HFActionEvent : public HFMetaEvent {
|
||||||
public:
|
public:
|
||||||
HFActionEvent() {};
|
HFActionEvent() {};
|
||||||
HFActionEvent(QEvent::Type type, const QPointF& localPosition);
|
HFActionEvent(QEvent::Type type, const PickRay& actionRay);
|
||||||
|
|
||||||
static QEvent::Type startType();
|
static QEvent::Type startType();
|
||||||
static QEvent::Type endType();
|
static QEvent::Type endType();
|
||||||
|
@ -27,7 +30,7 @@ public:
|
||||||
static QScriptValue toScriptValue(QScriptEngine* engine, const HFActionEvent& event);
|
static QScriptValue toScriptValue(QScriptEngine* engine, const HFActionEvent& event);
|
||||||
static void fromScriptValue(const QScriptValue& object, HFActionEvent& event);
|
static void fromScriptValue(const QScriptValue& object, HFActionEvent& event);
|
||||||
|
|
||||||
QPointF localPosition;
|
PickRay actionRay;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(HFActionEvent)
|
Q_DECLARE_METATYPE(HFActionEvent)
|
||||||
|
|
|
@ -53,7 +53,8 @@ void qURLFromScriptValue(const QScriptValue& object, QUrl& url);
|
||||||
|
|
||||||
class PickRay {
|
class PickRay {
|
||||||
public:
|
public:
|
||||||
PickRay() : origin(0.0f), direction(0.0f) { }
|
PickRay() : origin(0.0f), direction(0.0f) { }
|
||||||
|
PickRay(const glm::vec3& origin, const glm::vec3 direction) : origin(origin), direction(direction) {}
|
||||||
glm::vec3 origin;
|
glm::vec3 origin;
|
||||||
glm::vec3 direction;
|
glm::vec3 direction;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue