mirror of
https://github.com/overte-org/overte.git
synced 2025-08-17 09:15:37 +02:00
cleanup orientation of
This commit is contained in:
parent
595c628c39
commit
2b8ad51b41
5 changed files with 84 additions and 87 deletions
|
@ -87,12 +87,13 @@ var ACTION_TTL_REFRESH = 5;
|
|||
var PICKS_PER_SECOND_PER_HAND = 10;
|
||||
var MSECS_PER_SEC = 1000.0;
|
||||
var GRABBABLE_PROPERTIES = ["position",
|
||||
"rotation",
|
||||
"gravity",
|
||||
"ignoreForCollisions",
|
||||
"collisionsWillMove",
|
||||
"locked",
|
||||
"name"];
|
||||
"rotation",
|
||||
"gravity",
|
||||
"ignoreForCollisions",
|
||||
"collisionsWillMove",
|
||||
"locked",
|
||||
"name"
|
||||
];
|
||||
|
||||
|
||||
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
||||
|
@ -103,7 +104,7 @@ var DEFAULT_GRABBABLE_DATA = {
|
|||
invertSolidWhileHeld: false
|
||||
};
|
||||
|
||||
var disabledHand ='none';
|
||||
var disabledHand = 'none';
|
||||
|
||||
|
||||
// states for the state machine
|
||||
|
@ -122,28 +123,28 @@ var STATE_RELEASE = 10;
|
|||
|
||||
function stateToName(state) {
|
||||
switch (state) {
|
||||
case STATE_OFF:
|
||||
return "off";
|
||||
case STATE_SEARCHING:
|
||||
return "searching";
|
||||
case STATE_DISTANCE_HOLDING:
|
||||
return "distance_holding";
|
||||
case STATE_CONTINUE_DISTANCE_HOLDING:
|
||||
return "continue_distance_holding";
|
||||
case STATE_NEAR_GRABBING:
|
||||
return "near_grabbing";
|
||||
case STATE_CONTINUE_NEAR_GRABBING:
|
||||
return "continue_near_grabbing";
|
||||
case STATE_NEAR_TRIGGER:
|
||||
return "near_trigger";
|
||||
case STATE_CONTINUE_NEAR_TRIGGER:
|
||||
return "continue_near_trigger";
|
||||
case STATE_FAR_TRIGGER:
|
||||
return "far_trigger";
|
||||
case STATE_CONTINUE_FAR_TRIGGER:
|
||||
return "continue_far_trigger";
|
||||
case STATE_RELEASE:
|
||||
return "release";
|
||||
case STATE_OFF:
|
||||
return "off";
|
||||
case STATE_SEARCHING:
|
||||
return "searching";
|
||||
case STATE_DISTANCE_HOLDING:
|
||||
return "distance_holding";
|
||||
case STATE_CONTINUE_DISTANCE_HOLDING:
|
||||
return "continue_distance_holding";
|
||||
case STATE_NEAR_GRABBING:
|
||||
return "near_grabbing";
|
||||
case STATE_CONTINUE_NEAR_GRABBING:
|
||||
return "continue_near_grabbing";
|
||||
case STATE_NEAR_TRIGGER:
|
||||
return "near_trigger";
|
||||
case STATE_CONTINUE_NEAR_TRIGGER:
|
||||
return "continue_near_trigger";
|
||||
case STATE_FAR_TRIGGER:
|
||||
return "far_trigger";
|
||||
case STATE_CONTINUE_FAR_TRIGGER:
|
||||
return "continue_far_trigger";
|
||||
case STATE_RELEASE:
|
||||
return "release";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
|
@ -195,8 +196,17 @@ function MyController(hand) {
|
|||
this.triggerValue = 0; // rolling average of trigger value
|
||||
this.rawTriggerValue = 0;
|
||||
|
||||
this.offsetPosition = { x: 0.0, y: 0.0, z: 0.0 };
|
||||
this.offsetRotation = { x: 0.0, y: 0.0, z: 0.0, w: 1.0 };
|
||||
this.offsetPosition = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0
|
||||
};
|
||||
this.offsetRotation = {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0,
|
||||
w: 1.0
|
||||
};
|
||||
|
||||
var _this = this;
|
||||
|
||||
|
@ -293,11 +303,11 @@ function MyController(hand) {
|
|||
this.pointer = null;
|
||||
};
|
||||
|
||||
this.eitherTrigger = function (value) {
|
||||
this.eitherTrigger = function(value) {
|
||||
_this.rawTriggerValue = value;
|
||||
};
|
||||
|
||||
this.updateSmoothedTrigger = function () {
|
||||
this.updateSmoothedTrigger = function() {
|
||||
var triggerValue = this.rawTriggerValue;
|
||||
// smooth out trigger value
|
||||
this.triggerValue = (this.triggerValue * TRIGGER_SMOOTH_RATIO) +
|
||||
|
@ -412,10 +422,9 @@ function MyController(hand) {
|
|||
this.setState(STATE_NEAR_GRABBING);
|
||||
return;
|
||||
}
|
||||
} else if (! entityIsGrabbedByOther(intersection.entityID)) {
|
||||
} else if (!entityIsGrabbedByOther(intersection.entityID)) {
|
||||
// don't allow two people to distance grab the same object
|
||||
if (intersection.properties.collisionsWillMove
|
||||
&& !intersection.properties.locked) {
|
||||
if (intersection.properties.collisionsWillMove && !intersection.properties.locked) {
|
||||
// the hand is far from the intersected object. go into distance-holding mode
|
||||
this.grabbedEntity = intersection.entityID;
|
||||
this.setState(STATE_DISTANCE_HOLDING);
|
||||
|
@ -434,10 +443,18 @@ function MyController(hand) {
|
|||
Entities.addEntity({
|
||||
type: "Sphere",
|
||||
name: "Grab Debug Entity",
|
||||
dimensions: {x: GRAB_RADIUS, y: GRAB_RADIUS, z: GRAB_RADIUS},
|
||||
dimensions: {
|
||||
x: GRAB_RADIUS,
|
||||
y: GRAB_RADIUS,
|
||||
z: GRAB_RADIUS
|
||||
},
|
||||
visible: true,
|
||||
position: handPosition,
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
color: {
|
||||
red: 0,
|
||||
green: 255,
|
||||
blue: 0
|
||||
},
|
||||
lifetime: 0.1
|
||||
});
|
||||
}
|
||||
|
@ -704,7 +721,7 @@ function MyController(hand) {
|
|||
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
|
||||
}
|
||||
Entities.callEntityMethod(this.grabbedEntity, "startNearGrab");
|
||||
|
||||
|
||||
setEntityCustomData('hifiHoldActionKey', this.grabbedEntity, {
|
||||
holdActionID: this.actionID
|
||||
})
|
||||
|
@ -758,7 +775,7 @@ function MyController(hand) {
|
|||
|
||||
if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) {
|
||||
// if less than a 5 seconds left, refresh the actions ttl
|
||||
Entities.updateAction(this.grabbedEntity, this.actionID, {
|
||||
var success = Entities.updateAction(this.grabbedEntity, this.actionID, {
|
||||
hand: this.hand === RIGHT_HAND ? "right" : "left",
|
||||
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
||||
relativePosition: this.offsetPosition,
|
||||
|
@ -767,6 +784,8 @@ function MyController(hand) {
|
|||
kinematic: NEAR_GRABBING_KINEMATIC,
|
||||
kinematicSetVelocity: true
|
||||
});
|
||||
|
||||
print('Action update success:::' + success);
|
||||
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
||||
}
|
||||
};
|
||||
|
@ -944,7 +963,13 @@ function MyController(hand) {
|
|||
data["gravity"] = grabbedProperties.gravity;
|
||||
data["ignoreForCollisions"] = grabbedProperties.ignoreForCollisions;
|
||||
data["collisionsWillMove"] = grabbedProperties.collisionsWillMove;
|
||||
var whileHeldProperties = {gravity: {x:0, y:0, z:0}};
|
||||
var whileHeldProperties = {
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
};
|
||||
if (invertSolidWhileHeld) {
|
||||
whileHeldProperties["ignoreForCollisions"] = !grabbedProperties.ignoreForCollisions;
|
||||
}
|
||||
|
@ -996,4 +1021,4 @@ function cleanup() {
|
|||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
Script.update.connect(update);
|
||||
Script.update.connect(update);
|
|
@ -103,13 +103,8 @@
|
|||
},
|
||||
|
||||
disableGrab: function() {
|
||||
|
||||
|
||||
var actionID = this.getActionID();
|
||||
|
||||
print('actionID' + actionID)
|
||||
var success = Entities.deleteAction(this.entityID, actionID);
|
||||
print('ACTION DELETE SUCCESS:::'+success)
|
||||
var success = Entities.deleteAction(this.entityID, actionID);
|
||||
},
|
||||
|
||||
tellBowArrowIsNotched: function(bowID) {
|
||||
|
@ -141,10 +136,10 @@
|
|||
});
|
||||
|
||||
},
|
||||
update:function(){
|
||||
update: function() {
|
||||
|
||||
// var actions = Entities.getActionIDs(_this.entityID);
|
||||
// print('ACTIONS ON ME:::'+actions)
|
||||
// var actions = Entities.getActionIDs(_this.entityID);
|
||||
// print('ACTIONS ON ME:::'+actions)
|
||||
},
|
||||
|
||||
checkIfBurning: function() {
|
||||
|
|
|
@ -416,35 +416,12 @@
|
|||
return arrowPosition;
|
||||
},
|
||||
|
||||
orientationOf: function(vector) {
|
||||
var Y_AXIS = {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
};
|
||||
var X_AXIS = {
|
||||
x: 1,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
var theta = 0.0;
|
||||
|
||||
var RAD_TO_DEG = 180.0 / Math.PI;
|
||||
var direction, yaw, pitch;
|
||||
direction = Vec3.normalize(vector);
|
||||
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
|
||||
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
|
||||
return Quat.multiply(yaw, pitch);
|
||||
},
|
||||
|
||||
|
||||
updateArrowPositionInNotch: function() {
|
||||
//move it backwards
|
||||
|
||||
|
||||
var handToNotch = Vec3.subtract(this.notchDetectorPosition,this.stringData.handPosition);
|
||||
print('h2n:::'+JSON.stringify(handToNotch))
|
||||
|
||||
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
|
||||
print('h2n:::' + JSON.stringify(handToNotch))
|
||||
var pullBackDistance = Vec3.length(handToNotch);
|
||||
|
||||
if (pullBackDistance >= 0.6) {
|
||||
|
@ -461,16 +438,16 @@
|
|||
|
||||
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
|
||||
|
||||
print('ARROW ROTATION:: ' + JSON.stringify(arrowRotation));
|
||||
print('ARROW ROTATION:: ' + JSON.stringify(arrowRotation));
|
||||
Entities.editEntity(this.arrow, {
|
||||
position: finalArrowPosition,
|
||||
rotation: arrowRotation
|
||||
})
|
||||
|
||||
var currentRotation = Entities.getEntityProperties(this.arrow, "rotation").rotation
|
||||
// print('ACTUAL ARROW ROTATION::' +JSON.stringify(currentRotation));
|
||||
var currentRotation = Entities.getEntityProperties(this.arrow, "rotation").rotation
|
||||
// print('ACTUAL ARROW ROTATION::' +JSON.stringify(currentRotation));
|
||||
|
||||
// print('DIFFERENCE::: ' + (1 - Quat.dot(arrowRotation, currentRotation)));
|
||||
// print('DIFFERENCE::: ' + (1 - Quat.dot(arrowRotation, currentRotation)));
|
||||
// if (this.arrowIsBurning === true) {
|
||||
// Entities.editEntity(this.fire, {
|
||||
// position: arrowTipPosition
|
||||
|
@ -486,7 +463,7 @@
|
|||
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
|
||||
var pullBackDistance = Vec3.length(handToNotch);
|
||||
|
||||
var arrowRotation = this.orientationOf(handToNotch);
|
||||
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
|
||||
|
||||
print('HAND DISTANCE:: ' + pullBackDistance);
|
||||
var arrowForce = this.scaleArrowShotStrength(pullBackDistance, 0, 2, 20, 50);
|
||||
|
@ -538,7 +515,7 @@
|
|||
var detectorProperties = {
|
||||
name: 'Hifi-NotchDetector',
|
||||
type: 'Box',
|
||||
visible: true,
|
||||
visible: false,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
dimensions: NOTCH_DETECTOR_DIMENSIONS,
|
||||
|
@ -572,7 +549,7 @@
|
|||
|
||||
Entities.editEntity(this.notchDetector, {
|
||||
position: this.notchDetectorPosition,
|
||||
rotation:this.bowProperties.rotation
|
||||
rotation: this.bowProperties.rotation
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow.fbx";
|
||||
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow_collision_hull.obj";
|
||||
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js?123');
|
||||
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
|
||||
|
||||
var ARROW_DIMENSIONS = {
|
||||
x: 0.02,
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
Script.include("createBow.js?123");
|
||||
Script.include("createArrow.js?123");
|
||||
Script.include("createBow.js");
|
||||
Script.include("createArrow.js");
|
||||
|
|
Loading…
Reference in a new issue