make distance-grab work better when avatar is walking

This commit is contained in:
Seth Alves 2016-05-20 15:45:00 -07:00
parent 95f7ea5609
commit a24d63a39c

View file

@ -1112,8 +1112,8 @@ function MyController(hand) {
Controller.getPoseValue((this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand); Controller.getPoseValue((this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand);
// transform it into world frame // transform it into world frame
var controllerPosition = Vec3.sum(MyAvatar.position, var controllerPositionVSAvatar = Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation);
Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation)); var controllerPosition = Vec3.sum(MyAvatar.position, controllerPositionVSAvatar);
var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation); var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation);
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
@ -1161,7 +1161,7 @@ function MyController(hand) {
this.turnOffVisualizations(); this.turnOffVisualizations();
this.previousControllerPosition = controllerPosition; this.previousControllerPositionVSAvatar = controllerPositionVSAvatar;
this.previousControllerRotation = controllerRotation; this.previousControllerRotation = controllerRotation;
}; };
@ -1179,8 +1179,8 @@ function MyController(hand) {
Controller.Standard.RightHand : Controller.Standard.LeftHand); Controller.Standard.RightHand : Controller.Standard.LeftHand);
// transform it into world frame // transform it into world frame
var controllerPosition = Vec3.sum(MyAvatar.position, var controllerPositionVSAvatar = Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation);
Vec3.multiplyQbyV(MyAvatar.orientation, avatarControllerPose.translation)); var controllerPosition = Vec3.sum(MyAvatar.position, controllerPositionVSAvatar);
var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation); var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation);
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
@ -1197,7 +1197,8 @@ function MyController(hand) {
} }
// scale delta controller hand movement by radius. // scale delta controller hand movement by radius.
var handMoved = Vec3.multiply(Vec3.subtract(controllerPosition, this.previousControllerPosition), radius); var handMoved = Vec3.multiply(Vec3.subtract(controllerPositionVSAvatar, this.previousControllerPositionVSAvatar),
radius);
// double delta controller rotation // double delta controller rotation
var handChange = Quat.multiply(Quat.slerp(this.previousControllerRotation, var handChange = Quat.multiply(Quat.slerp(this.previousControllerRotation,
@ -1218,7 +1219,7 @@ function MyController(hand) {
var handControllerData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultMoveWithHeadData); var handControllerData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultMoveWithHeadData);
// Update radialVelocity // Update radialVelocity
var lastVelocity = Vec3.subtract(controllerPosition, this.previousControllerPosition); var lastVelocity = Vec3.subtract(controllerPositionVSAvatar, this.previousControllerPositionVSAvatar);
lastVelocity = Vec3.multiply(lastVelocity, 1.0 / deltaTime); lastVelocity = Vec3.multiply(lastVelocity, 1.0 / deltaTime);
var newRadialVelocity = Vec3.dot(lastVelocity, var newRadialVelocity = Vec3.dot(lastVelocity,
Vec3.normalize(Vec3.subtract(grabbedProperties.position, controllerPosition))); Vec3.normalize(Vec3.subtract(grabbedProperties.position, controllerPosition)));
@ -1266,7 +1267,9 @@ function MyController(hand) {
var clampedVector; var clampedVector;
var targetPosition; var targetPosition;
if (constraintData.axisStart !== false) { if (constraintData.axisStart !== false) {
clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisStart, constraintData.axisEnd); clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition,
constraintData.axisStart,
constraintData.axisEnd);
targetPosition = clampedVector; targetPosition = clampedVector;
} else { } else {
targetPosition = { targetPosition = {
@ -1309,7 +1312,7 @@ function MyController(hand) {
print("continueDistanceHolding -- updateAction failed"); print("continueDistanceHolding -- updateAction failed");
} }
this.previousControllerPosition = controllerPosition; this.previousControllerPositionVSAvatar = controllerPositionVSAvatar;
this.previousControllerRotation = controllerRotation; this.previousControllerRotation = controllerRotation;
}; };