mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 17:30:05 +02:00
added lifetime to pointer, default grab behavior now honors objects initial position and rotation
This commit is contained in:
parent
717cbf3d5b
commit
5025030726
2 changed files with 55 additions and 19 deletions
|
@ -11,8 +11,7 @@
|
|||
//
|
||||
|
||||
|
||||
Script.include("../libraries/utils.js");
|
||||
|
||||
Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js");
|
||||
|
||||
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
|
||||
var rightTriggerAction = RIGHT_HAND_CLICK;
|
||||
|
@ -22,6 +21,10 @@ var GRAB_USER_DATA_KEY = "grabKey";
|
|||
var LEFT_HAND_CLICK = Controller.findAction("LEFT_HAND_CLICK");
|
||||
var leftTriggerAction = LEFT_HAND_CLICK;
|
||||
|
||||
var LIFETIME = 10;
|
||||
var currentLife = 0;
|
||||
var POINTER_CHECK_TIME = 5000;
|
||||
|
||||
var ZERO_VEC = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
|
@ -42,7 +45,7 @@ var INTERSECT_COLOR = {
|
|||
blue: 10
|
||||
};
|
||||
|
||||
var GRAB_RADIUS = 1.0;
|
||||
var GRAB_RADIUS = 1.5;
|
||||
|
||||
var GRAB_COLOR = {
|
||||
red: 250,
|
||||
|
@ -59,8 +62,15 @@ var TRACTOR_BEAM_VELOCITY_THRESHOLD = 0.5;
|
|||
|
||||
var RIGHT = 1;
|
||||
var LEFT = 0;
|
||||
var rightController = new controller(RIGHT, rightTriggerAction, right4Action, "right")
|
||||
var leftController = new controller(LEFT, leftTriggerAction, left4Action, "left")
|
||||
var rightController = new controller(RIGHT, rightTriggerAction, right4Action, "right");
|
||||
var leftController = new controller(LEFT, leftTriggerAction, left4Action, "left");
|
||||
|
||||
|
||||
//Need to wait before calling these methods for some reason...
|
||||
Script.setTimeout(function() {
|
||||
rightController.checkPointer();
|
||||
leftController.checkPointer();
|
||||
}, 100)
|
||||
|
||||
function controller(side, triggerAction, pullAction, hand) {
|
||||
this.hand = hand;
|
||||
|
@ -92,7 +102,9 @@ function controller(side, triggerAction, pullAction, hand) {
|
|||
z: 1000
|
||||
},
|
||||
visible: false,
|
||||
lifetime: LIFETIME
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,6 +139,18 @@ controller.prototype.updateLine = function() {
|
|||
}
|
||||
|
||||
|
||||
controller.prototype.checkPointer = function() {
|
||||
var self = this;
|
||||
Script.setTimeout(function() {
|
||||
var props = Entities.getEntityProperties(self.pointer);
|
||||
var currentLife = LIFETIME + POINTER_CHECK_TIME + currentLife;
|
||||
//dimensions are set to .1, .1, .1 when lifetime expires
|
||||
Entities.editEntity(self.pointer, {
|
||||
lifetime: currentLife
|
||||
});
|
||||
self.checkPointer();
|
||||
}, POINTER_CHECK_TIME);
|
||||
}
|
||||
|
||||
controller.prototype.checkForIntersections = function(origin, direction) {
|
||||
var pickRay = {
|
||||
|
@ -241,14 +265,22 @@ controller.prototype.grabEntity = function() {
|
|||
this.closeGrabbing = true;
|
||||
//check if our entity has instructions on how to be grabbed, otherwise, just use default relative position and rotation
|
||||
var userData = getEntityUserData(this.grabbedEntity);
|
||||
var relativePosition = ZERO_VEC;
|
||||
var relativeRotation = Quat.fromPitchYawRollDegrees(0, 0, 0);
|
||||
if(userData.spatialKey) {
|
||||
if(userData.spatialKey.relativePosition) {
|
||||
relativePosition = userData.spatialKey.relativePosition;
|
||||
|
||||
var objectRotation = Entities.getEntityProperties(this.grabbedEntity).rotation;
|
||||
var offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
||||
|
||||
var objectPosition = Entities.getEntityProperties(this.grabbedEntity).position;
|
||||
var offset = Vec3.subtract(objectPosition, handPosition);
|
||||
var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset);
|
||||
|
||||
var relativePosition = offsetPosition;
|
||||
var relativeRotation = offsetRotation;
|
||||
if (userData.grabFrame) {
|
||||
if (userData.grabFrame.relativePosition) {
|
||||
relativePosition = userData.grabFrame.relativePosition;
|
||||
}
|
||||
if(userData.spatialKey.relativeRotation) {
|
||||
relativeRotation = userData.spatialKey.relativeRotation;
|
||||
if (userData.grabFrame.relativeRotation) {
|
||||
relativeRotation = userData.grabFrame.relativeRotation;
|
||||
}
|
||||
}
|
||||
this.actionID = Entities.addAction("hold", this.grabbedEntity, {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
(function() {
|
||||
Script.include("../libraries/utils.js");
|
||||
SPATIAL_USER_DATA_KEY = "spatialKey";
|
||||
GRAB_FRAME_USER_DATA_KEY = "grabFrame";
|
||||
this.userData = {};
|
||||
|
||||
var TIP_OFFSET_Z = 0.14;
|
||||
|
@ -62,13 +62,14 @@
|
|||
this.sprayStream = function() {
|
||||
var forwardVec = Quat.getFront(self.properties.rotation);
|
||||
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
|
||||
forwardVec = Vec3.normalize(forwardVec);
|
||||
|
||||
var upVec = Quat.getUp(self.properties.rotation);
|
||||
var position = Vec3.sum(self.properties.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z));
|
||||
position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y))
|
||||
Entities.editEntity(self.paintStream, {
|
||||
position: position,
|
||||
emitVelocity: forwardVec
|
||||
emitVelocity: Vec3.multiply(forwardVec, 4)
|
||||
});
|
||||
|
||||
//Now check for an intersection with an entity
|
||||
|
@ -155,12 +156,16 @@
|
|||
if (this.userData.grabKey && this.userData.grabKey.activated) {
|
||||
this.activated = true;
|
||||
}
|
||||
if(!this.userData.spatialKey) {
|
||||
if (!this.userData.grabFrame) {
|
||||
var data = {
|
||||
relativePosition: {x: 0, y: 0, z: 0},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0,0)
|
||||
relativePosition: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0)
|
||||
}
|
||||
setEntityCustomData(SPATIAL_USER_DATA_KEY, this.entityId, data);
|
||||
setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data);
|
||||
}
|
||||
this.initialize();
|
||||
}
|
||||
|
@ -174,7 +179,6 @@
|
|||
running: false
|
||||
});
|
||||
|
||||
|
||||
this.paintStream = Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
animationSettings: animationSettings,
|
||||
|
|
Loading…
Reference in a new issue