mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
balls
This commit is contained in:
parent
fffe6dbb9b
commit
1beec0dbe7
3 changed files with 49 additions and 25 deletions
|
@ -861,20 +861,25 @@ function MyController(hand) {
|
||||||
var handPosition = this.getHandPosition();
|
var handPosition = this.getHandPosition();
|
||||||
|
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
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 (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) {
|
||||||
// if an object is "equipped" and has a spatialKey, use it.
|
// if an object is "equipped" and has a spatialKey, use it.
|
||||||
this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false;
|
this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false;
|
||||||
this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
|
if (grabbableData.spatialKey.relativePosition) {
|
||||||
this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
|
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 {
|
} else {
|
||||||
this.ignoreIK = false;
|
this.ignoreIK = false;
|
||||||
|
|
||||||
var objectRotation = grabbedProperties.rotation;
|
|
||||||
this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
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);
|
this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ ArcBall = function(spawnPosition) {
|
||||||
|
|
||||||
|
|
||||||
var containerBall = Entities.addEntity({
|
var containerBall = Entities.addEntity({
|
||||||
type: "Box",
|
type: "Sphere",
|
||||||
name: "Arc Ball",
|
name: "Arc Ball",
|
||||||
script: scriptURL,
|
script: scriptURL,
|
||||||
position: Vec3.sum(spawnPosition, {
|
position: Vec3.sum(spawnPosition, {
|
||||||
|
@ -37,7 +37,7 @@ ArcBall = function(spawnPosition) {
|
||||||
dimensions: {
|
dimensions: {
|
||||||
x: .1,
|
x: .1,
|
||||||
y: .1,
|
y: .1,
|
||||||
z: .2
|
z: .1
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
red: 15,
|
red: 15,
|
||||||
|
@ -48,6 +48,13 @@ ArcBall = function(spawnPosition) {
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
grabbableKey: {
|
grabbableKey: {
|
||||||
|
spatialKey: {
|
||||||
|
relativePosition: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: -0.5
|
||||||
|
},
|
||||||
|
},
|
||||||
invertSolidWhileHeld: true
|
invertSolidWhileHeld: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
entities.forEach(function(entity) {
|
entities.forEach(function(entity) {
|
||||||
var props = Entities.getEntityProperties(entity, ["position", "name"]);
|
var props = Entities.getEntityProperties(entity, ["position", "name"]);
|
||||||
if (props.name === "Arc Ball" && JSON.stringify(_this.entityID) !== JSON.stringify(entity)) {
|
if (props.name === "Arc Ball" && JSON.stringify(_this.entityID) !== JSON.stringify(entity)) {
|
||||||
|
_this.target = entity;
|
||||||
_this.createBeam(position, props.position);
|
_this.createBeam(position, props.position);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -32,21 +33,13 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
createBeam: function(startPosition, endPosition) {
|
createBeam: function(startPosition, endPosition) {
|
||||||
print("CREATE BEAM")
|
|
||||||
// Creates particle arc from start position to end position
|
// Creates particle arc from start position to end position
|
||||||
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
|
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
|
||||||
var sourceToTargetVec = Vec3.subtract(endPosition, startPosition);
|
var sourceToTargetVec = Vec3.subtract(endPosition, startPosition);
|
||||||
var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec);
|
var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec);
|
||||||
emitOrientation = Quat.multiply(Quat.inverse(rotation), emitOrientation);
|
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 = {
|
var color = {
|
||||||
red: 200,
|
red: 200,
|
||||||
green: 10,
|
green: 10,
|
||||||
|
@ -57,7 +50,7 @@
|
||||||
name: "Particle Arc",
|
name: "Particle Arc",
|
||||||
parentID: this.entityID,
|
parentID: this.entityID,
|
||||||
parentJointIndex: -1,
|
parentJointIndex: -1,
|
||||||
position: startPosition,
|
// position: startPosition,
|
||||||
isEmitting: true,
|
isEmitting: true,
|
||||||
colorStart: color,
|
colorStart: color,
|
||||||
color: {
|
color: {
|
||||||
|
@ -67,7 +60,7 @@
|
||||||
},
|
},
|
||||||
colorFinish: color,
|
colorFinish: color,
|
||||||
maxParticles: 100000,
|
maxParticles: 100000,
|
||||||
lifespan: 6,
|
lifespan: 5,
|
||||||
emitRate: 1000,
|
emitRate: 1000,
|
||||||
emitOrientation: emitOrientation,
|
emitOrientation: emitOrientation,
|
||||||
emitSpeed: .4,
|
emitSpeed: .4,
|
||||||
|
@ -103,13 +96,32 @@
|
||||||
this.particleArc = Entities.addEntity(props);
|
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() {
|
unload: function() {
|
||||||
Entities.deleteEntity(this.particleArc);
|
if (this.particleArc) {
|
||||||
Entities.deleteEntity(testBox);
|
Entities.deleteEntity(this.particleArc);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
|
|
Loading…
Reference in a new issue