diff --git a/examples/controllerExample.js b/examples/controllerExample.js index 43eb516cee..47c8ed75e6 100644 --- a/examples/controllerExample.js +++ b/examples/controllerExample.js @@ -20,6 +20,7 @@ function checkController() { var numberOfTriggers = Controller.getNumberOfTriggers(); var numberOfSpatialControls = Controller.getNumberOfSpatialControls(); var controllersPerTrigger = numberOfSpatialControls / numberOfTriggers; + var triggerToggled=false; // this is expected for hydras if (numberOfTriggers == 2 && controllersPerTrigger == 2) { @@ -46,157 +47,140 @@ function checkController() { } } +// register the call back so it fires before each data send +Script.willSendVisualDataCallback.connect(checkController); + +function printKeyEvent(eventName, event) { + print(eventName); + print(" event.key=" + event.key); + print(" event.text=" + event.text); + print(" event.isShifted=" + event.isShifted); + print(" event.isControl=" + event.isControl); + print(" event.isMeta=" + event.isMeta); + print(" event.isAlt=" + event.isAlt); + print(" event.isKeypad=" + event.isKeypad); +} function keyPressEvent(event) { - print("keyPressEvent event.key=" + event.key); - print("keyPressEvent event.text=" + event.text); + printKeyEvent("keyPressEvent", event); - print("keyPressEvent event.isShifted=" + event.isShifted); - print("keyPressEvent event.isControl=" + event.isControl); - print("keyPressEvent event.isMeta=" + event.isMeta); - print("keyPressEvent event.isAlt=" + event.isAlt); - print("keyPressEvent event.isKeypad=" + event.isKeypad); - - - if (event.key == "A".charCodeAt(0)) { + if (event.text == "A") { print("the A key was pressed"); } - if (event.key == " ".charCodeAt(0)) { + if (event.text == " ") { print("the key was pressed"); } } -function mouseMoveEvent(event) { - print("mouseMoveEvent event.x,y=" + event.x + ", " + event.y); -} +function keyReleaseEvent(event) { + printKeyEvent("keyReleaseEvent", event); -function touchBeginEvent(event) { - print("touchBeginEvent event.x,y=" + event.x + ", " + event.y); + if (event.text == "A") { + print("the A key was released"); + } + if (event.text == " ") { + print("the key was pressed"); + } } -function touchUpdateEvent(event) { - print("touchUpdateEvent event.x,y=" + event.x + ", " + event.y); -} - -function touchEndEvent(event) { - print("touchEndEvent event.x,y=" + event.x + ", " + event.y); -} - -// register the call back so it fires before each data send -Script.willSendVisualDataCallback.connect(checkController); - // Map keyPress and mouse move events to our callbacks Controller.keyPressEvent.connect(keyPressEvent); -var KeyEvent_A = { - key: "A".charCodeAt(0), - text: "A", - isShifted: false, - isMeta: false -}; - -var KeyEvent_a = { - text: "a", - isShifted: false, - isMeta: false -}; - -var KeyEvent_a2 = { - key: "a".charCodeAt(0), - isShifted: false, - isMeta: false -}; - -var KeyEvent_a3 = { - text: "a" -}; - -var KeyEvent_A2 = { - text: "A" -}; - - -var KeyEvent_9 = { - text: "9" -}; - -var KeyEvent_Num = { - text: "#" -}; - -var KeyEvent_At = { - text: "@" -}; - -var KeyEvent_MetaAt = { - text: "@", - isMeta: true -}; - -var KeyEvent_Up = { - text: "up" -}; -var KeyEvent_Down = { - text: "down" -}; -var KeyEvent_Left = { - text: "left" -}; -var KeyEvent_Right = { - text: "right" -}; +Controller.keyReleaseEvent.connect(keyReleaseEvent); // prevent the A key from going through to the application -print("KeyEvent_A"); -Controller.captureKeyEvents(KeyEvent_A); - -print("KeyEvent_A2"); -Controller.captureKeyEvents(KeyEvent_A2); - -print("KeyEvent_a"); -Controller.captureKeyEvents(KeyEvent_a); - -print("KeyEvent_a2"); -Controller.captureKeyEvents(KeyEvent_a2); - -print("KeyEvent_a3"); -Controller.captureKeyEvents(KeyEvent_a3); - -print("KeyEvent_9"); -Controller.captureKeyEvents(KeyEvent_9); - -print("KeyEvent_Num"); -Controller.captureKeyEvents(KeyEvent_Num); - -print("KeyEvent_At"); -Controller.captureKeyEvents(KeyEvent_At); - -print("KeyEvent_MetaAt"); -Controller.captureKeyEvents(KeyEvent_MetaAt); - -print("KeyEvent_Up"); -Controller.captureKeyEvents(KeyEvent_Up); -print("KeyEvent_Down"); -Controller.captureKeyEvents(KeyEvent_Down); -print("KeyEvent_Left"); -Controller.captureKeyEvents(KeyEvent_Left); -print("KeyEvent_Right"); -Controller.captureKeyEvents(KeyEvent_Right); +Controller.captureKeyEvents({ text: "A" }); +Controller.captureKeyEvents({ key: "A".charCodeAt(0) }); // same as above, just another example of how to capture the key +Controller.captureKeyEvents({ text: " " }); +Controller.captureKeyEvents({ text: "@", isMeta: true }); +Controller.captureKeyEvents({ text: "page up" }); +Controller.captureKeyEvents({ text: "page down" }); +function printMouseEvent(eventName, event) { + print(eventName); + print(" event.x,y=" + event.x + ", " + event.y); + print(" event.button=" + event.button); + print(" event.isLeftButton=" + event.isLeftButton); + print(" event.isRightButton=" + event.isRightButton); + print(" event.isMiddleButton=" + event.isMiddleButton); + print(" event.isShifted=" + event.isShifted); + print(" event.isControl=" + event.isControl); + print(" event.isMeta=" + event.isMeta); + print(" event.isAlt=" + event.isAlt); +} +function mouseMoveEvent(event) { + printMouseEvent("mouseMoveEvent", event); +} +function mousePressEvent(event) { + printMouseEvent("mousePressEvent", event); +} + +function mouseReleaseEvent(event) { + printMouseEvent("mouseReleaseEvent", event); +} Controller.mouseMoveEvent.connect(mouseMoveEvent); +Controller.mousePressEvent.connect(mousePressEvent); +Controller.mouseReleaseEvent.connect(mouseReleaseEvent); +function printTouchEvent(eventName, event) { + print(eventName); + print(" event.x,y=" + event.x + ", " + event.y); + print(" event.isPressed=" + event.isPressed); + print(" event.isMoved=" + event.isMoved); + print(" event.isStationary=" + event.isStationary); + print(" event.isReleased=" + event.isReleased); + print(" event.isShifted=" + event.isShifted); + print(" event.isControl=" + event.isControl); + print(" event.isMeta=" + event.isMeta); + print(" event.isAlt=" + event.isAlt); + for (var i = 0; i < event.points.length; i++) { + print(" event.points[" + i + "].x.y:" + event.points[i].x + ", " + event.points[i].y); + } + +} + +function touchBeginEvent(event) { + printTouchEvent("touchBeginEvent", event); +} + +function touchUpdateEvent(event) { + printTouchEvent("touchUpdateEvent", event); +} + +function touchEndEvent(event) { + printTouchEvent("touchEndEvent", event); +} // Map touch events to our callbacks Controller.touchBeginEvent.connect(touchBeginEvent); Controller.touchUpdateEvent.connect(touchUpdateEvent); Controller.touchEndEvent.connect(touchEndEvent); -// disable the standard application for touch events -Controller.captureTouchEvents(); + +function wheelEvent(event) { + print("wheelEvent"); + print(" event.x,y=" + event.x + ", " + event.y); + print(" event.delta=" + event.delta); + print(" event.orientation=" + event.orientation); + print(" event.isLeftButton=" + event.isLeftButton); + print(" event.isRightButton=" + event.isRightButton); + print(" event.isMiddleButton=" + event.isMiddleButton); + print(" event.isShifted=" + event.isShifted); + print(" event.isControl=" + event.isControl); + print(" event.isMeta=" + event.isMeta); + print(" event.isAlt=" + event.isAlt); +} + +Controller.wheelEvent.connect(wheelEvent); function scriptEnding() { // re-enabled the standard application for touch events - Controller.releaseTouchEvents(); + Controller.releaseKeyEvents({ text: "A" }); + Controller.releaseKeyEvents({ key: "A".charCodeAt(0) }); // same as above, just another example of how to capture the key + Controller.releaseKeyEvents({ text: " " }); + Controller.releaseKeyEvents({ text: "@", isMeta: true }); + Controller.releaseKeyEvents({ text: "page up" }); + Controller.releaseKeyEvents({ text: "page down" }); } Script.scriptEnding.connect(scriptEnding); diff --git a/examples/rayPickExample.js b/examples/rayPickExample.js index 1c79d7cd6a..39dc910e78 100644 --- a/examples/rayPickExample.js +++ b/examples/rayPickExample.js @@ -20,6 +20,12 @@ function mouseMoveEvent(event) { if (intersection.intersects) { print("intersection voxel.red/green/blue=" + intersection.voxel.red + ", " + intersection.voxel.green + ", " + intersection.voxel.blue); + print("intersection voxel.x/y/z/s=" + intersection.voxel.x + ", " + + intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s); + print("intersection face=" + intersection.face); + print("intersection distance=" + intersection.distance); + print("intersection intersection.x/y/z=" + intersection.intersection.x + ", " + + intersection.intersection.y + ", " + intersection.intersection.z); } } diff --git a/libraries/script-engine/src/EventTypes.cpp b/libraries/script-engine/src/EventTypes.cpp index a642183eb4..faab830f72 100644 --- a/libraries/script-engine/src/EventTypes.cpp +++ b/libraries/script-engine/src/EventTypes.cpp @@ -9,18 +9,29 @@ // scripting engine #include +#include #include "EventTypes.h" -KeyEvent::KeyEvent() { - key = 0; - text = QString(""); - isShifted = false; - isMeta = false; - isControl = false; - isValid = false; +void registerEventTypes(QScriptEngine* engine) { + qScriptRegisterMetaType(engine, keyEventToScriptValue, keyEventFromScriptValue); + qScriptRegisterMetaType(engine, mouseEventToScriptValue, mouseEventFromScriptValue); + qScriptRegisterMetaType(engine, touchEventToScriptValue, touchEventFromScriptValue); + qScriptRegisterMetaType(engine, wheelEventToScriptValue, wheelEventFromScriptValue); } +KeyEvent::KeyEvent() : + key(0), + text(""), + isShifted(false), + isControl(false), + isMeta(false), + isAlt(false), + isKeypad(false), + isValid(false) +{ +}; + KeyEvent::KeyEvent(const QKeyEvent& event) { key = event.key(); @@ -73,43 +84,34 @@ KeyEvent::KeyEvent(const QKeyEvent& event) { text = "DELETE"; } else if (key == Qt::Key_Backspace) { text = "BACKSPACE"; + } else if (key == Qt::Key_Shift) { + text = "SHIFT"; + } else if (key == Qt::Key_Alt) { + text = "ALT"; + } else if (key == Qt::Key_Control) { + text = "CONTROL"; + } else if (key == Qt::Key_Meta) { + text = "META"; + } else if (key == Qt::Key_PageDown) { + text = "PAGE DOWN"; + } else if (key == Qt::Key_PageUp) { + text = "PAGE UP"; + } else if (key == Qt::Key_Home) { + text = "HOME"; + } else if (key == Qt::Key_End) { + text = "END"; + } else if (key == Qt::Key_Help) { + text = "HELP"; } } -MouseEvent::MouseEvent(const QMouseEvent& event) { - x = event.x(); - y = event.y(); -} - -TouchEvent::TouchEvent(const QTouchEvent& event) { - // convert the touch points into an average - const QList& tPoints = event.touchPoints(); - float touchAvgX = 0.0f; - float touchAvgY = 0.0f; - int numTouches = tPoints.count(); - if (numTouches > 1) { - for (int i = 0; i < numTouches; ++i) { - touchAvgX += tPoints[i].pos().x(); - touchAvgY += tPoints[i].pos().y(); - } - touchAvgX /= (float)(numTouches); - touchAvgY /= (float)(numTouches); - } - x = touchAvgX; - y = touchAvgY; -} - -WheelEvent::WheelEvent(const QWheelEvent& event) { - x = event.x(); - y = event.y(); -} - - -void registerEventTypes(QScriptEngine* engine) { - qScriptRegisterMetaType(engine, keyEventToScriptValue, keyEventFromScriptValue); - qScriptRegisterMetaType(engine, mouseEventToScriptValue, mouseEventFromScriptValue); - qScriptRegisterMetaType(engine, touchEventToScriptValue, touchEventFromScriptValue); - qScriptRegisterMetaType(engine, wheelEventToScriptValue, wheelEventFromScriptValue); +bool KeyEvent::operator==(const KeyEvent& other) const { + return other.key == key + && other.isShifted == isShifted + && other.isControl == isControl + && other.isMeta == isMeta + && other.isAlt == isAlt + && other.isKeypad == isKeypad; } QScriptValue keyEventToScriptValue(QScriptEngine* engine, const KeyEvent& event) { @@ -188,6 +190,24 @@ void keyEventFromScriptValue(const QScriptValue& object, KeyEvent& event) { event.key = Qt::Key_Delete; } else if (event.text.toUpper() == "BACKSPACE") { event.key = Qt::Key_Backspace; + } else if (event.text.toUpper() == "SHIFT") { + event.key = Qt::Key_Shift; + } else if (event.text.toUpper() == "ALT") { + event.key = Qt::Key_Alt; + } else if (event.text.toUpper() == "CONTROL") { + event.key = Qt::Key_Control; + } else if (event.text.toUpper() == "META") { + event.key = Qt::Key_Meta; + } else if (event.text.toUpper() == "PAGE DOWN") { + event.key = Qt::Key_PageDown; + } else if (event.text.toUpper() == "PAGE UP") { + event.key = Qt::Key_PageUp; + } else if (event.text.toUpper() == "HOME") { + event.key = Qt::Key_Home; + } else if (event.text.toUpper() == "END") { + event.key = Qt::Key_End; + } else if (event.text.toUpper() == "HELP") { + event.key = Qt::Key_Help; } else { event.key = event.text.at(0).unicode(); } @@ -224,10 +244,67 @@ void keyEventFromScriptValue(const QScriptValue& object, KeyEvent& event) { } } +MouseEvent::MouseEvent() : + x(0), + y(0), + isLeftButton(false), + isRightButton(false), + isMiddleButton(false), + isShifted(false), + isControl(false), + isMeta(false), + isAlt(false) +{ +}; + + +MouseEvent::MouseEvent(const QMouseEvent& event) { + x = event.x(); + y = event.y(); + + // single button that caused the event + switch (event.button()) { + case Qt::LeftButton: + button = "LEFT"; + isLeftButton = true; + break; + case Qt::RightButton: + button = "RIGHT"; + isRightButton = true; + break; + case Qt::MiddleButton: + button = "MIDDLE"; + isMiddleButton = true; + break; + default: + button = "NONE"; + break; + } + // button pressed state + isLeftButton = isLeftButton || (event.buttons().testFlag(Qt::LeftButton)); + isRightButton = isRightButton || (event.buttons().testFlag(Qt::RightButton)); + isMiddleButton = isMiddleButton || (event.buttons().testFlag(Qt::MiddleButton)); + + // keyboard modifiers + isShifted = event.modifiers().testFlag(Qt::ShiftModifier); + isMeta = event.modifiers().testFlag(Qt::MetaModifier); + isControl = event.modifiers().testFlag(Qt::ControlModifier); + isAlt = event.modifiers().testFlag(Qt::AltModifier); +} + QScriptValue mouseEventToScriptValue(QScriptEngine* engine, const MouseEvent& event) { QScriptValue obj = engine->newObject(); obj.setProperty("x", event.x); obj.setProperty("y", event.y); + obj.setProperty("button", event.button); + obj.setProperty("isLeftButton", event.isLeftButton); + obj.setProperty("isRightButton", event.isRightButton); + obj.setProperty("isMiddleButton", event.isMiddleButton); + obj.setProperty("isShifted", event.isShifted); + obj.setProperty("isMeta", event.isMeta); + obj.setProperty("isControl", event.isControl); + obj.setProperty("isAlt", event.isAlt); + return obj; } @@ -235,10 +312,76 @@ void mouseEventFromScriptValue(const QScriptValue& object, MouseEvent& event) { // nothing for now... } +TouchEvent::TouchEvent() : + x(0), + y(0), + isPressed(false), + isMoved(false), + isStationary(false), + isReleased(false), + isShifted(false), + isControl(false), + isMeta(false), + isAlt(false), + points() +{ +}; + + +TouchEvent::TouchEvent(const QTouchEvent& event) { + // convert the touch points into an average + const QList& tPoints = event.touchPoints(); + float touchAvgX = 0.0f; + float touchAvgY = 0.0f; + int numTouches = tPoints.count(); + if (numTouches > 1) { + for (int i = 0; i < numTouches; ++i) { + touchAvgX += tPoints[i].pos().x(); + touchAvgY += tPoints[i].pos().y(); + + // add it to our points vector + glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y()); + points << thisPoint; + } + touchAvgX /= (float)(numTouches); + touchAvgY /= (float)(numTouches); + } + x = touchAvgX; + y = touchAvgY; + + isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed); + isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved); + isStationary = event.touchPointStates().testFlag(Qt::TouchPointStationary); + isReleased = event.touchPointStates().testFlag(Qt::TouchPointReleased); + + // keyboard modifiers + isShifted = event.modifiers().testFlag(Qt::ShiftModifier); + isMeta = event.modifiers().testFlag(Qt::MetaModifier); + isControl = event.modifiers().testFlag(Qt::ControlModifier); + isAlt = event.modifiers().testFlag(Qt::AltModifier); +} + QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& event) { QScriptValue obj = engine->newObject(); obj.setProperty("x", event.x); obj.setProperty("y", event.y); + obj.setProperty("isPressed", event.isPressed); + obj.setProperty("isMoved", event.isMoved); + obj.setProperty("isStationary", event.isStationary); + obj.setProperty("isReleased", event.isReleased); + obj.setProperty("isShifted", event.isShifted); + obj.setProperty("isMeta", event.isMeta); + obj.setProperty("isControl", event.isControl); + obj.setProperty("isAlt", event.isAlt); + + QScriptValue pointsObj = engine->newArray(); + int index = 0; + foreach (glm::vec2 point, event.points) { + QScriptValue thisPoint = vec2toScriptValue(engine, point); + pointsObj.setProperty(index, thisPoint); + index++; + } + obj.setProperty("points", pointsObj); return obj; } @@ -246,10 +389,58 @@ void touchEventFromScriptValue(const QScriptValue& object, TouchEvent& event) { // nothing for now... } +WheelEvent::WheelEvent() : + x(0), + y(0), + delta(0), + orientation("UNKNOwN"), + isLeftButton(false), + isRightButton(false), + isMiddleButton(false), + isShifted(false), + isControl(false), + isMeta(false), + isAlt(false) +{ +}; + +WheelEvent::WheelEvent(const QWheelEvent& event) { + x = event.x(); + y = event.y(); + + delta = event.delta(); + if (event.orientation() == Qt::Horizontal) { + orientation = "HORIZONTAL"; + } else { + orientation = "VERTICAL"; + } + + // button pressed state + isLeftButton = (event.buttons().testFlag(Qt::LeftButton)); + isRightButton = (event.buttons().testFlag(Qt::RightButton)); + isMiddleButton = (event.buttons().testFlag(Qt::MiddleButton)); + + // keyboard modifiers + isShifted = event.modifiers().testFlag(Qt::ShiftModifier); + isMeta = event.modifiers().testFlag(Qt::MetaModifier); + isControl = event.modifiers().testFlag(Qt::ControlModifier); + isAlt = event.modifiers().testFlag(Qt::AltModifier); +} + + QScriptValue wheelEventToScriptValue(QScriptEngine* engine, const WheelEvent& event) { QScriptValue obj = engine->newObject(); obj.setProperty("x", event.x); obj.setProperty("y", event.y); + obj.setProperty("delta", event.delta); + obj.setProperty("orientation", event.orientation); + obj.setProperty("isLeftButton", event.isLeftButton); + obj.setProperty("isRightButton", event.isRightButton); + obj.setProperty("isMiddleButton", event.isMiddleButton); + obj.setProperty("isShifted", event.isShifted); + obj.setProperty("isMeta", event.isMeta); + obj.setProperty("isControl", event.isControl); + obj.setProperty("isAlt", event.isAlt); return obj; } diff --git a/libraries/script-engine/src/EventTypes.h b/libraries/script-engine/src/EventTypes.h index ebc85d04d3..4aa560afea 100644 --- a/libraries/script-engine/src/EventTypes.h +++ b/libraries/script-engine/src/EventTypes.h @@ -23,13 +23,7 @@ class KeyEvent { public: KeyEvent(); KeyEvent(const QKeyEvent& event); - inline bool operator==(const KeyEvent& other) const { - return other.key == key - && other.isShifted == isShifted - && other.isControl == isControl - && other.isMeta == isMeta - && other.isAlt == isAlt - && other.isKeypad == isKeypad; } + bool operator==(const KeyEvent& other) const; int key; QString text; bool isShifted; @@ -43,26 +37,52 @@ public: class MouseEvent { public: - MouseEvent() : x(0), y(0) { }; + MouseEvent(); MouseEvent(const QMouseEvent& event); int x; int y; + QString button; + bool isLeftButton; + bool isRightButton; + bool isMiddleButton; + bool isShifted; + bool isControl; + bool isMeta; + bool isAlt; }; class TouchEvent { public: - TouchEvent() : x(0), y(0) { }; + TouchEvent(); TouchEvent(const QTouchEvent& event); float x; float y; + bool isPressed; + bool isMoved; + bool isStationary; + bool isReleased; + bool isShifted; + bool isControl; + bool isMeta; + bool isAlt; + QVector points; }; class WheelEvent { public: - WheelEvent() : x(0), y(0) { }; + WheelEvent(); WheelEvent(const QWheelEvent& event); int x; int y; + int delta; + QString orientation; + bool isLeftButton; + bool isRightButton; + bool isMiddleButton; + bool isShifted; + bool isControl; + bool isMeta; + bool isAlt; }; Q_DECLARE_METATYPE(KeyEvent) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index e18878eec9..5c089b9a74 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -125,6 +125,7 @@ void ScriptEngine::init() { qScriptRegisterMetaType(&_engine, ParticlePropertiesToScriptValue, ParticlePropertiesFromScriptValue); qScriptRegisterMetaType(&_engine, ParticleIDtoScriptValue, ParticleIDfromScriptValue); qScriptRegisterSequenceMetaType >(&_engine); + qScriptRegisterSequenceMetaType >(&_engine); QScriptValue soundConstructorValue = _engine.newFunction(soundConstructor); QScriptValue soundMetaObject = _engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue); diff --git a/libraries/voxels/src/VoxelDetail.cpp b/libraries/voxels/src/VoxelDetail.cpp index 8d9f7df0c5..4527f7ca2c 100644 --- a/libraries/voxels/src/VoxelDetail.cpp +++ b/libraries/voxels/src/VoxelDetail.cpp @@ -5,6 +5,8 @@ // Created by Brad Hefta-Gaub on 1/29/2014 // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // + +#include #include "VoxelDetail.h" void registerVoxelMetaTypes(QScriptEngine* engine) { @@ -72,6 +74,9 @@ QScriptValue rayToVoxelIntersectionResultToScriptValue(QScriptEngine* engine, co break; } obj.setProperty("face", faceName); + + QScriptValue intersection = vec3toScriptValue(engine, value.intersection); + obj.setProperty("intersection", intersection); return obj; } @@ -97,6 +102,10 @@ void rayToVoxelIntersectionResultFromScriptValue(const QScriptValue& object, Ray } else { value.face = MAX_Z_FACE; }; + QScriptValue intersection = object.property("intersection"); + if (intersection.isValid()) { + vec3FromScriptValue(intersection, value.intersection); + } } diff --git a/libraries/voxels/src/VoxelDetail.h b/libraries/voxels/src/VoxelDetail.h index 9da2e40776..1604a022a0 100644 --- a/libraries/voxels/src/VoxelDetail.h +++ b/libraries/voxels/src/VoxelDetail.h @@ -40,6 +40,7 @@ public: VoxelDetail voxel; float distance; BoxFace face; + glm::vec3 intersection; }; Q_DECLARE_METATYPE(RayToVoxelIntersectionResult) diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index af5f8ce3c2..c0468ccca6 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -57,6 +57,7 @@ RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersection(const result.voxel.red = voxel->getColor()[0]; result.voxel.green = voxel->getColor()[1]; result.voxel.blue = voxel->getColor()[2]; + result.intersection = ray.origin + (ray.direction * result.distance); } _tree->unlock(); }