arc balls working

This commit is contained in:
ericrius1 2015-12-21 10:43:59 -08:00
parent fffe6dbb9b
commit 7a7befafb9
3 changed files with 81 additions and 47 deletions

View file

@ -218,6 +218,7 @@ function getSpatialOffsetPosition(hand, spatialKey) {
}
var yFlip = Quat.angleAxis(180, Vec3.UNIT_Y);
function getSpatialOffsetRotation(hand, spatialKey) {
var rotation = Quat.IDENTITY;
@ -261,9 +262,9 @@ function MyController(hand) {
this.triggerValue = 0; // rolling average of trigger value
this.rawTriggerValue = 0;
this.rawBumperValue = 0;
this.overlayLine = null;
this.ignoreIK = false;
this.offsetPosition = Vec3.ZERO;
this.offsetRotation = Quat.IDENTITY;
@ -819,8 +820,16 @@ function MyController(hand) {
// mix in head motion
if (MOVE_WITH_HEAD) {
var objDistance = Vec3.length(objectToAvatar);
var before = Vec3.multiplyQbyV(this.currentCameraOrientation, { x: 0.0, y: 0.0, z: objDistance });
var after = Vec3.multiplyQbyV(Camera.orientation, { x: 0.0, y: 0.0, z: objDistance });
var before = Vec3.multiplyQbyV(this.currentCameraOrientation, {
x: 0.0,
y: 0.0,
z: objDistance
});
var after = Vec3.multiplyQbyV(Camera.orientation, {
x: 0.0,
y: 0.0,
z: objDistance
});
var change = Vec3.subtract(before, after);
this.currentCameraOrientation = Camera.orientation;
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change);
@ -861,20 +870,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);
}
@ -1304,10 +1318,10 @@ Controller.enableMapping(MAPPING_NAME);
var handToDisable = 'none';
function update() {
if (handToDisable !== LEFT_HAND && handToDisable!=='both') {
if (handToDisable !== LEFT_HAND && handToDisable !== 'both') {
leftController.update();
}
if (handToDisable !== RIGHT_HAND && handToDisable!=='both') {
if (handToDisable !== RIGHT_HAND && handToDisable !== 'both') {
rightController.update();
}
}
@ -1315,7 +1329,7 @@ function update() {
Messages.subscribe('Hifi-Hand-Disabler');
handleHandDisablerMessages = function(channel, message, sender) {
if (sender === MyAvatar.sessionUUID) {
if (message === 'left') {
handToDisable = LEFT_HAND;
@ -1323,11 +1337,11 @@ handleHandDisablerMessages = function(channel, message, sender) {
if (message === 'right') {
handToDisable = RIGHT_HAND;
}
if(message==='both'){
handToDisable='both';
if (message === 'both') {
handToDisable = 'both';
}
if(message==='none'){
handToDisable='none';
if (message === 'none') {
handToDisable = 'none';
}
}
@ -1342,4 +1356,4 @@ function cleanup() {
}
Script.scriptEnding.connect(cleanup);
Script.update.connect(update);
Script.update.connect(update);

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, {
@ -35,12 +35,12 @@ ArcBall = function(spawnPosition) {
z: 0
}),
dimensions: {
x: .1,
y: .1,
z: .2
x: .05,
y: .05,
z: .05
},
color: {
red: 15,
red: 100,
green: 10,
blue: 150
},
@ -48,6 +48,13 @@ ArcBall = function(spawnPosition) {
collisionsWillMove: true,
userData: JSON.stringify({
grabbableKey: {
spatialKey: {
relativePosition: {
x: 0,
y: 0,
z: -0.5
},
},
invertSolidWhileHeld: true
}
})
@ -127,11 +134,11 @@ ArcBall = function(spawnPosition) {
function cleanup() {
Entities.deleteEntity(arcBall);
Entities.deleteEntity(containerBall);
Entities.deleteEntity(light);
}
function cleanup() {
Entities.deleteEntity(arcBall);
Entities.deleteEntity(containerBall);
Entities.deleteEntity(light);
}
this.cleanup = cleanup;
}

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
// 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,
@ -98,18 +91,38 @@
alphaStart: 0.5,
alphaFinish: 0.5,
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png",
emitterShouldTrail: false
emitterShouldTrail: true
}
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(emitOrientation,Quat.inverse(rotation));
Entities.editEntity(this.particleArc, {
emitOrientation: 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) {