Fix stretch tools not following mouse correctly

This commit is contained in:
Ryan Huffman 2014-12-01 15:07:03 -08:00
parent da568c96ce
commit 4f0683dc5e

View file

@ -1337,7 +1337,11 @@ SelectionDisplay = (function () {
var vec3Mult = function(v1, v2) {
return { x: v1.x * v2.x, y: v1.y * v2.y, z: v1.z * v2.z };
}
var makeStretchTool = function(stretchMode, direction, pivot) {
// stretchMode - name of mode
// direction - direction to stretch in
// pivot - point to use as a pivot
// offset - the position of the overlay tool relative to the selections center position
var makeStretchTool = function(stretchMode, direction, pivot, offset) {
var signs = {
x: direction.x < 0 ? -1 : (direction.x > 0 ? 1 : 0),
y: direction.y < 0 ? -1 : (direction.y > 0 ? 1 : 0),
@ -1358,6 +1362,7 @@ SelectionDisplay = (function () {
var initialDimensions = null;
var initialIntersection = null;
var initialProperties = null;
var pickRayPosition = null;
var rotation = null;
var onBegin = function(event) {
@ -1366,13 +1371,22 @@ SelectionDisplay = (function () {
rotation = spaceMode == SPACE_LOCAL ? properties.rotation : Quat.fromPitchYawRollDegrees(0, 0, 0);
if (spaceMode == SPACE_LOCAL) {
rotation = SelectionManager.localRotation;
initialPosition = SelectionManager.localPosition;
initialDimensions = SelectionManager.localDimensions;
} else {
rotation = SelectionManager.worldRotation;
initialPosition = SelectionManager.worldPosition;
initialDimensions = SelectionManager.worldDimensions;
}
var scaledOffset = {
x: initialDimensions.x * offset.x * 0.5,
y: initialDimensions.y * offset.y * 0.5,
z: initialDimensions.z * offset.z * 0.5,
};
pickRayPosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffset));
if (numDimensions == 1 && mask.x) {
var start = Vec3.multiplyQbyV(rotation, { x: -10000, y: 0, z: 0 });
start = Vec3.sum(start, properties.position);
@ -1426,7 +1440,7 @@ SelectionDisplay = (function () {
planeNormal = Vec3.multiplyQbyV(rotation, planeNormal);
var pickRay = Camera.computePickRay(event.x, event.y);
lastPick = rayPlaneIntersection(pickRay,
initialPosition,
pickRayPosition,
planeNormal);
// Overlays.editOverlay(normalLine, {
@ -1461,7 +1475,7 @@ SelectionDisplay = (function () {
var pickRay = Camera.computePickRay(event.x, event.y);
newPick = rayPlaneIntersection(pickRay,
initialPosition,
pickRayPosition,
planeNormal);
var vector = Vec3.subtract(newPick, lastPick);
@ -1536,44 +1550,44 @@ SelectionDisplay = (function () {
};
};
function addStretchTool(overlay, mode, pivot, direction) {
function addStretchTool(overlay, mode, pivot, direction, offset) {
if (!pivot) {
pivot = Vec3.multiply(-1, direction);
pivot.y = direction.y;
}
var tool = makeStretchTool(mode, direction, pivot);
var tool = makeStretchTool(mode, direction, pivot, offset);
addGrabberTool(overlay, tool);
}
addStretchTool(grabberNEAR, "STRETCH_NEAR", { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 });
addStretchTool(grabberFAR, "STRETCH_FAR", { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 });
addStretchTool(grabberTOP, "STRETCH_TOP", { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 });
addStretchTool(grabberBOTTOM, "STRETCH_BOTTOM", { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 });
addStretchTool(grabberRIGHT, "STRETCH_RIGHT", { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 });
addStretchTool(grabberLEFT, "STRETCH_LEFT", { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 });
addStretchTool(grabberNEAR, "STRETCH_NEAR", { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 });
addStretchTool(grabberFAR, "STRETCH_FAR", { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 });
addStretchTool(grabberTOP, "STRETCH_TOP", { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 });
addStretchTool(grabberBOTTOM, "STRETCH_BOTTOM", { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 });
addStretchTool(grabberRIGHT, "STRETCH_RIGHT", { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 });
addStretchTool(grabberLEFT, "STRETCH_LEFT", { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 });
addStretchTool(grabberLBN, "STRETCH_LBN", null, {x: 1, y: 0, z: 1});
addStretchTool(grabberRBN, "STRETCH_RBN", null, {x: -1, y: 0, z: 1});
addStretchTool(grabberLBF, "STRETCH_LBF", null, {x: 1, y: 0, z: -1});
addStretchTool(grabberRBF, "STRETCH_RBF", null, {x: -1, y: 0, z: -1});
addStretchTool(grabberLTN, "STRETCH_LTN", null, {x: 1, y: 0, z: 1});
addStretchTool(grabberRTN, "STRETCH_RTN", null, {x: -1, y: 0, z: 1});
addStretchTool(grabberLTF, "STRETCH_LTF", null, {x: 1, y: 0, z: -1});
addStretchTool(grabberRTF, "STRETCH_RTF", null, {x: -1, y: 0, z: -1});
addStretchTool(grabberLBN, "STRETCH_LBN", null, {x: 1, y: 0, z: 1}, { x: -1, y: -1, z: -1 });
addStretchTool(grabberRBN, "STRETCH_RBN", null, {x: -1, y: 0, z: 1}, { x: 1, y: -1, z: -1 });
addStretchTool(grabberLBF, "STRETCH_LBF", null, {x: 1, y: 0, z: -1}, { x: -1, y: -1, z: 1 });
addStretchTool(grabberRBF, "STRETCH_RBF", null, {x: -1, y: 0, z: -1}, { x: 1, y: -1, z: 1 });
addStretchTool(grabberLTN, "STRETCH_LTN", null, {x: 1, y: 0, z: 1}, { x: -1, y: 1, z: -1 });
addStretchTool(grabberRTN, "STRETCH_RTN", null, {x: -1, y: 0, z: 1}, { x: 1, y: 1, z: -1 });
addStretchTool(grabberLTF, "STRETCH_LTF", null, {x: 1, y: 0, z: -1}, { x: -1, y: 1, z: 1 });
addStretchTool(grabberRTF, "STRETCH_RTF", null, {x: -1, y: 0, z: -1}, { x: 1, y: 1, z: 1 });
addStretchTool(grabberEdgeTR, "STRETCH_EdgeTR", null, {x: 1, y: 1, z: 0});
addStretchTool(grabberEdgeTL, "STRETCH_EdgeTL", null, {x: -1, y: 1, z: 0});
addStretchTool(grabberEdgeTF, "STRETCH_EdgeTF", null, {x: 0, y: 1, z: -1});
addStretchTool(grabberEdgeTN, "STRETCH_EdgeTN", null, {x: 0, y: 1, z: 1});
addStretchTool(grabberEdgeBR, "STRETCH_EdgeBR", null, {x: -1, y: 0, z: 0});
addStretchTool(grabberEdgeBL, "STRETCH_EdgeBL", null, {x: 1, y: 0, z: 0});
addStretchTool(grabberEdgeBF, "STRETCH_EdgeBF", null, {x: 0, y: 0, z: -1});
addStretchTool(grabberEdgeBN, "STRETCH_EdgeBN", null, {x: 0, y: 0, z: 1});
addStretchTool(grabberEdgeNR, "STRETCH_EdgeNR", null, {x: -1, y: 0, z: 1});
addStretchTool(grabberEdgeNL, "STRETCH_EdgeNL", null, {x: 1, y: 0, z: 1});
addStretchTool(grabberEdgeFR, "STRETCH_EdgeFR", null, {x: -1, y: 0, z: -1});
addStretchTool(grabberEdgeFL, "STRETCH_EdgeFL", null, {x: 1, y: 0, z: -1});
addStretchTool(grabberEdgeTR, "STRETCH_EdgeTR", null, {x: 1, y: 1, z: 0}, { x: 1, y: 1, z: 0 });
addStretchTool(grabberEdgeTL, "STRETCH_EdgeTL", null, {x: -1, y: 1, z: 0}, { x: -1, y: 1, z: 0 });
addStretchTool(grabberEdgeTF, "STRETCH_EdgeTF", null, {x: 0, y: 1, z: -1}, { x: 0, y: 1, z: -1 });
addStretchTool(grabberEdgeTN, "STRETCH_EdgeTN", null, {x: 0, y: 1, z: 1}, { x: 0, y: 1, z: 1 });
addStretchTool(grabberEdgeBR, "STRETCH_EdgeBR", null, {x: -1, y: 0, z: 0}, { x: 1, y: -1, z: 0 });
addStretchTool(grabberEdgeBL, "STRETCH_EdgeBL", null, {x: 1, y: 0, z: 0}, { x: -1, y: -1, z: 0 });
addStretchTool(grabberEdgeBF, "STRETCH_EdgeBF", null, {x: 0, y: 0, z: -1}, { x: 0, y: -1, z: -1 });
addStretchTool(grabberEdgeBN, "STRETCH_EdgeBN", null, {x: 0, y: 0, z: 1}, { x: 0, y: -1, z: 1 });
addStretchTool(grabberEdgeNR, "STRETCH_EdgeNR", null, {x: -1, y: 0, z: 1}, { x: 1, y: 0, z: -1 });
addStretchTool(grabberEdgeNL, "STRETCH_EdgeNL", null, {x: 1, y: 0, z: 1}, { x: -1, y: 0, z: -1 });
addStretchTool(grabberEdgeFR, "STRETCH_EdgeFR", null, {x: -1, y: 0, z: -1}, { x: 1, y: 0, z: 1 });
addStretchTool(grabberEdgeFL, "STRETCH_EdgeFL", null, {x: 1, y: 0, z: -1}, { x: -1, y: 0, z: 1 });
var initialPosition = SelectionManager.worldPosition;
addGrabberTool(yawHandle, {