mirror of
https://github.com/overte-org/overte.git
synced 2025-06-21 16:41:34 +02:00
Cleaned up the code, created a function to check if the hands are in the right position.
This commit is contained in:
parent
5f600b4ea9
commit
bfcddcf3b7
1 changed files with 33 additions and 29 deletions
|
@ -17,39 +17,23 @@
|
||||||
function checkRocketing() {
|
function checkRocketing() {
|
||||||
if (HMD.active) {
|
if (HMD.active) {
|
||||||
if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) {
|
if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) {
|
||||||
var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand);
|
if (canRocket()) {
|
||||||
var rightHand = Controller.getPoseValue(Controller.Standard.RightHand);
|
isRocketing = true;
|
||||||
var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation));
|
MyAvatar.motorReferenceFrame = "world";
|
||||||
var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation));
|
var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10);
|
||||||
var hipPosition = MyAvatar.getJointPosition("Hips");
|
if (!MyAvatar.isFlying()) {
|
||||||
var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips.
|
moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0});
|
||||||
var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold.
|
|
||||||
|
|
||||||
if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) &&
|
|
||||||
(leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) &&
|
|
||||||
(rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) &&
|
|
||||||
(rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) {
|
|
||||||
if ((leftHand.rotation.y < controllerRotationThreshold) &&
|
|
||||||
(leftHand.rotation.y > -controllerRotationThreshold) &&
|
|
||||||
(rightHand.rotation.y < controllerRotationThreshold) &&
|
|
||||||
(rightHand.rotation.y > -controllerRotationThreshold)) {
|
|
||||||
isRocketing = true;
|
|
||||||
MyAvatar.motorReferenceFrame = "world";
|
|
||||||
var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10);
|
|
||||||
if (!MyAvatar.isFlying()) {
|
|
||||||
moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0});
|
|
||||||
}
|
|
||||||
MyAvatar.motorVelocity = moveVector;
|
|
||||||
MyAvatar.motorTimescale = 1.0;
|
|
||||||
} else {
|
|
||||||
checkCanStopRocketing();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
checkCanStopRocketing();
|
|
||||||
}
|
}
|
||||||
|
MyAvatar.motorVelocity = moveVector;
|
||||||
|
MyAvatar.motorTimescale = 1.0;
|
||||||
|
} else {
|
||||||
|
checkCanStopRocketing();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
checkCanStopRocketing();
|
checkCanStopRocketing();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
checkCanStopRocketing();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,5 +43,25 @@
|
||||||
isRocketing = false;
|
isRocketing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canRocket() {
|
||||||
|
var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand);
|
||||||
|
var rightHand = Controller.getPoseValue(Controller.Standard.RightHand);
|
||||||
|
var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation));
|
||||||
|
var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation));
|
||||||
|
var hipPosition = MyAvatar.getJointPosition("Hips");
|
||||||
|
var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips.
|
||||||
|
var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold.
|
||||||
|
|
||||||
|
return ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) &&
|
||||||
|
(leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) &&
|
||||||
|
(rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) &&
|
||||||
|
(rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) &&
|
||||||
|
leftHand.rotation.y < controllerRotationThreshold &&
|
||||||
|
leftHand.rotation.y > -controllerRotationThreshold &&
|
||||||
|
rightHand.rotation.y < controllerRotationThreshold &&
|
||||||
|
rightHand.rotation.y > -controllerRotationThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
Script.update.connect(checkRocketing);
|
Script.update.connect(checkRocketing);
|
||||||
}());
|
}());
|
Loading…
Reference in a new issue