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