From 1beec0dbe7c46327bc0553734fa5871bbf3fc90d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Dec 2015 18:15:05 -0800 Subject: [PATCH] balls --- examples/controllers/handControllerGrab.js | 21 ++++++---- examples/flowArts/arcBall/arcBall.js | 11 ++++- .../flowArts/arcBall/arcBallEntityScript.js | 42 ++++++++++++------- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 07894b46d1..fb7ba8a4f6 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -861,20 +861,25 @@ function MyController(hand) { var handPosition = this.getHandPosition(); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); - + var objectRotation = grabbedProperties.rotation; + var currentObjectPosition = grabbedProperties.position; + var offset = Vec3.subtract(currentObjectPosition, handPosition); 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); + if (grabbableData.spatialKey.relativePosition) { + this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey); + } else { + this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); + } + if (grabbableData.spatialKey.relativeRotation) { + this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey); + } else { + this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); + } } else { this.ignoreIK = false; - - var objectRotation = grabbedProperties.rotation; this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); - - var currentObjectPosition = grabbedProperties.position; - var offset = Vec3.subtract(currentObjectPosition, handPosition); this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); } diff --git a/examples/flowArts/arcBall/arcBall.js b/examples/flowArts/arcBall/arcBall.js index 736920ddd5..f779f65643 100644 --- a/examples/flowArts/arcBall/arcBall.js +++ b/examples/flowArts/arcBall/arcBall.js @@ -26,7 +26,7 @@ ArcBall = function(spawnPosition) { var containerBall = Entities.addEntity({ - type: "Box", + type: "Sphere", name: "Arc Ball", script: scriptURL, position: Vec3.sum(spawnPosition, { @@ -37,7 +37,7 @@ ArcBall = function(spawnPosition) { dimensions: { x: .1, y: .1, - z: .2 + z: .1 }, color: { red: 15, @@ -48,6 +48,13 @@ ArcBall = function(spawnPosition) { collisionsWillMove: true, userData: JSON.stringify({ grabbableKey: { + spatialKey: { + relativePosition: { + x: 0, + y: 0, + z: -0.5 + }, + }, invertSolidWhileHeld: true } }) diff --git a/examples/flowArts/arcBall/arcBallEntityScript.js b/examples/flowArts/arcBall/arcBallEntityScript.js index 4ad0d66257..7cae0a9cb0 100644 --- a/examples/flowArts/arcBall/arcBallEntityScript.js +++ b/examples/flowArts/arcBall/arcBallEntityScript.js @@ -25,6 +25,7 @@ entities.forEach(function(entity) { var props = Entities.getEntityProperties(entity, ["position", "name"]); if (props.name === "Arc Ball" && JSON.stringify(_this.entityID) !== JSON.stringify(entity)) { + _this.target = entity; _this.createBeam(position, props.position); } }); @@ -32,21 +33,13 @@ }, createBeam: function(startPosition, endPosition) { - print("CREATE BEAM") // Creates particle arc from start position to end position var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; var sourceToTargetVec = Vec3.subtract(endPosition, startPosition); var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec); emitOrientation = Quat.multiply(Quat.inverse(rotation), emitOrientation); - testBox = Entities.addEntity({ - type: "Box", - dimensions: {x: .1, y: .1, z: 1}, - color: {red: 200, green: 10, blue: 10}, - position: startPosition, - rotation: emitOrientation, - visible: false - }); + var color = { red: 200, green: 10, @@ -57,7 +50,7 @@ name: "Particle Arc", parentID: this.entityID, parentJointIndex: -1, - position: startPosition, + // position: startPosition, isEmitting: true, colorStart: color, color: { @@ -67,7 +60,7 @@ }, colorFinish: color, maxParticles: 100000, - lifespan: 6, + lifespan: 5, emitRate: 1000, emitOrientation: emitOrientation, emitSpeed: .4, @@ -103,13 +96,32 @@ this.particleArc = Entities.addEntity(props); }, - continueNearGrab: function() {}, + updateBeam: function(startPosition) { + var targetPosition = Entities.getEntityProperties(this.target, "position").position; + print("TARGET position " + JSON.stringify(this.target)); + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var sourceToTargetVec = Vec3.subtract(targetPosition, startPosition); + var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec); + emitOrientation = Quat.multiply(Quat.inverse(rotation), emitOrientation); + Entities.editEntity(this.particleArc, {emitOrientation: emitOrientation}); + Entities.editEntity(this.testBox, {rotation: emitOrientation}); + }, - releaseGrab: function() {}, + continueNearGrab: function() { + var startPosition = Entities.getEntityProperties(this.entityID, "position").position; + this.updateBeam(startPosition); + }, + + releaseGrab: function() { + Entities.editEntity(this.particleArc, { + isEmitting: false + }); + }, unload: function() { - Entities.deleteEntity(this.particleArc); - Entities.deleteEntity(testBox); + if (this.particleArc) { + Entities.deleteEntity(this.particleArc); + } }, preload: function(entityID) {