mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 22:36:57 +02:00
HandControllerGrab: fixes for distance holding
Because controller poses are in avatar space, there is no need to apply delta avatar position changes and rotation changes.
This commit is contained in:
parent
f21815e332
commit
076b0b42d7
1 changed files with 36 additions and 64 deletions
|
@ -1049,9 +1049,14 @@ function MyController(hand) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.distanceHolding = function() {
|
this.distanceHolding = function() {
|
||||||
var handControllerPosition = (this.hand === RIGHT_HAND) ? MyAvatar.rightHandPosition : MyAvatar.leftHandPosition;
|
|
||||||
var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
// controller pose is in avatar frame
|
||||||
var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(controllerHandInput).rotation);
|
var avatarControllerPose = Controller.getPoseValue((this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand);
|
||||||
|
|
||||||
|
// transform it into world frame
|
||||||
|
var controllerPosition = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation));
|
||||||
|
var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation);
|
||||||
|
|
||||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
|
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
|
@ -1059,12 +1064,10 @@ function MyController(hand) {
|
||||||
this.currentObjectPosition = grabbedProperties.position;
|
this.currentObjectPosition = grabbedProperties.position;
|
||||||
this.currentObjectRotation = grabbedProperties.rotation;
|
this.currentObjectRotation = grabbedProperties.rotation;
|
||||||
this.currentObjectTime = now;
|
this.currentObjectTime = now;
|
||||||
this.handRelativePreviousPosition = Vec3.subtract(handControllerPosition, MyAvatar.position);
|
|
||||||
this.handPreviousRotation = handRotation;
|
|
||||||
this.currentCameraOrientation = Camera.orientation;
|
this.currentCameraOrientation = Camera.orientation;
|
||||||
|
|
||||||
// compute a constant based on the initial conditions which we use below to exagerate hand motion onto the held object
|
// compute a constant based on the initial conditions which we use below to exagerate hand motion onto the held object
|
||||||
this.radiusScalar = Math.log(Vec3.distance(this.currentObjectPosition, handControllerPosition) + 1.0);
|
this.radiusScalar = Math.log(Vec3.distance(this.currentObjectPosition, controllerPosition) + 1.0);
|
||||||
if (this.radiusScalar < 1.0) {
|
if (this.radiusScalar < 1.0) {
|
||||||
this.radiusScalar = 1.0;
|
this.radiusScalar = 1.0;
|
||||||
}
|
}
|
||||||
|
@ -1094,10 +1097,10 @@ function MyController(hand) {
|
||||||
this.callEntityMethodOnGrabbed("startDistanceGrab");
|
this.callEntityMethodOnGrabbed("startDistanceGrab");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentAvatarPosition = MyAvatar.position;
|
|
||||||
this.currentAvatarOrientation = MyAvatar.orientation;
|
|
||||||
|
|
||||||
this.turnOffVisualizations();
|
this.turnOffVisualizations();
|
||||||
|
|
||||||
|
this.previousControllerPosition = controllerPosition;
|
||||||
|
this.previousControllerRotation = controllerRotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.continueDistanceHolding = function() {
|
this.continueDistanceHolding = function() {
|
||||||
|
@ -1109,10 +1112,13 @@ function MyController(hand) {
|
||||||
|
|
||||||
this.heartBeat(this.grabbedEntity);
|
this.heartBeat(this.grabbedEntity);
|
||||||
|
|
||||||
var handPosition = this.getHandPosition();
|
// controller pose is in avatar frame
|
||||||
var handControllerPosition = (this.hand === RIGHT_HAND) ? MyAvatar.rightHandPosition : MyAvatar.leftHandPosition;
|
var avatarControllerPose = Controller.getPoseValue((this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand);
|
||||||
var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
|
||||||
var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(controllerHandInput).rotation);
|
// transform it into world frame
|
||||||
|
var controllerPosition = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation));
|
||||||
|
var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation);
|
||||||
|
|
||||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
|
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||||
|
|
||||||
|
@ -1125,66 +1131,27 @@ function MyController(hand) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var now = Date.now();
|
||||||
|
this.currentObjectTime = now;
|
||||||
|
|
||||||
// the action was set up on a previous call. update the targets.
|
// the action was set up on a previous call. update the targets.
|
||||||
var radius = Vec3.distance(this.currentObjectPosition, handControllerPosition) *
|
var radius = Vec3.distance(this.currentObjectPosition, controllerPosition) *
|
||||||
this.radiusScalar * DISTANCE_HOLDING_RADIUS_FACTOR;
|
this.radiusScalar * DISTANCE_HOLDING_RADIUS_FACTOR;
|
||||||
if (radius < 1.0) {
|
if (radius < 1.0) {
|
||||||
radius = 1.0;
|
radius = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// how far did avatar move this timestep?
|
// scale delta controller hand movement by radius.
|
||||||
var currentPosition = MyAvatar.position;
|
var handMoved = Vec3.multiply(Vec3.subtract(controllerPosition, this.previousControllerPosition), radius);
|
||||||
var avatarDeltaPosition = Vec3.subtract(currentPosition, this.currentAvatarPosition);
|
|
||||||
this.currentAvatarPosition = currentPosition;
|
|
||||||
|
|
||||||
// How far did the avatar turn this timestep?
|
// double delta controller rotation
|
||||||
// Note: The following code is too long because we need a Quat.quatBetween() function
|
var handChange = Quat.multiply(Quat.slerp(this.previousControllerRotation,
|
||||||
// that returns the minimum quaternion between two quaternions.
|
controllerRotation,
|
||||||
var currentOrientation = MyAvatar.orientation;
|
DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR),
|
||||||
if (Quat.dot(currentOrientation, this.currentAvatarOrientation) < 0.0) {
|
Quat.inverse(this.previousControllerRotation));
|
||||||
var negativeCurrentOrientation = {
|
|
||||||
x: -currentOrientation.x,
|
|
||||||
y: -currentOrientation.y,
|
|
||||||
z: -currentOrientation.z,
|
|
||||||
w: -currentOrientation.w
|
|
||||||
};
|
|
||||||
var avatarDeltaOrientation = Quat.multiply(negativeCurrentOrientation, Quat.inverse(this.currentAvatarOrientation));
|
|
||||||
} else {
|
|
||||||
var avatarDeltaOrientation = Quat.multiply(currentOrientation, Quat.inverse(this.currentAvatarOrientation));
|
|
||||||
}
|
|
||||||
var handToAvatar = Vec3.subtract(handControllerPosition, this.currentAvatarPosition);
|
|
||||||
var objectToAvatar = Vec3.subtract(this.currentObjectPosition, this.currentAvatarPosition);
|
|
||||||
var handMovementFromTurning = Vec3.subtract(Quat.multiply(avatarDeltaOrientation, handToAvatar), handToAvatar);
|
|
||||||
var objectMovementFromTurning = Vec3.subtract(Quat.multiply(avatarDeltaOrientation, objectToAvatar), objectToAvatar);
|
|
||||||
this.currentAvatarOrientation = currentOrientation;
|
|
||||||
|
|
||||||
// how far did hand move this timestep?
|
// update the currentObject position and rotation.
|
||||||
var handMoved = Vec3.subtract(handToAvatar, this.handRelativePreviousPosition);
|
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, handMoved);
|
||||||
this.handRelativePreviousPosition = handToAvatar;
|
|
||||||
|
|
||||||
// magnify the hand movement but not the change from avatar movement & rotation
|
|
||||||
handMoved = Vec3.subtract(handMoved, handMovementFromTurning);
|
|
||||||
var superHandMoved = Vec3.multiply(handMoved, radius);
|
|
||||||
|
|
||||||
// Move the object by the magnified amount and then by amount from avatar movement & rotation
|
|
||||||
var newObjectPosition = Vec3.sum(this.currentObjectPosition, superHandMoved);
|
|
||||||
newObjectPosition = Vec3.sum(newObjectPosition, avatarDeltaPosition);
|
|
||||||
newObjectPosition = Vec3.sum(newObjectPosition, objectMovementFromTurning);
|
|
||||||
|
|
||||||
var deltaPosition = Vec3.subtract(newObjectPosition, this.currentObjectPosition); // meters
|
|
||||||
var now = Date.now();
|
|
||||||
var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds
|
|
||||||
|
|
||||||
this.currentObjectPosition = newObjectPosition;
|
|
||||||
this.currentObjectTime = now;
|
|
||||||
|
|
||||||
// this doubles hand rotation
|
|
||||||
var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation,
|
|
||||||
handRotation,
|
|
||||||
DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR),
|
|
||||||
Quat.inverse(this.handPreviousRotation));
|
|
||||||
this.handPreviousRotation = handRotation;
|
|
||||||
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
|
this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation);
|
||||||
|
|
||||||
this.callEntityMethodOnGrabbed("continueDistantGrab");
|
this.callEntityMethodOnGrabbed("continueDistantGrab");
|
||||||
|
@ -1195,6 +1162,7 @@ function MyController(hand) {
|
||||||
|
|
||||||
var handControllerData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultMoveWithHeadData);
|
var handControllerData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultMoveWithHeadData);
|
||||||
|
|
||||||
|
var objectToAvatar = Vec3.subtract(this.currentObjectPosition, MyAvatar.position);
|
||||||
if (handControllerData.disableMoveWithHead !== true) {
|
if (handControllerData.disableMoveWithHead !== true) {
|
||||||
// mix in head motion
|
// mix in head motion
|
||||||
if (MOVE_WITH_HEAD) {
|
if (MOVE_WITH_HEAD) {
|
||||||
|
@ -1234,6 +1202,7 @@ function MyController(hand) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var handPosition = this.getHandPosition();
|
||||||
|
|
||||||
//visualizations
|
//visualizations
|
||||||
if (USE_ENTITY_LINES_FOR_MOVING === true) {
|
if (USE_ENTITY_LINES_FOR_MOVING === true) {
|
||||||
|
@ -1265,6 +1234,9 @@ function MyController(hand) {
|
||||||
} else {
|
} else {
|
||||||
print("continueDistanceHolding -- updateAction failed");
|
print("continueDistanceHolding -- updateAction failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.previousControllerPosition = controllerPosition;
|
||||||
|
this.previousControllerRotation = controllerRotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setupHoldAction = function() {
|
this.setupHoldAction = function() {
|
||||||
|
|
Loading…
Reference in a new issue