Merge pull request #6593 from Atlante45/master

Update toys relativeRotation/Position
This commit is contained in:
Brad Hefta-Gaub 2015-12-10 07:37:08 -08:00
commit 1512703182
5 changed files with 55 additions and 49 deletions

View file

@ -202,31 +202,41 @@ function entityIsGrabbedByOther(entityID) {
}
function getSpatialOffsetPosition(hand, spatialKey) {
var position = Vec3.ZERO;
if (hand !== RIGHT_HAND && spatialKey.leftRelativePosition) {
return spatialKey.leftRelativePosition;
position = spatialKey.leftRelativePosition;
}
if (hand === RIGHT_HAND && spatialKey.rightRelativePosition) {
return spatialKey.rightRelativePosition;
position = spatialKey.rightRelativePosition;
}
if (spatialKey.relativePosition) {
return spatialKey.relativePosition;
position = spatialKey.relativePosition;
}
return Vec3.ZERO;
return position;
}
var yFlip = Quat.angleAxis(180, Vec3.UNIT_Y);
function getSpatialOffsetRotation(hand, spatialKey) {
var rotation = Quat.IDENTITY;
if (hand !== RIGHT_HAND && spatialKey.leftRelativeRotation) {
return spatialKey.leftRelativeRotation;
rotation = spatialKey.leftRelativeRotation;
}
if (hand === RIGHT_HAND && spatialKey.rightRelativeRotation) {
return spatialKey.rightRelativeRotation;
rotation = spatialKey.rightRelativeRotation;
}
if (spatialKey.relativeRotation) {
return spatialKey.relativeRotation;
rotation = spatialKey.relativeRotation;
}
return Quat.IDENTITY;
// Flip left hand
if (hand !== RIGHT_HAND) {
rotation = Quat.multiply(yFlip, rotation);
}
return rotation;
}
function MyController(hand) {
@ -254,6 +264,7 @@ function MyController(hand) {
this.overlayLine = null;
this.ignoreIK = false;
this.offsetPosition = Vec3.ZERO;
this.offsetRotation = Quat.IDENTITY;
@ -853,9 +864,12 @@ function MyController(hand) {
if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) {
// if an object is "equipped" and has a spatialKey, use it.
this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false;
this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
} else {
this.ignoreIK = false;
var objectRotation = grabbedProperties.rotation;
this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
@ -872,7 +886,8 @@ function MyController(hand) {
relativeRotation: this.offsetRotation,
ttl: ACTION_TTL,
kinematic: NEAR_GRABBING_KINEMATIC,
kinematicSetVelocity: true
kinematicSetVelocity: true,
ignoreIK: this.ignoreIK
});
if (this.actionID === NULL_ACTION_ID) {
this.actionID = null;
@ -956,7 +971,8 @@ function MyController(hand) {
relativeRotation: this.offsetRotation,
ttl: ACTION_TTL,
kinematic: NEAR_GRABBING_KINEMATIC,
kinematicSetVelocity: true
kinematicSetVelocity: true,
ignoreIK: this.ignoreIK
});
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
}
@ -982,6 +998,7 @@ function MyController(hand) {
// use a spring to pull the object to where it will be when equipped
var relativeRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
var relativePosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
var ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false;
var handRotation = this.getHandRotation();
var handPosition = this.getHandPosition();
var targetRotation = Quat.multiply(handRotation, relativeRotation);
@ -996,7 +1013,8 @@ function MyController(hand) {
linearTimeScale: EQUIP_SPRING_TIMEFRAME,
targetRotation: targetRotation,
angularTimeScale: EQUIP_SPRING_TIMEFRAME,
ttl: ACTION_TTL
ttl: ACTION_TTL,
ignoreIK: ignoreIK
});
if (this.equipSpringID === NULL_ACTION_ID) {
this.equipSpringID = null;
@ -1009,7 +1027,8 @@ function MyController(hand) {
linearTimeScale: EQUIP_SPRING_TIMEFRAME,
targetRotation: targetRotation,
angularTimeScale: EQUIP_SPRING_TIMEFRAME,
ttl: ACTION_TTL
ttl: ACTION_TTL,
ignoreIK: ignoreIK
});
}

View file

@ -66,21 +66,6 @@
max2: 15
}
var BOW_SPATIAL_KEY = {
leftRelativePosition: {
x: 0.05,
y: 0.06,
z: -0.05
},
rightRelativePosition: {
x: -0.05,
y: 0.06,
z: -0.05
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90)
}
var USE_DEBOUNCE = false;
var TRIGGER_CONTROLS = [
@ -168,11 +153,9 @@
var handToDisable = this.initialHand === 'right' ? 'left' : 'right';
Messages.sendMessage('Hifi-Hand-Disabler', handToDisable);
setEntityCustomData('grabbableKey', this.entityID, {
grabbable: false,
invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
});
var data = getEntityCustomData('grabbableKey', this.entityID, {});
data.grabbable = false;
setEntityCustomData('grabbableKey', this.entityID, data);
},
continueNearGrab: function() {
@ -226,11 +209,10 @@
this.isGrabbed = false;
this.stringDrawn = false;
this.deleteStrings();
setEntityCustomData('grabbableKey', this.entityID, {
grabbable: true,
invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
});
var data = getEntityCustomData('grabbableKey', this.entityID, {});
data.grabbable = true;
setEntityCustomData('grabbableKey', this.entityID, data);
Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
this.aiming = false;

View file

@ -49,14 +49,14 @@ var bow = Entities.addEntity({
invertSolidWhileHeld: true,
spatialKey: {
leftRelativePosition: {
x: 0.05,
y: 0.06,
z: -0.05
x: -0.02,
y: 0.08,
z: 0.09
},
rightRelativePosition: {
x: -0.05,
y: 0.06,
z: -0.05
relativePosition: {
x: 0.02,
y: 0.08,
z: 0.09
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, -90)
}

View file

@ -53,8 +53,13 @@ var wand = Entities.addEntity({
y: 0.1,
z: 0
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 90)
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, -90)
}
}
})
});
});
function scriptEnding() {
Entities.deleteEntity(wand);
}
Script.scriptEnding.connect(scriptEnding);

View file

@ -28,10 +28,10 @@ var pistol = Entities.addEntity({
spatialKey: {
relativePosition: {
x: 0,
y: 0,
z: 0
y: 0.05,
z: -0.08
},
relativeRotation: Quat.fromPitchYawRollDegrees(45, 90, 0)
relativeRotation: Quat.fromPitchYawRollDegrees(90, 90, 0)
},
invertSolidWhileHeld: true
}