Showing the changes to interface/src/scripting/HMDScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -15,3 +15,30 @@ HMDScriptingInterface& HMDScriptingInterface::getInstance() { · 14 unmodified lines | ||
| 15 | 15 | static HMDScriptingInterface sharedInstance; |
| 16 | 16 | return sharedInstance; |
| 17 | 17 | } |
| 18 | + | |
| 19 | +glm::vec3 HMDScriptingInterface::getHUDLookAtPosition3D() const { | |
| 20 | + Camera* camera = Application::getInstance()->getCamera(); | |
| 21 | + glm::vec3 position = camera->getPosition(); | |
| 22 | + glm::quat orientation = camera->getOrientation(); | |
| 23 | + | |
| 24 | + glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f); | |
| 25 | + | |
| 26 | + ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay(); | |
| 27 | + | |
| 28 | + glm::vec3 result; | |
| 29 | + applicationOverlay.calculateRayUICollisionPoint(position, direction, result); | |
| 30 | + return result; | |
| 31 | +} | |
| 32 | + | |
| 33 | +glm::vec2 HMDScriptingInterface::getHUDLookAtPosition2D() const { | |
| 34 | + MyAvatar* myAvatar = Application::getInstance()->getAvatar(); | |
| 35 | + glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); | |
| 36 | + | |
| 37 | + glm::vec3 hudIntersection = getHUDLookAtPosition3D(); | |
| 38 | + | |
| 39 | + glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); | |
| 40 | + glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); | |
| 41 | + glm::vec3 eulers = ::safeEulerAngles(rotation); | |
| 42 | + | |
| 43 | + return Application::getInstance()->getApplicationOverlay().sphericalToOverlay(glm::vec2(eulers.y, -eulers.x));; | |
| 44 | +} | |