* 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 | 93 | void HMDScriptingInterface::setPosition(const glm::vec3& position) { |
| 94 | − MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | |
| 95 | − glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix(); | |
| 96 | − glm::mat4 sensorToWorld = myAvatar->getSensorToWorldMatrix(); | |
| 97 | − glm::mat4 hmdToWorld = sensorToWorld * hmdToSensor; | |
| 98 | − setTranslation(hmdToWorld, position); | |
| 99 | − sensorToWorld = hmdToWorld * glm::inverse(hmdToSensor); | |
| 100 | − myAvatar->setSensorToWorldMatrix(sensorToWorld); | |
| 94 | + if (QThread::currentThread() != thread()) { | |
| 95 | + QMetaObject::invokeMethod(this, "setPosition", Qt::QueuedConnection, Q_ARG(const glm::vec3&, position)); | |
| 96 | + return; | |
| 97 | + } else { | |
| 98 | + MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); | |
| 99 | + glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix(); | |
| 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 | 108 | glm::quat HMDScriptingInterface::getOrientation() const { |