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 | 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 { | |
| 22 | − Camera* camera = Application::getInstance()->getCamera(); | |
| 23 | − glm::vec3 position = camera->getPosition(); | |
| 24 | − glm::quat orientation = camera->getOrientation(); | |
| 14 | +#include <QtScript/QScriptContext> | |
| 25 | 15 | |
| 26 | − glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f); | |
| 27 | − | |
| 28 | − const auto& compositor = Application::getInstance()->getApplicationCompositor(); | |
| 16 | +#include "display-plugins/DisplayPlugin.h" | |
| 17 | +#include <avatar/AvatarManager.h> | |
| 18 | +#include "Application.h" | |
| 29 | 19 | |
| 30 | − return compositor.calculateRayUICollisionPoint(position, direction, result); | |
| 20 | +HMDScriptingInterface::HMDScriptingInterface() { | |
| 31 | 21 | } |
| 32 | 22 | |
| 33 | 23 | QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { |
| 34 | − | |
| 35 | 24 | glm::vec3 hudIntersection; |
| 36 | − | |
| 37 | − if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(hudIntersection)) { | |
| 25 | + auto instance = DependencyManager::get<HMDScriptingInterface>(); | |
| 26 | + if (instance->getHUDLookAtPosition3D(hudIntersection)) { | |
| 38 | 27 | MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); |
| 39 | 28 | glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); |
| 40 | 29 | glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); |
| 41 | 30 | glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); |
| 42 | 31 | glm::vec3 eulers = ::safeEulerAngles(rotation); |
| 43 | 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 | 35 | return QScriptValue::NullValue; |
| 47 | 36 | } |
| 48 | 37 | |
| 49 | 38 | QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { |
| 50 | 39 | glm::vec3 result; |
| 51 | − if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(result)) { | |
| 40 | + auto instance = DependencyManager::get<HMDScriptingInterface>(); | |
| 41 | + if (instance->getHUDLookAtPosition3D(result)) { | |
| 52 | 42 | return qScriptValueFromValue<glm::vec3>(engine, result); |
| 53 | 43 | } |
| 54 | 44 | return QScriptValue::NullValue; |
| 55 | 45 | } |
| 56 | 46 | |
| 57 | −float HMDScriptingInterface::getIPD() const { | |
| 58 | − return Application::getInstance()->getActiveDisplayPlugin()->getIPD(); | |
| 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); | |
| 59 | 65 | } |