mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-30 17:03:13 +02:00
more work on hand movement
This commit is contained in:
parent
42764426ce
commit
4075f355a3
3 changed files with 117 additions and 19 deletions
|
@ -9,23 +9,83 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// 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();
|
function msecTimestampNow() {
|
||||||
globalPos.x += yaw;
|
var d = new Date();
|
||||||
globalPos.y += pitch;
|
return d.getTime();
|
||||||
Controller.setReticlePosition(globalPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function length(posA, posB) {
|
||||||
|
var dx = posA.x - posB.x;
|
||||||
|
var dy = posA.y - posB.y;
|
||||||
|
var length = Math.sqrt((dx*dx) + (dy*dy))
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
var EXPECTED_CHANGE = 50;
|
||||||
|
var lastPos = Controller.getReticlePosition();
|
||||||
|
function moveReticle(dX, dY) {
|
||||||
|
var globalPos = Controller.getReticlePosition();
|
||||||
|
|
||||||
|
// some debugging to see if position is jumping around on us...
|
||||||
|
var distanceSinceLastMove = length(lastPos, globalPos);
|
||||||
|
if (distanceSinceLastMove > EXPECTED_CHANGE) {
|
||||||
|
print("distanceSinceLastMove:" + distanceSinceLastMove + "----------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.abs(dX) > EXPECTED_CHANGE) {
|
||||||
|
print("surpressing unexpectedly large change dX:" + dX + "----------------------------");
|
||||||
|
dX = 0;
|
||||||
|
}
|
||||||
|
if (Math.abs(dY) > EXPECTED_CHANGE) {
|
||||||
|
print("surpressing unexpectedly large change dY:" + dY + "----------------------------");
|
||||||
|
dY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
globalPos.x += dX;
|
||||||
|
globalPos.y += dY;
|
||||||
|
Controller.setReticlePosition(globalPos);
|
||||||
|
lastPos = globalPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastTime = msecTimestampNow();
|
||||||
|
|
||||||
var MAPPING_NAME = "com.highfidelity.testing.reticleWithHand";
|
var MAPPING_NAME = "com.highfidelity.testing.reticleWithHand";
|
||||||
var mapping = Controller.newMapping(MAPPING_NAME);
|
var mapping = Controller.newMapping(MAPPING_NAME);
|
||||||
mapping.from(Controller.Standard.RightHand).peek().to(function(pose) {
|
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);
|
// pose.angularVelocity - is the angularVelocity in a "physics" sense, that
|
||||||
moveReticle(pitch, yaw);
|
// means the direction of the vector is the axis of symetry of rotation
|
||||||
|
// and the scale of the vector is the speed in radians/second of rotation
|
||||||
|
// around that axis.
|
||||||
|
//
|
||||||
|
// we want to deconstruct that in the portion of the rotation on the Y axis
|
||||||
|
// and make that portion move our reticle in the horizontal/X direction
|
||||||
|
// and the portion of the rotation on the X axis and make that portion
|
||||||
|
// move our reticle in the veritcle/Y direction
|
||||||
|
var xPart = -pose.angularVelocity.y;
|
||||||
|
var yPart = -pose.angularVelocity.x;
|
||||||
|
|
||||||
|
|
||||||
|
var MOVE_SCALE = 1;
|
||||||
|
var MSECS_PER_SECOND = 1000;
|
||||||
|
var now = msecTimestampNow();
|
||||||
|
var secondsSinceLast = (now - lastTime) / MSECS_PER_SECOND;
|
||||||
|
lastTime = now;
|
||||||
|
|
||||||
|
//print("secondsSinceLast:" + secondsSinceLast);
|
||||||
|
|
||||||
|
//print("x part:" + xPart);
|
||||||
|
//print("y part:" + yPart);
|
||||||
|
|
||||||
|
var dX = (xPart * MOVE_SCALE) / secondsSinceLast;
|
||||||
|
var dY = (yPart * MOVE_SCALE) / secondsSinceLast;
|
||||||
|
|
||||||
|
//print("dX:" + dX);
|
||||||
|
//print("dY:" + dY);
|
||||||
|
|
||||||
|
moveReticle(dX, dY);
|
||||||
});
|
});
|
||||||
mapping.enable();
|
mapping.enable();
|
||||||
|
|
||||||
|
|
|
@ -686,13 +686,37 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
} else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
|
} else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
|
||||||
VrMenu::toggle(); // show context menu even on non-stereo displays
|
VrMenu::toggle(); // show context menu even on non-stereo displays
|
||||||
} else if (action == controller::toInt(controller::Action::RETICLE_X)) {
|
} else if (action == controller::toInt(controller::Action::RETICLE_X)) {
|
||||||
auto globalPos = QCursor::pos();
|
auto oldPos = QCursor::pos();
|
||||||
globalPos.setX(globalPos.x() + state);
|
auto newPos = oldPos;
|
||||||
QCursor::setPos(globalPos);
|
newPos.setX(oldPos.x() + state);
|
||||||
|
QCursor::setPos(newPos);
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
|
||||||
|
// remove it after we're done
|
||||||
|
const float REASONABLE_CHANGE = 50.0f;
|
||||||
|
glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
|
||||||
|
glm::vec2 newPosG = { newPos.x(), newPos.y() };
|
||||||
|
auto distance = glm::distance(oldPosG, newPosG);
|
||||||
|
if (distance > REASONABLE_CHANGE) {
|
||||||
|
qDebug() << "Action::RETICLE_X... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
|
} else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
|
||||||
auto globalPos = QCursor::pos();
|
auto oldPos = QCursor::pos();
|
||||||
globalPos.setY(globalPos.y() + state);
|
auto newPos = oldPos;
|
||||||
QCursor::setPos(globalPos);
|
newPos.setY(oldPos.y() + state);
|
||||||
|
QCursor::setPos(newPos);
|
||||||
|
|
||||||
|
// NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
|
||||||
|
// remove it after we're done
|
||||||
|
const float REASONABLE_CHANGE = 50.0f;
|
||||||
|
glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
|
||||||
|
glm::vec2 newPosG = { newPos.x(), newPos.y() };
|
||||||
|
auto distance = glm::distance(oldPosG, newPosG);
|
||||||
|
if (distance > REASONABLE_CHANGE) {
|
||||||
|
qDebug() << "Action::RETICLE_Y... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <QtScript/QScriptValue>
|
#include <QtScript/QScriptValue>
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
|
#include <StreamUtils.h>
|
||||||
|
|
||||||
#include "UserInputMapper.h"
|
#include "UserInputMapper.h"
|
||||||
#include "StandardControls.h"
|
#include "StandardControls.h"
|
||||||
|
@ -88,8 +89,21 @@ 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 glm::vec2 getReticlePosition() {
|
||||||
Q_INVOKABLE void setReticlePosition(glm::vec2 position) { QCursor::setPos(position.x, position.y); }
|
return toGlm(QCursor::pos());
|
||||||
|
}
|
||||||
|
Q_INVOKABLE void setReticlePosition(glm::vec2 position) {
|
||||||
|
// NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
|
||||||
|
// remove it after we're done
|
||||||
|
const float REASONABLE_CHANGE = 50.0f;
|
||||||
|
glm::vec2 oldPos = toGlm(QCursor::pos());
|
||||||
|
auto distance = glm::distance(oldPos, position);
|
||||||
|
if (distance > REASONABLE_CHANGE) {
|
||||||
|
qDebug() << "Contrller::ScriptingInterface ---- UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPos << " newPos:" << 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