mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +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();
|
||||
}
|
||||
|
||||
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 {
|
||||
if (qApp->getActiveDisplayPlugin()->isHmd()) {
|
||||
return glm::normalize(glm::quat_cast(getWorldHMDMatrix()));
|
||||
|
@ -139,3 +149,8 @@ bool HMDScriptingInterface::isKeyboardVisible() {
|
|||
void HMDScriptingInterface::centerUI() {
|
||||
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 {
|
||||
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(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
|
||||
Q_INVOKABLE void centerUI();
|
||||
|
||||
// snap HMD to align with Avatar's current position in world-frame
|
||||
Q_INVOKABLE void snapToAvatar();
|
||||
public:
|
||||
HMDScriptingInterface();
|
||||
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);
|
||||
|
@ -68,7 +70,10 @@ public:
|
|||
private:
|
||||
// Get the position of the HMD
|
||||
glm::vec3 getPosition() const;
|
||||
|
||||
|
||||
// Set the position of the HMD
|
||||
void setPosition(const glm::vec3& position);
|
||||
|
||||
// Get the orientation of the HMD
|
||||
glm::quat getOrientation() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue