send a pick ray with HFActionEvent, not x,y

This commit is contained in:
Stephen Birarda 2014-11-04 10:01:25 -08:00
parent 1707025bd0
commit 8d6b041758
7 changed files with 26 additions and 21 deletions

View file

@ -177,6 +177,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_packetsPerSecond(0),
_bytesPerSecond(0),
_nodeBoundsDisplay(this),
_cameraScriptableObject(&_myCamera, &_viewFrustum),
_previousScriptLocation(),
_applicationOverlay(),
_runningScriptsWidget(NULL),
@ -1116,7 +1117,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
case Qt::Key_Space: {
if (!event->isAutoRepeat()) {
// this starts an HFActionEvent
HFActionEvent startActionEvent(HFActionEvent::startType(), getViewportCenter());
PickRay actionRay;
HFActionEvent startActionEvent(HFActionEvent::startType(), actionRay);
sendEvent(this, &startActionEvent);
}
@ -1207,7 +1210,7 @@ void Application::keyReleaseEvent(QKeyEvent* event) {
case Qt::Key_Space: {
if (!event->isAutoRepeat()) {
// this ends the HFActionEvent
HFActionEvent endActionEvent(HFActionEvent::endType(), getViewportCenter());
HFActionEvent endActionEvent(HFActionEvent::endType(), Application::getInstance()->getCamera()->getPickRay());
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
HFActionEvent actionEvent(HFActionEvent::startType(), event->localPos());
HFActionEvent actionEvent(HFActionEvent::startType(),
_cameraScriptableObject.computePickRay(event->x(), event->y()));
sendEvent(this, &actionEvent);
} else if (event->button() == Qt::RightButton) {
@ -1335,7 +1339,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
}
// fire an action end event
HFActionEvent actionEvent(HFActionEvent::endType(), event->localPos());
HFActionEvent actionEvent(HFActionEvent::endType(),
_cameraScriptableObject.computePickRay(event->x(), event->y()));
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->setAvatarHashMap(&_avatarManager, "AvatarList");
CameraScriptableObject* cameraScriptable = new CameraScriptableObject(&_myCamera, &_viewFrustum);
scriptEngine->registerGlobalObject("Camera", cameraScriptable);
connect(scriptEngine, SIGNAL(finished(const QString&)), cameraScriptable, SLOT(deleteLater()));
scriptEngine->registerGlobalObject("Camera", &_cameraScriptableObject);
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
scriptEngine->registerGlobalObject("SpeechRecognizer", Menu::getInstance()->getSpeechRecognizer());

View file

@ -287,8 +287,6 @@ public:
PointShader& getPointShader() { return _pointShader; }
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()); }
NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; }
NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; }
@ -599,6 +597,7 @@ private:
std::vector<VoxelFade> _voxelFades;
QReadWriteLock _voxelFadesLock;
ControllerScriptingInterface _controllerScriptingInterface;
CameraScriptableObject _cameraScriptableObject;
QPointer<LogDialog> _logDialog;
QPointer<SnapshotShareDialog> _snapshotShareDialog;

View file

@ -53,6 +53,8 @@ public:
void setEyeOffsetOrientation(const glm::quat& o) { _eyeOffsetOrientation = o; }
void setScale(const float s) { _scale = s; }
PickRay getPickRay() const { return PickRay(getPosition(), getRotation() * IDENTITY_FRONT); }
glm::vec3 getPosition() const { return _position + _hmdPosition; }
glm::quat getRotation() const { return _rotation * _hmdRotation; }
const glm::vec3& getHmdPosition() const { return _hmdPosition; }
@ -66,7 +68,7 @@ public:
const glm::vec3& getEyeOffsetPosition() const { return _eyeOffsetPosition; }
const glm::quat& getEyeOffsetOrientation() const { return _eyeOffsetOrientation; }
float getScale() const { return _scale; }
signals:
void modeUpdated(CameraMode newMode);

View file

@ -129,9 +129,7 @@ void JoystickScriptingInterface::update() {
: HFActionEvent::endType();
// global action events fire in the center of the screen
QPointF centerPoint = Application::getInstance()->getViewportCenter();
HFActionEvent actionEvent(actionType, centerPoint);
HFActionEvent actionEvent(actionType, Application::getInstance()->getCamera()->getPickRay());
qApp->sendEvent(qApp, &actionEvent);
}

View file

@ -11,9 +11,9 @@
#include "HFActionEvent.h"
HFActionEvent::HFActionEvent(QEvent::Type type, const QPointF& localPosition) :
HFActionEvent::HFActionEvent(QEvent::Type type, const PickRay& actionRay) :
HFMetaEvent(type),
localPosition(localPosition)
actionRay(actionRay)
{
}
@ -30,8 +30,7 @@ QEvent::Type HFActionEvent::endType() {
QScriptValue HFActionEvent::toScriptValue(QScriptEngine* engine, const HFActionEvent& event) {
QScriptValue obj = engine->newObject();
obj.setProperty("x", event.localPosition.x());
obj.setProperty("y", event.localPosition.y());
obj.setProperty("actionRay", pickRayToScriptValue(engine, event.actionRay));
return obj;
}

View file

@ -12,14 +12,17 @@
#ifndef hifi_HFActionEvent_h
#define hifi_HFActionEvent_h
#include "HFMetaEvent.h"
#include <qscriptengine.h>
#include <RegisteredMetaTypes.h>
#include "HFMetaEvent.h"
class HFActionEvent : public HFMetaEvent {
public:
HFActionEvent() {};
HFActionEvent(QEvent::Type type, const QPointF& localPosition);
HFActionEvent(QEvent::Type type, const PickRay& actionRay);
static QEvent::Type startType();
static QEvent::Type endType();
@ -27,7 +30,7 @@ public:
static QScriptValue toScriptValue(QScriptEngine* engine, const HFActionEvent& event);
static void fromScriptValue(const QScriptValue& object, HFActionEvent& event);
QPointF localPosition;
PickRay actionRay;
};
Q_DECLARE_METATYPE(HFActionEvent)

View file

@ -53,7 +53,8 @@ void qURLFromScriptValue(const QScriptValue& object, QUrl& url);
class PickRay {
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 direction;
};