Teleport bugs

* made HMD.setPosition thread safe
* changed script to use HMD.position = foo;
This commit is contained in:
Anthony J. Thibault 2016-09-09 17:31:11 -07:00
parent 82522fbbb1
commit 86351ca21c
3 changed files with 14 additions and 9 deletions

View file

@ -91,13 +91,18 @@ glm::vec3 HMDScriptingInterface::getPosition() const {
} }
void HMDScriptingInterface::setPosition(const glm::vec3& position) { void HMDScriptingInterface::setPosition(const glm::vec3& position) {
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar(); if (QThread::currentThread() != thread()) {
glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix(); QMetaObject::invokeMethod(this, "setPosition", Qt::QueuedConnection, Q_ARG(const glm::vec3&, position));
glm::mat4 sensorToWorld = myAvatar->getSensorToWorldMatrix(); return;
glm::mat4 hmdToWorld = sensorToWorld * hmdToSensor; } else {
setTranslation(hmdToWorld, position); MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
sensorToWorld = hmdToWorld * glm::inverse(hmdToSensor); glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix();
myAvatar->setSensorToWorldMatrix(sensorToWorld); glm::mat4 sensorToWorld = myAvatar->getSensorToWorldMatrix();
glm::mat4 hmdToWorld = sensorToWorld * hmdToSensor;
setTranslation(hmdToWorld, position);
sensorToWorld = hmdToWorld * glm::inverse(hmdToSensor);
myAvatar->setSensorToWorldMatrix(sensorToWorld);
}
} }
glm::quat HMDScriptingInterface::getOrientation() const { glm::quat HMDScriptingInterface::getOrientation() const {

View file

@ -72,7 +72,7 @@ private:
glm::vec3 getPosition() const; glm::vec3 getPosition() const;
// Set the position of the HMD // Set the position of the HMD
void setPosition(const glm::vec3& position); Q_INVOKABLE void setPosition(const glm::vec3& position);
// Get the orientation of the HMD // Get the orientation of the HMD
glm::quat getOrientation() const; glm::quat getOrientation() const;

View file

@ -564,7 +564,7 @@ function Teleporter() {
} else if (this.teleportMode === "HMDFirstAvatarWillFollow") { } else if (this.teleportMode === "HMDFirstAvatarWillFollow") {
var eyeOffset = Vec3.subtract(MyAvatar.getEyePosition(), MyAvatar.position); var eyeOffset = Vec3.subtract(MyAvatar.getEyePosition(), MyAvatar.position);
landingPoint = Vec3.sum(landingPoint, eyeOffset); landingPoint = Vec3.sum(landingPoint, eyeOffset);
HMD.setPosition(landingPoint); HMD.position = landingPoint;
} }
} }