Showing the changes to interface/src/scripting/HMDScriptingInterface.cpp (1 of 21 files). Show all
Unified · Split
| @@ -10,50 +10,56 @@ · 9 unmodified lines | |||
| 10 | // | 10 | // |
| 11 | 11 | ||
| 12 | #include "HMDScriptingInterface.h" | 12 | #include "HMDScriptingInterface.h" |
| 13 | #include "display-plugins/DisplayPlugin.h" | ||
| 14 | #include <avatar/AvatarManager.h> | ||
| 15 | |||
| 16 | HMDScriptingInterface& HMDScriptingInterface::getInstance() { | ||
| 17 | static HMDScriptingInterface sharedInstance; | ||
| 18 | return sharedInstance; | ||
| 19 | } | ||
| 20 | 13 | ||
| 21 | bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { | 14 | #include <QtScript/QScriptContext> |
| 22 | Camera* camera = Application::getInstance()->getCamera(); | ||
| 23 | glm::vec3 position = camera->getPosition(); | ||
| 24 | glm::quat orientation = camera->getOrientation(); | ||
| 25 | 15 | ||
| 26 | glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f); | 16 | #include "display-plugins/DisplayPlugin.h" |
| 27 | 17 | #include <avatar/AvatarManager.h> | |
| 28 | const auto& compositor = Application::getInstance()->getApplicationCompositor(); | 18 | #include "Application.h" |
| 29 | 19 | ||
| 30 | return compositor.calculateRayUICollisionPoint(position, direction, result); | 20 | HMDScriptingInterface::HMDScriptingInterface() { |
| 31 | } | 21 | } |
| 32 | 22 | ||
| 33 | QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { | 23 | QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { |
| 34 | |||
| 35 | glm::vec3 hudIntersection; | 24 | glm::vec3 hudIntersection; |
| 36 | 25 | auto instance = DependencyManager::get<HMDScriptingInterface>(); | |
| 37 | if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(hudIntersection)) { | 26 | if (instance->getHUDLookAtPosition3D(hudIntersection)) { |
| 38 | MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | 27 | MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); |
| 39 | glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); | 28 | glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); |
| 40 | glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); | 29 | glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); |
| 41 | glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); | 30 | glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); |
| 42 | glm::vec3 eulers = ::safeEulerAngles(rotation); | 31 | glm::vec3 eulers = ::safeEulerAngles(rotation); |
| 43 | return qScriptValueFromValue<glm::vec2>(engine, Application::getInstance()->getApplicationCompositor() | 32 | return qScriptValueFromValue<glm::vec2>(engine, Application::getInstance()->getApplicationCompositor() |
| 44 | .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); | 33 | .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); |
| 45 | } | 34 | } |
| 46 | return QScriptValue::NullValue; | 35 | return QScriptValue::NullValue; |
| 47 | } | 36 | } |
| 48 | 37 | ||
| 49 | QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { | 38 | QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { |
| 50 | glm::vec3 result; | 39 | glm::vec3 result; |
| 51 | if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(result)) { | 40 | auto instance = DependencyManager::get<HMDScriptingInterface>(); |
| 41 | if (instance->getHUDLookAtPosition3D(result)) { | ||
| 52 | return qScriptValueFromValue<glm::vec3>(engine, result); | 42 | return qScriptValueFromValue<glm::vec3>(engine, result); |
| 53 | } | 43 | } |
| 54 | return QScriptValue::NullValue; | 44 | return QScriptValue::NullValue; |
| 55 | } | 45 | } |
| 56 | 46 | ||
| 57 | float HMDScriptingInterface::getIPD() const { | 47 | void HMDScriptingInterface::toggleMagnifier() { |
| 58 | return Application::getInstance()->getActiveDisplayPlugin()->getIPD(); | 48 | qApp->getApplicationCompositor().toggleMagnifier(); |
| 49 | } | ||
| 50 | |||
| 51 | bool HMDScriptingInterface::getMagnifier() const { | ||
| 52 | return Application::getInstance()->getApplicationCompositor().hasMagnifier(); | ||
| 53 | } | ||
| 54 | |||
| 55 | bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { | ||
| 56 | Camera* camera = Application::getInstance()->getCamera(); | ||
| 57 | glm::vec3 position = camera->getPosition(); | ||
| 58 | glm::quat orientation = camera->getOrientation(); | ||
| 59 | |||
| 60 | glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f); | ||
| 61 | |||
| 62 | const auto& compositor = Application::getInstance()->getApplicationCompositor(); | ||
| 63 | |||
| 64 | return compositor.calculateRayUICollisionPoint(position, direction, result); | ||
| 59 | } | 65 | } |