remove 'STICKS' mode, add drop line to better tell what something you are holding is above

This commit is contained in:
Philip Rosedale 2015-01-26 20:19:46 -08:00
parent 6d3a9f7bc0
commit e0c9af853c

View file

@ -28,13 +28,12 @@ var RIGHT = 1;
var jointList = MyAvatar.getJointNames(); var jointList = MyAvatar.getJointNames();
var STICKS = 0; var LASER_WIDTH = 3;
var MAPPED = 1; var LASER_COLOR = { red: 50, green: 150, blue: 200 };
var mode = STICKS; var DROP_COLOR = { red: 200, green: 200, blue: 200 };
var DROP_WIDTH = 4;
var DROP_DISTANCE = 5.0;
var LASER_WIDTH = 4;
var LASER_COLOR = [{ red: 200, green: 150, blue: 50 }, // STICKS
{ red: 50, green: 150, blue: 200 }]; // MAPPED
var LASER_LENGTH_FACTOR = 500; var LASER_LENGTH_FACTOR = 500;
var lastAccurateIntersection = null; var lastAccurateIntersection = null;
@ -115,13 +114,21 @@ function controller(wichSide) {
this.laser = Overlays.addOverlay("line3d", { this.laser = Overlays.addOverlay("line3d", {
start: { x: 0, y: 0, z: 0 }, start: { x: 0, y: 0, z: 0 },
end: { x: 0, y: 0, z: 0 }, end: { x: 0, y: 0, z: 0 },
color: LASER_COLOR[mode], color: LASER_COLOR,
alpha: 1, alpha: 1,
visible: false, visible: false,
lineWidth: LASER_WIDTH, lineWidth: LASER_WIDTH,
anchor: "MyAvatar" anchor: "MyAvatar"
}); });
this.dropLine = Overlays.addOverlay("line3d", {
start: { x: 0, y: 0, z: 0 },
end: { x: 0, y: 0, z: 0 },
color: DROP_COLOR,
alpha: 1,
visible: false,
lineWidth: DROP_WIDTH });
this.guideScale = 0.02; this.guideScale = 0.02;
this.ball = Overlays.addOverlay("sphere", { this.ball = Overlays.addOverlay("sphere", {
position: { x: 0, y: 0, z: 0 }, position: { x: 0, y: 0, z: 0 },
@ -180,6 +187,7 @@ function controller(wichSide) {
} }
} }
this.showLaser(false); this.showLaser(false);
Overlays.editOverlay(this.dropLine, { visible: true });
} }
this.release = function () { this.release = function () {
@ -225,6 +233,8 @@ function controller(wichSide) {
Entities.deleteEntity(this.entityID); Entities.deleteEntity(this.entityID);
} }
} }
Overlays.editOverlay(this.dropLine, { visible: false });
} }
this.grabbing = false; this.grabbing = false;
@ -297,7 +307,6 @@ function controller(wichSide) {
end: endPosition end: endPosition
}); });
Overlays.editOverlay(this.ball, { Overlays.editOverlay(this.ball, {
position: endPosition position: endPosition
}); });
@ -309,7 +318,7 @@ function controller(wichSide) {
start: Vec3.sum(endPosition, Vec3.multiply(this.up, 2 * this.guideScale)), start: Vec3.sum(endPosition, Vec3.multiply(this.up, 2 * this.guideScale)),
end: Vec3.sum(endPosition, Vec3.multiply(this.up, -2 * this.guideScale)) end: Vec3.sum(endPosition, Vec3.multiply(this.up, -2 * this.guideScale))
}); });
this.showLaser(!this.grabbing || mode == STICKS); this.showLaser(!this.grabbing);
if (this.glowedIntersectingModel.isKnownID) { if (this.glowedIntersectingModel.isKnownID) {
Entities.editEntity(this.glowedIntersectingModel, { glowLevel: 0.0 }); Entities.editEntity(this.glowedIntersectingModel, { glowLevel: 0.0 });
@ -353,48 +362,32 @@ function controller(wichSide) {
var newPosition; var newPosition;
var newRotation; var newRotation;
switch (mode) { var forward = Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -1 });
case STICKS: var d = Vec3.dot(forward, MyAvatar.position);
newPosition = Vec3.sum(this.palmPosition,
Vec3.multiply(this.front, this.x));
newPosition = Vec3.sum(newPosition,
Vec3.multiply(this.up, this.y));
newPosition = Vec3.sum(newPosition,
Vec3.multiply(this.right, this.z));
var factor1 = Vec3.dot(forward, this.positionAtGrab) - d;
var factor2 = Vec3.dot(forward, this.modelPositionAtGrab) - d;
var vector = Vec3.subtract(this.palmPosition, this.positionAtGrab);
newRotation = Quat.multiply(this.rotation, if (factor2 < 0) {
Quat.inverse(this.oldRotation)); factor2 = 0;
newRotation = Quat.multiply(newRotation,
this.oldModelRotation);
break;
case MAPPED:
var forward = Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -1 });
var d = Vec3.dot(forward, MyAvatar.position);
var factor1 = Vec3.dot(forward, this.positionAtGrab) - d;
var factor2 = Vec3.dot(forward, this.modelPositionAtGrab) - d;
var vector = Vec3.subtract(this.palmPosition, this.positionAtGrab);
if (factor2 < 0) {
factor2 = 0;
}
if (factor1 <= 0) {
factor1 = 1;
factor2 = 1;
}
newPosition = Vec3.sum(this.modelPositionAtGrab,
Vec3.multiply(vector,
factor2 / factor1));
newRotation = Quat.multiply(this.rotation,
Quat.inverse(this.rotationAtGrab));
newRotation = Quat.multiply(newRotation, newRotation);
newRotation = Quat.multiply(newRotation,
this.modelRotationAtGrab);
break;
} }
if (factor1 <= 0) {
factor1 = 1;
factor2 = 1;
}
newPosition = Vec3.sum(this.modelPositionAtGrab,
Vec3.multiply(vector,
factor2 / factor1));
newRotation = Quat.multiply(this.rotation,
Quat.inverse(this.rotationAtGrab));
newRotation = Quat.multiply(newRotation, newRotation);
newRotation = Quat.multiply(newRotation,
this.modelRotationAtGrab);
Entities.editEntity(this.entityID, { Entities.editEntity(this.entityID, {
position: newPosition, position: newPosition,
rotation: newRotation rotation: newRotation
@ -402,6 +395,8 @@ function controller(wichSide) {
this.oldModelRotation = newRotation; this.oldModelRotation = newRotation;
this.oldModelPosition = newPosition; this.oldModelPosition = newPosition;
Overlays.editOverlay(this.dropLine, { start: newPosition, end: Vec3.sum(newPosition, { x: 0, y: -DROP_DISTANCE, z: 0 }) });
var indicesToRemove = []; var indicesToRemove = [];
for (var i = 0; i < this.jointsIntersectingFromStart.length; ++i) { for (var i = 0; i < this.jointsIntersectingFromStart.length; ++i) {
var distance = Vec3.distance(MyAvatar.getJointPosition(this.jointsIntersectingFromStart[i]), this.oldModelPosition); var distance = Vec3.distance(MyAvatar.getJointPosition(this.jointsIntersectingFromStart[i]), this.oldModelPosition);
@ -437,15 +432,6 @@ function controller(wichSide) {
this.triggerValue = Controller.getTriggerValue(this.trigger); this.triggerValue = Controller.getTriggerValue(this.trigger);
var bumperValue = Controller.isButtonPressed(this.bumper); var bumperValue = Controller.isButtonPressed(this.bumper);
if (bumperValue && !this.bumperValue) {
if (mode === STICKS) {
mode = MAPPED;
} else if (mode === MAPPED) {
mode = STICKS;
}
Overlays.editOverlay(leftController.laser, { color: LASER_COLOR[mode] });
Overlays.editOverlay(rightController.laser, { color: LASER_COLOR[mode] });
}
this.bumperValue = bumperValue; this.bumperValue = bumperValue;
@ -563,55 +549,31 @@ function moveEntities() {
var rotation = leftController.oldModelRotation; var rotation = leftController.oldModelRotation;
var ratio = 1; var ratio = 1;
var u = Vec3.normalize(Vec3.subtract(rightController.oldPalmPosition, leftController.oldPalmPosition));
var v = Vec3.normalize(Vec3.subtract(rightController.palmPosition, leftController.palmPosition));
switch (mode) { var cos_theta = Vec3.dot(u, v);
case STICKS: if (cos_theta > 1) {
var oldLeftPoint = Vec3.sum(leftController.oldPalmPosition, Vec3.multiply(leftController.oldFront, leftController.x)); cos_theta = 1;
var oldRightPoint = Vec3.sum(rightController.oldPalmPosition, Vec3.multiply(rightController.oldFront, rightController.x));
var oldMiddle = Vec3.multiply(Vec3.sum(oldLeftPoint, oldRightPoint), 0.5);
var oldLength = Vec3.length(Vec3.subtract(oldLeftPoint, oldRightPoint));
var leftPoint = Vec3.sum(leftController.palmPosition, Vec3.multiply(leftController.front, leftController.x));
var rightPoint = Vec3.sum(rightController.palmPosition, Vec3.multiply(rightController.front, rightController.x));
var middle = Vec3.multiply(Vec3.sum(leftPoint, rightPoint), 0.5);
var length = Vec3.length(Vec3.subtract(leftPoint, rightPoint));
ratio = length / oldLength;
newPosition = Vec3.sum(middle,
Vec3.multiply(Vec3.subtract(leftController.oldModelPosition, oldMiddle), ratio));
break;
case MAPPED:
var u = Vec3.normalize(Vec3.subtract(rightController.oldPalmPosition, leftController.oldPalmPosition));
var v = Vec3.normalize(Vec3.subtract(rightController.palmPosition, leftController.palmPosition));
var cos_theta = Vec3.dot(u, v);
if (cos_theta > 1) {
cos_theta = 1;
}
var angle = Math.acos(cos_theta) / Math.PI * 180;
if (angle < 0.1) {
return;
}
var w = Vec3.normalize(Vec3.cross(u, v));
rotation = Quat.multiply(Quat.angleAxis(angle, w), leftController.oldModelRotation);
leftController.positionAtGrab = leftController.palmPosition;
leftController.rotationAtGrab = leftController.rotation;
leftController.modelPositionAtGrab = leftController.oldModelPosition;
leftController.modelRotationAtGrab = rotation;
rightController.positionAtGrab = rightController.palmPosition;
rightController.rotationAtGrab = rightController.rotation;
rightController.modelPositionAtGrab = rightController.oldModelPosition;
rightController.modelRotationAtGrab = rotation;
break;
} }
var angle = Math.acos(cos_theta) / Math.PI * 180;
if (angle < 0.1) {
return;
}
var w = Vec3.normalize(Vec3.cross(u, v));
rotation = Quat.multiply(Quat.angleAxis(angle, w), leftController.oldModelRotation);
leftController.positionAtGrab = leftController.palmPosition;
leftController.rotationAtGrab = leftController.rotation;
leftController.modelPositionAtGrab = leftController.oldModelPosition;
leftController.modelRotationAtGrab = rotation;
rightController.positionAtGrab = rightController.palmPosition;
rightController.rotationAtGrab = rightController.rotation;
rightController.modelPositionAtGrab = rightController.oldModelPosition;
rightController.modelRotationAtGrab = rotation;
Entities.editEntity(leftController.entityID, { Entities.editEntity(leftController.entityID, {
position: newPosition, position: newPosition,
rotation: rotation, rotation: rotation,
@ -621,7 +583,6 @@ function moveEntities() {
y: leftController.oldModelHalfDiagonal * ratio, y: leftController.oldModelHalfDiagonal * ratio,
z: leftController.oldModelHalfDiagonal * ratio } z: leftController.oldModelHalfDiagonal * ratio }
}); });
leftController.oldModelPosition = newPosition; leftController.oldModelPosition = newPosition;
leftController.oldModelRotation = rotation; leftController.oldModelRotation = rotation;