add hand driven reticle

This commit is contained in:
Brad Hefta-Gaub 2015-12-17 17:38:20 -08:00
parent 63a63152a4
commit 762aefbbca
3 changed files with 38 additions and 43 deletions

View 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();
});

View file

@ -33,49 +33,6 @@ var mappingJSON = {
mapping = Controller.parseMapping(JSON.stringify(mappingJSON));
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(){
mapping.disable();
});

View file

@ -21,6 +21,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <QCursor>
#include <QThread>
#include <QtCore/QObject>
#include <QtCore/QVariant>
@ -87,6 +88,8 @@ namespace controller {
Q_INVOKABLE QObject* parseMapping(const QString& json);
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 glm::vec2 getPrimaryJoystickPosition() const;