This commit is contained in:
ericrius1 2015-12-18 18:15:05 -08:00
parent fffe6dbb9b
commit 1beec0dbe7
3 changed files with 49 additions and 25 deletions

View file

@ -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);
}

View file

@ -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
}
})

View file

@ -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) {