mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 16:23:39 +02:00
Merge pull request #11897 from Delanir/Gizmos
IPD Secondary Task List: edit.js arrow orientation: Yaw, Pitch, Roll tools
This commit is contained in:
commit
86a1bc75c9
1 changed files with 132 additions and 272 deletions
|
@ -1031,6 +1031,71 @@ SelectionDisplay = (function() {
|
|||
that.updateHandles();
|
||||
};
|
||||
|
||||
// Function: Calculate New Bound Extremes
|
||||
// uses dot product to discover new top and bottom on the new referential (max and min)
|
||||
that.calculateNewBoundExtremes = function(boundPointList, referenceVector) {
|
||||
|
||||
if (boundPointList.length < 2) {
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
var refMax = boundPointList[0];
|
||||
var refMin = boundPointList[1];
|
||||
|
||||
var dotMax = Vec3.dot(boundPointList[0], referenceVector);
|
||||
var dotMin = Vec3.dot(boundPointList[1], referenceVector);
|
||||
|
||||
if (dotMin > dotMax) {
|
||||
dotMax = dotMin;
|
||||
dotMin = Vec3.dot(boundPointList[0], referenceVector);
|
||||
refMax = boundPointList[1];
|
||||
refMin = boundPointList[0];
|
||||
}
|
||||
|
||||
for (var i = 2; i < boundPointList.length ; i++) {
|
||||
var dotAux = Vec3.dot(boundPointList[i], referenceVector);
|
||||
if (dotAux > dotMax) {
|
||||
dotMax = dotAux;
|
||||
refMax = boundPointList[i];
|
||||
} else if (dotAux < dotMin) {
|
||||
dotMin = dotAux;
|
||||
refMin = boundPointList[i];
|
||||
}
|
||||
}
|
||||
return [refMin, refMax];
|
||||
}
|
||||
|
||||
// Function: Project Bounding Box Points
|
||||
// Projects all 6 bounding box points: Top, Bottom, Left, Right, Near, Far (assumes center 0,0,0) onto
|
||||
// one of the basis of the new avatar referencial
|
||||
// dimensions - dimensions of the AABB (axis aligned bounding box) on the standard basis
|
||||
// [1, 0, 0], [0, 1, 0], [0, 0, 1]
|
||||
// v - projection vector
|
||||
// rotateHandleOffset - offset for the rotation handle gizmo position
|
||||
that.projectBoundingBoxPoints = function(dimensions, v, rotateHandleOffset) {
|
||||
var projT_v = Vec3.dot(Vec3.multiply((dimensions.y / 2) + rotateHandleOffset, Vec3.UNIT_Y), v);
|
||||
projT_v = Vec3.multiply(projT_v, v);
|
||||
|
||||
var projB_v = Vec3.dot(Vec3.multiply(-(dimensions.y / 2) - rotateHandleOffset, Vec3.UNIT_Y), v);
|
||||
projB_v = Vec3.multiply(projB_v, v);
|
||||
|
||||
var projL_v = Vec3.dot(Vec3.multiply((dimensions.x / 2) + rotateHandleOffset, Vec3.UNIT_X), v);
|
||||
projL_v = Vec3.multiply(projL_v, v);
|
||||
|
||||
var projR_v = Vec3.dot(Vec3.multiply(-1.0 * (dimensions.x / 2) - 1.0 * rotateHandleOffset, Vec3.UNIT_X), v);
|
||||
projR_v = Vec3.multiply(projR_v, v);
|
||||
|
||||
var projN_v = Vec3.dot(Vec3.multiply((dimensions.z / 2) + rotateHandleOffset, Vec3.FRONT), v);
|
||||
projN_v = Vec3.multiply(projN_v, v);
|
||||
|
||||
var projF_v = Vec3.dot(Vec3.multiply(-1.0 * (dimensions.z / 2) - 1.0 * rotateHandleOffset, Vec3.FRONT), v);
|
||||
projF_v = Vec3.multiply(projF_v, v);
|
||||
|
||||
var projList = [projT_v, projB_v, projL_v, projR_v, projN_v, projF_v];
|
||||
|
||||
return that.calculateNewBoundExtremes(projList, v);
|
||||
};
|
||||
|
||||
// FUNCTION: UPDATE ROTATION HANDLES
|
||||
that.updateRotationHandles = function() {
|
||||
var diagonal = (Vec3.length(SelectionManager.worldDimensions) / 2) * 1.1;
|
||||
|
@ -1043,10 +1108,10 @@ SelectionDisplay = (function() {
|
|||
} else {
|
||||
outerAlpha = 0.5;
|
||||
}
|
||||
|
||||
// prev 0.05
|
||||
var rotateHandleOffset = 0.05;
|
||||
|
||||
var top, far, left, bottom, near, right, boundsCenter, objectCenter, BLN, BRN, BLF, TLN, TRN, TLF, TRF;
|
||||
var boundsCenter, objectCenter;
|
||||
|
||||
var dimensions, rotation;
|
||||
if (spaceMode === SPACE_LOCAL) {
|
||||
|
@ -1058,280 +1123,66 @@ SelectionDisplay = (function() {
|
|||
dimensions = SelectionManager.worldDimensions;
|
||||
var position = objectCenter;
|
||||
|
||||
top = objectCenter.y + (dimensions.y / 2);
|
||||
far = objectCenter.z + (dimensions.z / 2);
|
||||
left = objectCenter.x + (dimensions.x / 2);
|
||||
|
||||
bottom = objectCenter.y - (dimensions.y / 2);
|
||||
near = objectCenter.z - (dimensions.z / 2);
|
||||
right = objectCenter.x - (dimensions.x / 2);
|
||||
|
||||
boundsCenter = objectCenter;
|
||||
|
||||
var yawCorner;
|
||||
var pitchCorner;
|
||||
var rollCorner;
|
||||
|
||||
// determine which bottom corner we are closest to
|
||||
/*------------------------------
|
||||
example:
|
||||
|
||||
BRF +--------+ BLF
|
||||
| |
|
||||
| |
|
||||
BRN +--------+ BLN
|
||||
|
||||
*
|
||||
|
||||
------------------------------*/
|
||||
|
||||
var cameraPosition = Camera.getPosition();
|
||||
if (cameraPosition.x > objectCenter.x) {
|
||||
// must be BRF or BRN
|
||||
if (cameraPosition.z < objectCenter.z) {
|
||||
var look = Vec3.normalize(Vec3.subtract(cameraPosition, objectCenter));
|
||||
|
||||
yawHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 270,
|
||||
y: 90,
|
||||
z: 0
|
||||
});
|
||||
pitchHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 90,
|
||||
z: 0
|
||||
});
|
||||
rollHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
// place yaw, pitch and roll rotations on the avatar referential
|
||||
|
||||
var avatarReferential = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 180,
|
||||
z: 0
|
||||
}));
|
||||
var upVector = Quat.getUp(avatarReferential);
|
||||
var rightVector = Vec3.multiply(-1, Quat.getRight(avatarReferential));
|
||||
var frontVector = Quat.getFront(avatarReferential);
|
||||
|
||||
// project all 6 bounding box points: Top, Bottom, Left, Right, Near, Far (assumes center 0,0,0)
|
||||
// onto the new avatar referential
|
||||
|
||||
yawCorner = {
|
||||
x: left + rotateHandleOffset,
|
||||
y: bottom - rotateHandleOffset,
|
||||
z: near - rotateHandleOffset
|
||||
};
|
||||
|
||||
pitchCorner = {
|
||||
x: right - rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: near - rotateHandleOffset
|
||||
};
|
||||
|
||||
rollCorner = {
|
||||
x: left + rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: far + rotateHandleOffset
|
||||
};
|
||||
|
||||
yawCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: bottom,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
pitchCenter = {
|
||||
x: right,
|
||||
y: boundsCenter.y,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
rollCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: boundsCenter.y,
|
||||
z: far
|
||||
};
|
||||
|
||||
|
||||
Overlays.editOverlay(pitchHandle, {
|
||||
url: ROTATE_ARROW_WEST_SOUTH_URL
|
||||
});
|
||||
Overlays.editOverlay(rollHandle, {
|
||||
url: ROTATE_ARROW_WEST_SOUTH_URL
|
||||
});
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
yawHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 270,
|
||||
y: 0,
|
||||
z: 0
|
||||
});
|
||||
pitchHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 180,
|
||||
y: 270,
|
||||
z: 0
|
||||
});
|
||||
rollHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 90
|
||||
});
|
||||
|
||||
yawCorner = {
|
||||
x: left + rotateHandleOffset,
|
||||
y: bottom - rotateHandleOffset,
|
||||
z: far + rotateHandleOffset
|
||||
};
|
||||
|
||||
pitchCorner = {
|
||||
x: right - rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: far + rotateHandleOffset
|
||||
};
|
||||
|
||||
rollCorner = {
|
||||
x: left + rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: near - rotateHandleOffset
|
||||
};
|
||||
|
||||
|
||||
yawCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: bottom,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
pitchCenter = {
|
||||
x: right,
|
||||
y: boundsCenter.y,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
rollCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: boundsCenter.y,
|
||||
z: near
|
||||
};
|
||||
|
||||
Overlays.editOverlay(pitchHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
Overlays.editOverlay(rollHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
// must be BLF or BLN
|
||||
if (cameraPosition.z < objectCenter.z) {
|
||||
|
||||
yawHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 270,
|
||||
y: 180,
|
||||
z: 0
|
||||
});
|
||||
pitchHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 90,
|
||||
y: 0,
|
||||
z: 90
|
||||
});
|
||||
rollHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 180
|
||||
});
|
||||
|
||||
yawCorner = {
|
||||
x: right - rotateHandleOffset,
|
||||
y: bottom - rotateHandleOffset,
|
||||
z: near - rotateHandleOffset
|
||||
};
|
||||
|
||||
pitchCorner = {
|
||||
x: left + rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: near - rotateHandleOffset
|
||||
};
|
||||
|
||||
rollCorner = {
|
||||
x: right - rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: far + rotateHandleOffset
|
||||
};
|
||||
|
||||
yawCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: bottom,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
pitchCenter = {
|
||||
x: left,
|
||||
y: boundsCenter.y,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
rollCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: boundsCenter.y,
|
||||
z: far
|
||||
};
|
||||
|
||||
Overlays.editOverlay(pitchHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
Overlays.editOverlay(rollHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
yawHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 270,
|
||||
y: 270,
|
||||
z: 0
|
||||
});
|
||||
pitchHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 180,
|
||||
y: 270,
|
||||
z: 0
|
||||
});
|
||||
rollHandleRotation = Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 180
|
||||
});
|
||||
|
||||
yawCorner = {
|
||||
x: right - rotateHandleOffset,
|
||||
y: bottom - rotateHandleOffset,
|
||||
z: far + rotateHandleOffset
|
||||
};
|
||||
|
||||
rollCorner = {
|
||||
x: right - rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: near - rotateHandleOffset
|
||||
};
|
||||
|
||||
pitchCorner = {
|
||||
x: left + rotateHandleOffset,
|
||||
y: top + rotateHandleOffset,
|
||||
z: far + rotateHandleOffset
|
||||
};
|
||||
|
||||
yawCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: bottom,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
rollCenter = {
|
||||
x: boundsCenter.x,
|
||||
y: boundsCenter.y,
|
||||
z: near
|
||||
};
|
||||
pitchCenter = {
|
||||
x: left,
|
||||
y: boundsCenter.y,
|
||||
z: boundsCenter.z
|
||||
};
|
||||
|
||||
Overlays.editOverlay(pitchHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
Overlays.editOverlay(rollHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
// UP
|
||||
var projUP = that.projectBoundingBoxPoints(dimensions, upVector, rotateHandleOffset);
|
||||
// RIGHT
|
||||
var projRIGHT = that.projectBoundingBoxPoints(dimensions, rightVector, rotateHandleOffset);
|
||||
// FRONT
|
||||
var projFRONT = that.projectBoundingBoxPoints(dimensions, frontVector, rotateHandleOffset);
|
||||
|
||||
// YAW
|
||||
yawCenter = Vec3.sum(boundsCenter, projUP[0]);
|
||||
yawCorner = Vec3.sum(boundsCenter, Vec3.sum(Vec3.sum(projUP[0], projRIGHT[1]), projFRONT[1]));
|
||||
|
||||
yawHandleRotation = Quat.lookAt(
|
||||
yawCorner,
|
||||
Vec3.sum(yawCorner, upVector),
|
||||
Vec3.subtract(yawCenter,yawCorner));
|
||||
yawHandleRotation = Quat.multiply(Quat.angleAxis(45, upVector), yawHandleRotation);
|
||||
|
||||
// PTCH
|
||||
pitchCorner = Vec3.sum(boundsCenter, Vec3.sum(Vec3.sum(projUP[1], projRIGHT[0]), projFRONT[1]));
|
||||
pitchCenter = Vec3.sum(boundsCenter, projRIGHT[0]);
|
||||
|
||||
pitchHandleRotation = Quat.lookAt(
|
||||
pitchCorner,
|
||||
Vec3.sum(pitchCorner, rightVector),
|
||||
Vec3.subtract(pitchCenter,pitchCorner));
|
||||
pitchHandleRotation = Quat.multiply(Quat.angleAxis(45, rightVector), pitchHandleRotation);
|
||||
|
||||
// ROLL
|
||||
rollCorner = Vec3.sum(boundsCenter, Vec3.sum(Vec3.sum(projUP[1], projRIGHT[1]), projFRONT[0]));
|
||||
rollCenter = Vec3.sum(boundsCenter, projFRONT[0]);
|
||||
|
||||
rollHandleRotation = Quat.lookAt(
|
||||
rollCorner,
|
||||
Vec3.sum(rollCorner, frontVector),
|
||||
Vec3.subtract(rollCenter,rollCorner));
|
||||
rollHandleRotation = Quat.multiply(Quat.angleAxis(45, frontVector), rollHandleRotation);
|
||||
|
||||
|
||||
var rotateHandlesVisible = true;
|
||||
var rotationOverlaysVisible = false;
|
||||
|
@ -1382,6 +1233,8 @@ SelectionDisplay = (function() {
|
|||
position: rollCorner,
|
||||
rotation: rollHandleRotation
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
// FUNCTION: UPDATE HANDLE SIZES
|
||||
|
@ -3422,7 +3275,7 @@ SelectionDisplay = (function() {
|
|||
y: innerRadius * ROTATION_DISPLAY_SIZE_Y_MULTIPLIER
|
||||
},
|
||||
lineHeight: innerRadius * ROTATION_DISPLAY_LINE_HEIGHT_MULTIPLIER,
|
||||
text: normalizeDegrees(angleFromZero) + "°"
|
||||
text: normalizeDegrees(-angleFromZero) + "°"
|
||||
};
|
||||
if (wantDebug) {
|
||||
print(" TranslatedPos: " + position.x + ", " + position.y + ", " + position.z);
|
||||
|
@ -3483,6 +3336,13 @@ SelectionDisplay = (function() {
|
|||
initialPosition = SelectionManager.worldPosition;
|
||||
rotationNormal = { x: 0, y: 0, z: 0 };
|
||||
rotationNormal[rotAroundAxis] = 1;
|
||||
//get the correct axis according to the avatar referencial
|
||||
var avatarReferential = Quat.multiply(MyAvatar.orientation, Quat.fromVec3Degrees({
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}));
|
||||
rotationNormal = Vec3.multiplyQbyV(avatarReferential, rotationNormal);
|
||||
|
||||
// Size the overlays to the current selection size
|
||||
var diagonal = (Vec3.length(SelectionManager.worldDimensions) / 2) * 1.1;
|
||||
|
@ -3584,11 +3444,11 @@ SelectionDisplay = (function() {
|
|||
var snapAngle = snapToInner ? innerSnapAngle : 1.0;
|
||||
angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle;
|
||||
|
||||
var vec3Degrees = { x: 0, y: 0, z: 0 };
|
||||
vec3Degrees[rotAroundAxis] = angleFromZero;
|
||||
var rotChange = Quat.fromVec3Degrees(vec3Degrees);
|
||||
|
||||
var rotChange = Quat.angleAxis(angleFromZero, rotationNormal);
|
||||
updateSelectionsRotation(rotChange);
|
||||
|
||||
//present angle in avatar referencial
|
||||
angleFromZero = -angleFromZero;
|
||||
updateRotationDegreesOverlay(angleFromZero, handleRotation, rotCenter);
|
||||
|
||||
// update the rotation display accordingly...
|
||||
|
|
Loading…
Reference in a new issue