mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
rotateable lid
This commit is contained in:
parent
416c8752b3
commit
30b32f27f8
2 changed files with 13 additions and 82 deletions
|
@ -46,20 +46,7 @@
|
||||||
startNearTrigger: function() {
|
startNearTrigger: function() {
|
||||||
this.getParts();
|
this.getParts();
|
||||||
},
|
},
|
||||||
getGrabConstraints: function() {
|
|
||||||
var defaultConstraints = {
|
|
||||||
positionLocked: false,
|
|
||||||
rotationLocked: false,
|
|
||||||
positionMod: false,
|
|
||||||
rotationMod: {
|
|
||||||
pitch: false,
|
|
||||||
yaw: false,
|
|
||||||
roll: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var constraints = getEntityCustomData(GRAB_CONSTRAINTS_USER_DATA_KEY, this.grabbedEntity, defaultConstraints);
|
|
||||||
return constraints;
|
|
||||||
},
|
|
||||||
getHandPosition: function() {
|
getHandPosition: function() {
|
||||||
if (this.hand === 'left') {
|
if (this.hand === 'left') {
|
||||||
return MyAvatar.getLeftPalmPosition();
|
return MyAvatar.getLeftPalmPosition();
|
||||||
|
@ -71,66 +58,24 @@
|
||||||
},
|
},
|
||||||
continueNearTrigger: function(myID, paramsArray) {
|
continueNearTrigger: function(myID, paramsArray) {
|
||||||
paramsArray.forEach(function(param, index) {
|
paramsArray.forEach(function(param, index) {
|
||||||
print('PARAM::' + param)
|
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
_this.hand = param;
|
_this.hand = param;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
print('HAND:: ' + _this.hand);
|
|
||||||
|
|
||||||
var constraints = this.getGrabConstraints();
|
|
||||||
var handPosition = this.getHandPosition();
|
|
||||||
|
|
||||||
|
|
||||||
var modTypes = [];
|
|
||||||
if (constraints.rotationMod !== false) {
|
|
||||||
if (constraints.rotationMod.pitch !== false) {
|
|
||||||
modTypes.push('pitch')
|
|
||||||
}
|
|
||||||
if (constraints.rotationMod.yaw !== false) {
|
|
||||||
modTypes.push('yaw')
|
|
||||||
}
|
|
||||||
if (constraints.rotationMod.roll !== false) {
|
|
||||||
modTypes.push('roll')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var properties = Entities.getEntityProperties(this.entityID);
|
|
||||||
|
|
||||||
// var constraints = this.getGrabConstraints();
|
|
||||||
// if (constraints.rotationMod !== false) {
|
|
||||||
// //implement the rotation modifier
|
|
||||||
// var grabbedProps = Entities.getEntityProperties(this.grabbedEntity);
|
|
||||||
|
|
||||||
var handPosition = this.getHandPosition();
|
|
||||||
|
|
||||||
var modTypes = [];
|
|
||||||
|
|
||||||
if (constraints.rotationMod.pitch !== false) {
|
|
||||||
modTypes.push('pitch')
|
|
||||||
}
|
|
||||||
if (constraints.rotationMod.yaw !== false) {
|
|
||||||
modTypes.push('yaw')
|
|
||||||
}
|
|
||||||
if (constraints.rotationMod.roll !== false) {
|
|
||||||
modTypes.push('roll')
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the base position
|
// get the base position
|
||||||
// get the hand position
|
// get the hand position
|
||||||
//
|
// get the distance between
|
||||||
|
// use that value to scale the angle of the lid rotation
|
||||||
|
|
||||||
var baseProps = Entities.getEntityProperties(_this.base);
|
var baseProps = Entities.getEntityProperties(_this.base);
|
||||||
var baseBoxPosition = baseProps.position;
|
var baseBoxPosition = baseProps.position;
|
||||||
var handPosition = _this.getHandPosition();
|
var handPosition = _this.getHandPosition();
|
||||||
var lidProps = Entities.getEntityProperties(_this.entityID);
|
var lidProps = Entities.getEntityProperties(_this.entityID);
|
||||||
|
|
||||||
var distaceHandToBaseBox = Vec3.distance(baseBoxPosition, handPosition);
|
var distaceHandToBaseBox = Vec3.distance(baseBoxPosition, handPosition);
|
||||||
|
|
||||||
var safeEuler = Quat.safeEulerAngles()
|
var safeEuler = Quat.safeEulerAngles(baseProps.rotation);
|
||||||
var finalRotation = {
|
var finalRotation = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
@ -142,7 +87,7 @@
|
||||||
|
|
||||||
var maxDistance = 0.4;
|
var maxDistance = 0.4;
|
||||||
|
|
||||||
var finalAngle = scale(distance, 0, maxDistance, 0, 75)
|
var finalAngle = scaleValue(distaceHandToBaseBox, 0.1, maxDistance, 0, 75)
|
||||||
|
|
||||||
print('FINAL ANGLE:: ' + finalAngle);
|
print('FINAL ANGLE:: ' + finalAngle);
|
||||||
|
|
||||||
|
@ -153,10 +98,9 @@
|
||||||
finalAngle = 75;
|
finalAngle = 75;
|
||||||
}
|
}
|
||||||
finalRotation.z = finalAngle;
|
finalRotation.z = finalAngle;
|
||||||
|
|
||||||
_this.handleLidActivities(finalRotation)
|
_this.handleLidActivities(finalRotation)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleLidActivities: function(finalRotation) {
|
handleLidActivities: function(finalRotation) {
|
||||||
|
@ -185,10 +129,10 @@
|
||||||
this.stopHat();
|
this.stopHat();
|
||||||
}
|
}
|
||||||
|
|
||||||
var hatHeight = scaleValue(constraint, MIN_LID_ROTATION, MAX_LID_ROTATION, 0, 0.04);
|
var hatHeight = scaleValue(constraint, 0, 75, 0, 0.04);
|
||||||
|
|
||||||
Entities.editEntity(this.entityID, {
|
Entities.editEntity(this.entityID, {
|
||||||
rotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z)
|
localRotation: Quat.fromPitchYawRollDegrees(finalRotation.x, finalRotation.y, finalRotation.z)
|
||||||
})
|
})
|
||||||
|
|
||||||
var VERTICAL_OFFSET = 0.025;
|
var VERTICAL_OFFSET = 0.025;
|
||||||
|
|
|
@ -80,26 +80,13 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
|
||||||
position: startPosition,
|
position: startPosition,
|
||||||
parentID: baseID,
|
parentID: baseID,
|
||||||
registrationPoint: LID_REGISTRATION_POINT,
|
registrationPoint: LID_REGISTRATION_POINT,
|
||||||
dynamic: false,
|
dynamic: true,
|
||||||
script: LID_SCRIPT_URL,
|
script: LID_SCRIPT_URL,
|
||||||
collidesWith: 'myAvatar,otherAvatar',
|
collidesWith: 'myAvatar,otherAvatar',
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
'hifiHomeKey': {
|
'hifiHomeKey': {
|
||||||
'reset': true
|
'reset': true
|
||||||
},
|
},
|
||||||
grabConstraintsKey: {
|
|
||||||
rotationMod: {
|
|
||||||
pitch: false,
|
|
||||||
yaw: false,
|
|
||||||
roll: {
|
|
||||||
min: 0,
|
|
||||||
max: 75,
|
|
||||||
startingAxis: 'y',
|
|
||||||
startingPoint: startPosition.y,
|
|
||||||
distanceToMax: startPosition.y + 0.35
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
grabbableKey: {
|
grabbableKey: {
|
||||||
wantsTrigger: true,
|
wantsTrigger: true,
|
||||||
disableReleaseVelocity: true
|
disableReleaseVelocity: true
|
||||||
|
@ -184,9 +171,9 @@ HomeMusicBox = function(spawnPosition, spawnRotation) {
|
||||||
name: 'home_music_box_base',
|
name: 'home_music_box_base',
|
||||||
type: 'Model',
|
type: 'Model',
|
||||||
position: BASE_POSITION,
|
position: BASE_POSITION,
|
||||||
// dynamic: true,
|
dynamic: true,
|
||||||
// shapeType: 'compound',
|
shapeType: 'compound',
|
||||||
// compoundShapeURL: 'atp:/boxHull2.obj',
|
compoundShapeURL: 'atp:/boxHull2.obj',
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: 0.1661,
|
x: 0.1661,
|
||||||
y: 0.0928,
|
y: 0.0928,
|
||||||
|
|
Loading…
Reference in a new issue