mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 07:37:31 +02:00
add hand driven reticle
This commit is contained in:
parent
63a63152a4
commit
762aefbbca
3 changed files with 38 additions and 43 deletions
35
examples/controllers/reticleHandTest.js
Normal file
35
examples/controllers/reticleHandTest.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
//
|
||||||
|
// reticleTest.js
|
||||||
|
// examples/controllers
|
||||||
|
//
|
||||||
|
// Created by Brad Hefta-Gaub on 2015/12/15
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
function moveReticle(pitch, yaw) {
|
||||||
|
//print("pitch:" + pitch);
|
||||||
|
//print("yaw:" + yaw);
|
||||||
|
|
||||||
|
var globalPos = Controller.getReticlePosition();
|
||||||
|
globalPos.x += yaw;
|
||||||
|
globalPos.y += pitch;
|
||||||
|
Controller.setReticlePosition(globalPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
var MAPPING_NAME = "com.highfidelity.testing.reticleWithHand";
|
||||||
|
var mapping = Controller.newMapping(MAPPING_NAME);
|
||||||
|
mapping.from(Controller.Standard.RightHand).peek().to(function(pose) {
|
||||||
|
var angularVelocityEADs = Quat.safeEulerAngles(pose.angularVelocity); // degrees
|
||||||
|
var yaw = isNaN(angularVelocityEADs.y) ? 0 : (-angularVelocityEADs.y / 10);
|
||||||
|
var pitch = isNaN(angularVelocityEADs.x) ? 0 : (-angularVelocityEADs.x / 10);
|
||||||
|
moveReticle(pitch, yaw);
|
||||||
|
});
|
||||||
|
mapping.enable();
|
||||||
|
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(function(){
|
||||||
|
mapping.disable();
|
||||||
|
});
|
|
@ -33,49 +33,6 @@ var mappingJSON = {
|
||||||
|
|
||||||
mapping = Controller.parseMapping(JSON.stringify(mappingJSON));
|
mapping = Controller.parseMapping(JSON.stringify(mappingJSON));
|
||||||
mapping.enable();
|
mapping.enable();
|
||||||
|
|
||||||
|
|
||||||
var MAPPING_NAME = "com.highfidelity.testing.reticleWithHand";
|
|
||||||
var mapping2 = Controller.newMapping(MAPPING_NAME);
|
|
||||||
//mapping2.from(Controller.Standard.RightHand).debug(true).to(Controller.Actions.LeftHand);
|
|
||||||
|
|
||||||
/*
|
|
||||||
mapping2.from(Controller.Standard.RightHand).peek().to(function(pose) {
|
|
||||||
print("Controller.Standard.RightHand value:" + JSON.stringify(pose));
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
var translation = { x: 0, y: 0.1, z: 0 };
|
|
||||||
var translationDx = 0.01;
|
|
||||||
var translationDy = 0.01;
|
|
||||||
var translationDz = 0.01;
|
|
||||||
var TRANSLATION_LIMIT = 0.5;
|
|
||||||
var rotation = Quat.fromPitchYawRollDegrees(45, 0, 45);
|
|
||||||
mapping2.from(function() {
|
|
||||||
translation.x = translation.x + translationDx;
|
|
||||||
translation.y = translation.y + translationDy;
|
|
||||||
translation.z = translation.z + translationDz;
|
|
||||||
if ((translation.x > TRANSLATION_LIMIT) || (translation.x < (-1 *TRANSLATION_LIMIT))) {
|
|
||||||
translationDx = translationDx * -1;
|
|
||||||
}
|
|
||||||
if ((translation.y > TRANSLATION_LIMIT) || (translation.y < (-1 *TRANSLATION_LIMIT))) {
|
|
||||||
translationDy = translationDy * -1;
|
|
||||||
}
|
|
||||||
if ((translation.z > TRANSLATION_LIMIT) || (translation.z < (-1 *TRANSLATION_LIMIT))) {
|
|
||||||
translationDz = translationDz * -1;
|
|
||||||
}
|
|
||||||
var pose = {
|
|
||||||
translation: translation,
|
|
||||||
rotation: rotation,
|
|
||||||
velocity: { x: 0, y: 0, z: 0 },
|
|
||||||
angularVelocity: { x: 0, y: 0, z: 0, w: 1 }
|
|
||||||
};
|
|
||||||
return pose;
|
|
||||||
}).debug(true).to(Controller.Standard.LeftHand);
|
|
||||||
|
|
||||||
Controller.enableMapping(MAPPING_NAME);
|
|
||||||
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(function(){
|
Script.scriptEnding.connect(function(){
|
||||||
mapping.disable();
|
mapping.disable();
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
#include <QCursor>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
@ -87,6 +88,8 @@ namespace controller {
|
||||||
Q_INVOKABLE QObject* parseMapping(const QString& json);
|
Q_INVOKABLE QObject* parseMapping(const QString& json);
|
||||||
Q_INVOKABLE QObject* loadMapping(const QString& jsonUrl);
|
Q_INVOKABLE QObject* loadMapping(const QString& jsonUrl);
|
||||||
|
|
||||||
|
Q_INVOKABLE glm::vec2 getReticlePosition() { return toGlm(QCursor::pos()); }
|
||||||
|
Q_INVOKABLE void setReticlePosition(glm::vec2 position) { QCursor::setPos(position.x, position.y); }
|
||||||
|
|
||||||
//Q_INVOKABLE bool isPrimaryButtonPressed() const;
|
//Q_INVOKABLE bool isPrimaryButtonPressed() const;
|
||||||
//Q_INVOKABLE glm::vec2 getPrimaryJoystickPosition() const;
|
//Q_INVOKABLE glm::vec2 getPrimaryJoystickPosition() const;
|
||||||
|
|
Loading…
Reference in a new issue