mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 17:23:29 +02:00
expose setting HMD sensorToWorld from JS script
This commit is contained in:
parent
0f248c4540
commit
97623f489c
2 changed files with 22 additions and 2 deletions
|
@ -90,6 +90,16 @@ glm::vec3 HMDScriptingInterface::getPosition() const {
|
||||||
return glm::vec3();
|
return glm::vec3();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HMDScriptingInterface::setPosition(const glm::vec3& position) {
|
||||||
|
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
|
glm::mat4 hmdToSensor = myAvatar->getHMDSensorMatrix();
|
||||||
|
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 {
|
||||||
if (qApp->getActiveDisplayPlugin()->isHmd()) {
|
if (qApp->getActiveDisplayPlugin()->isHmd()) {
|
||||||
return glm::normalize(glm::quat_cast(getWorldHMDMatrix()));
|
return glm::normalize(glm::quat_cast(getWorldHMDMatrix()));
|
||||||
|
@ -139,3 +149,8 @@ bool HMDScriptingInterface::isKeyboardVisible() {
|
||||||
void HMDScriptingInterface::centerUI() {
|
void HMDScriptingInterface::centerUI() {
|
||||||
QMetaObject::invokeMethod(qApp, "centerUI", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(qApp, "centerUI", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HMDScriptingInterface::snapToAvatar() {
|
||||||
|
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
|
myAvatar->updateSensorToWorldMatrix();
|
||||||
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class QScriptEngine;
|
||||||
|
|
||||||
class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency {
|
class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(glm::vec3 position READ getPosition)
|
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||||
Q_PROPERTY(glm::quat orientation READ getOrientation)
|
Q_PROPERTY(glm::quat orientation READ getOrientation)
|
||||||
Q_PROPERTY(bool mounted READ isMounted)
|
Q_PROPERTY(bool mounted READ isMounted)
|
||||||
|
|
||||||
|
@ -58,6 +58,8 @@ public:
|
||||||
// rotate the overlay UI sphere so that it is centered about the the current HMD position and orientation
|
// rotate the overlay UI sphere so that it is centered about the the current HMD position and orientation
|
||||||
Q_INVOKABLE void centerUI();
|
Q_INVOKABLE void centerUI();
|
||||||
|
|
||||||
|
// snap HMD to align with Avatar's current position in world-frame
|
||||||
|
Q_INVOKABLE void snapToAvatar();
|
||||||
public:
|
public:
|
||||||
HMDScriptingInterface();
|
HMDScriptingInterface();
|
||||||
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);
|
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);
|
||||||
|
@ -68,7 +70,10 @@ public:
|
||||||
private:
|
private:
|
||||||
// Get the position of the HMD
|
// Get the position of the HMD
|
||||||
glm::vec3 getPosition() const;
|
glm::vec3 getPosition() const;
|
||||||
|
|
||||||
|
// Set the position of the HMD
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue