Showing the changes to interface/src/scripting/HMDScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -1,4 +1,4 @@ | ||
| 1 | −// | |
| 1 | +// | |
| 2 | 2 | // HMDScriptingInterface.cpp |
| 3 | 3 | // interface/src/scripting |
| 4 | 4 | // |
| @@ -18,7 +18,7 @@ HMDScriptingInterface& HMDScriptingInterface::getInstance() { · 13 unmodified lines | ||
| 18 | 18 | return sharedInstance; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | −glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { | |
| 21 | +bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { | |
| 22 | 22 | Camera* camera = Application::getInstance()->getCamera(); |
| 23 | 23 | glm::vec3 position = camera->getPosition(); |
| 24 | 24 | glm::quat orientation = camera->getOrientation(); |
| @@ -27,20 +27,30 @@ glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { · 2 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay(); |
| 29 | 29 | |
| 30 | − glm::vec3 result; | |
| 31 | − applicationOverlay.calculateRayUICollisionPoint(position, direction, result); | |
| 32 | − return result; | |
| 30 | + return applicationOverlay.calculateRayUICollisionPoint(position, direction, result); | |
| 33 | 31 | } |
| 34 | 32 | |
| 35 | −glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const { | |
| 36 | − MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | |
| 37 | − glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); | |
| 33 | +QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { | |
| 38 | 34 | |
| 39 | − glm::vec3 hudIntersection = getHUDLookAtPosition3D(); | |
| 35 | + glm::vec3 hudIntersection; | |
| 40 | 36 | |
| 41 | − glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); | |
| 42 | − glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); | |
| 43 | − glm::vec3 eulers = ::safeEulerAngles(rotation); | |
| 37 | + if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(hudIntersection)) { | |
| 38 | + MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | |
| 39 | + glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); | |
| 40 | + glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); | |
| 41 | + glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); | |
| 42 | + glm::vec3 eulers = ::safeEulerAngles(rotation); | |
| 43 | + return qScriptValueFromValue<glm::vec2>(engine, Application::getInstance()->getApplicationOverlay() | |
| 44 | + .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); | |
| 45 | + } | |
| 46 | + return QScriptValue::NullValue; | |
| 47 | +} | |
| 44 | 48 | |
| 45 | − return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x)); | |
| 49 | +QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { | |
| 50 | + glm::vec3 result; | |
| 51 | + HMDScriptingInterface* hmdInterface = &HMDScriptingInterface::getInstance(); | |
| 52 | + if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(result)) { | |
| 53 | + return qScriptValueFromValue<glm::vec3>(engine, result); | |
| 54 | + } | |
| 55 | + return QScriptValue::NullValue; | |
| 46 | 56 | } |