* made HMD.setPosition thread safe * changed script to use HMD.position = foo;
Showing the changes to interface/src/scripting/HMDScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -91,13 +91,18 @@ glm::vec3 HMDScriptingInterface::getPosition() const { · 90 unmodified lines | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void HMDScriptingInterface::setPosition(const glm::vec3& position) { | 93 | void HMDScriptingInterface::setPosition(const glm::vec3& position) { |
| 94 | MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | 94 | if (QThread::currentThread() != thread()) { |
| 95 | glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix(); | 95 | QMetaObject::invokeMethod(this, "setPosition", Qt::QueuedConnection, Q_ARG(const glm::vec3&, position)); |
| 96 | glm::mat4 sensorToWorld = myAvatar->getSensorToWorldMatrix(); | 96 | return; |
| 97 | glm::mat4 hmdToWorld = sensorToWorld * hmdToSensor; | 97 | } else { |
| 98 | setTranslation(hmdToWorld, position); | 98 | MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); |
| 99 | sensorToWorld = hmdToWorld * glm::inverse(hmdToSensor); | 99 | glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix(); |
| 100 | myAvatar->setSensorToWorldMatrix(sensorToWorld); | 100 | glm::mat4 sensorToWorld = myAvatar->getSensorToWorldMatrix(); |
| 101 | glm::mat4 hmdToWorld = sensorToWorld * hmdToSensor; | ||
| 102 | setTranslation(hmdToWorld, position); | ||
| 103 | sensorToWorld = hmdToWorld * glm::inverse(hmdToSensor); | ||
| 104 | myAvatar->setSensorToWorldMatrix(sensorToWorld); | ||
| 105 | } | ||
| 101 | } | 106 | } |
| 102 | 107 | ||
| 103 | glm::quat HMDScriptingInterface::getOrientation() const { | 108 | glm::quat HMDScriptingInterface::getOrientation() const { |