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