mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 04:03:59 +02:00
YAW ROLL PITCH tool gizmos + functionality
This commit is contained in:
parent
123f898f80
commit
eb0d925091
1 changed files with 154 additions and 260 deletions
|
@ -1031,6 +1031,40 @@ 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: UPDATE ROTATION HANDLES
|
||||
that.updateRotationHandles = function() {
|
||||
var diagonal = (Vec3.length(SelectionManager.worldDimensions) / 2) * 1.1;
|
||||
|
@ -1043,7 +1077,7 @@ 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;
|
||||
|
@ -1088,253 +1122,6 @@ SelectionDisplay = (function() {
|
|||
var cameraPosition = Camera.getPosition();
|
||||
var look = Vec3.normalize(Vec3.subtract(cameraPosition, objectCenter));
|
||||
|
||||
if (cameraPosition.x > objectCenter.x) {
|
||||
// must be BRF or BRN
|
||||
if (cameraPosition.z < objectCenter.z) {
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// place yaw, pitch and roll rotations on the avatar referential
|
||||
yawHandleRotation = Quat.multiply(MyAvatar.orientation , yawHandleRotation);
|
||||
pitchHandleRotation = Quat.multiply(MyAvatar.orientation , pitchHandleRotation);
|
||||
|
@ -1345,7 +1132,7 @@ SelectionDisplay = (function() {
|
|||
z: 0
|
||||
}));
|
||||
var upVector = Quat.getUp(avatarReferential);
|
||||
var rightVector = Quat.getRight(avatarReferential);
|
||||
var rightVector = Vec3.multiply(-1, Quat.getRight(avatarReferential));
|
||||
var frontVector = Quat.getFront(avatarReferential);
|
||||
// Centers
|
||||
var xSign = -1.0;
|
||||
|
@ -1357,20 +1144,127 @@ SelectionDisplay = (function() {
|
|||
zSign = 1.0;
|
||||
}
|
||||
|
||||
yawCenter = Vec3.sum(boundsCenter, Vec3.multiply(-(dimensions.y / 2), upVector));
|
||||
var myBotom = Vec3.multiply(-(dimensions.y / 2) - rotateHandleOffset, upVector);
|
||||
var myRight = Vec3.multiply(xSign * (dimensions.x / 2) + xSign * rotateHandleOffset, rightVector);
|
||||
var myFront = Vec3.multiply(zSign * (dimensions.z / 2) + zSign * rotateHandleOffset, frontVector);
|
||||
yawCorner = Vec3.sum(boundsCenter, Vec3.sum(Vec3.sum(myBotom, myRight), myFront));
|
||||
|
||||
|
||||
|
||||
//project all 8 bounding box points (assumes center 0,0,0) onto the new avatar referential
|
||||
|
||||
var projT_UP = Vec3.dot(Vec3.multiply((dimensions.y / 2) + rotateHandleOffset, Vec3.UNIT_Y), upVector);
|
||||
projT_UP = Vec3.multiply(projT_UP, upVector);
|
||||
|
||||
|
||||
var projB_UP = Vec3.dot(Vec3.multiply(-(dimensions.y / 2) - rotateHandleOffset, Vec3.UNIT_Y), upVector);
|
||||
projB_UP = Vec3.multiply(projB_UP, upVector);
|
||||
|
||||
|
||||
var projL_UP = Vec3.dot(Vec3.multiply(xSign * (dimensions.x / 2) + xSign * rotateHandleOffset, Vec3.UNIT_X), upVector);
|
||||
projL_UP = Vec3.multiply(projL_UP, upVector);
|
||||
|
||||
var projR_UP = Vec3.dot(Vec3.multiply(-xSign * (dimensions.x / 2) - xSign * rotateHandleOffset, Vec3.UNIT_X), upVector);
|
||||
projR_UP = Vec3.multiply(projR_UP, upVector);
|
||||
|
||||
|
||||
var projN_UP = Vec3.dot(Vec3.multiply(zSign * (dimensions.z / 2) + zSign * rotateHandleOffset, Vec3.FRONT), upVector);
|
||||
projN_UP = Vec3.multiply(projN_UP, upVector);
|
||||
|
||||
var projF_UP = Vec3.dot(Vec3.multiply(-zSign * (dimensions.z / 2) - zSign * rotateHandleOffset, Vec3.FRONT), upVector);
|
||||
projF_UP = Vec3.multiply(projF_UP, upVector);
|
||||
|
||||
var projUPList = [projT_UP, projB_UP, projL_UP, projR_UP, projN_UP, projF_UP];
|
||||
|
||||
var projUP = that.calculateNewBoundExtremes(projUPList, upVector);
|
||||
|
||||
//// RIGHT
|
||||
|
||||
var projT_RIGHT = Vec3.dot(Vec3.multiply((dimensions.y / 2) + rotateHandleOffset, Vec3.UNIT_Y), rightVector);
|
||||
projT_RIGHT = Vec3.multiply(projT_RIGHT, rightVector);
|
||||
|
||||
|
||||
var projB_RIGHT = Vec3.dot(Vec3.multiply(-(dimensions.y / 2) - rotateHandleOffset, Vec3.UNIT_Y), rightVector);
|
||||
projB_RIGHT = Vec3.multiply(projB_RIGHT, rightVector);
|
||||
|
||||
|
||||
var projL_RIGHT = Vec3.dot(Vec3.multiply(xSign * (dimensions.x / 2) + xSign * rotateHandleOffset, Vec3.UNIT_X), rightVector);
|
||||
projL_RIGHT = Vec3.multiply(projL_RIGHT, rightVector);
|
||||
|
||||
var projR_RIGHT = Vec3.dot(Vec3.multiply(-xSign * (dimensions.x / 2) - xSign * rotateHandleOffset, Vec3.UNIT_X), rightVector);
|
||||
projR_RIGHT = Vec3.multiply(projR_RIGHT, rightVector);
|
||||
|
||||
|
||||
var projN_RIGHT = Vec3.dot(Vec3.multiply(zSign * (dimensions.z / 2) + zSign * rotateHandleOffset, Vec3.FRONT), rightVector);
|
||||
projN_RIGHT = Vec3.multiply(projN_RIGHT, rightVector);
|
||||
|
||||
var projF_RIGHT = Vec3.dot(Vec3.multiply(-zSign * (dimensions.z / 2) - zSign * rotateHandleOffset, Vec3.FRONT), rightVector);
|
||||
projF_RIGHT = Vec3.multiply(projF_RIGHT, rightVector);
|
||||
|
||||
|
||||
var projRIGHTList = [projT_RIGHT, projB_RIGHT, projL_RIGHT, projR_RIGHT, projN_RIGHT, projF_RIGHT];
|
||||
|
||||
var projRIGHT = that.calculateNewBoundExtremes(projRIGHTList, rightVector);
|
||||
|
||||
//FRONT
|
||||
|
||||
var projT_FRONT = Vec3.dot(Vec3.multiply((dimensions.y / 2) + rotateHandleOffset, Vec3.UNIT_Y), frontVector);
|
||||
projT_FRONT = Vec3.multiply(projT_FRONT, frontVector);
|
||||
|
||||
|
||||
var projB_FRONT = Vec3.dot(Vec3.multiply(-(dimensions.y / 2) - rotateHandleOffset, Vec3.UNIT_Y), frontVector);
|
||||
projB_FRONT = Vec3.multiply(projB_FRONT, frontVector);
|
||||
|
||||
|
||||
var projL_FRONT = Vec3.dot(Vec3.multiply(xSign * (dimensions.x / 2) + xSign * rotateHandleOffset, Vec3.UNIT_X), frontVector);
|
||||
projL_FRONT = Vec3.multiply(projL_FRONT, frontVector);
|
||||
|
||||
var projR_FRONT = Vec3.dot(Vec3.multiply(-xSign * (dimensions.x / 2) - xSign * rotateHandleOffset, Vec3.UNIT_X), frontVector);
|
||||
projR_FRONT = Vec3.multiply(projR_FRONT, frontVector);
|
||||
|
||||
|
||||
var projN_FRONT = Vec3.dot(Vec3.multiply(zSign * (dimensions.z / 2) + zSign * rotateHandleOffset, Vec3.FRONT), frontVector);
|
||||
projN_FRONT = Vec3.multiply(projN_FRONT, frontVector);
|
||||
|
||||
var projF_FRONT = Vec3.dot(Vec3.multiply(-zSign * (dimensions.z / 2) - zSign * rotateHandleOffset, Vec3.FRONT), frontVector);
|
||||
projF_FRONT = Vec3.multiply(projF_FRONT, frontVector);
|
||||
|
||||
var projFRONTList = [projT_FRONT, projB_FRONT, projL_FRONT, projR_FRONT, projN_FRONT, projF_FRONT];
|
||||
|
||||
var projFRONT = that.calculateNewBoundExtremes(projFRONTList, frontVector);
|
||||
|
||||
|
||||
/////
|
||||
|
||||
Overlays.editOverlay(pitchHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
Overlays.editOverlay(rollHandle, {
|
||||
url: ROTATE_ARROW_WEST_NORTH_URL
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
//Quat.fromPitchYawRollDegrees(0,270,0)
|
||||
pitchCenter = Vec3.sum(boundsCenter, Vec3.multiply(xSign * (dimensions.x / 2), rightVector));
|
||||
rollCenter = Vec3.sum(boundsCenter, Vec3.multiply(zSign * (dimensions.z / 2), frontVector));
|
||||
|
||||
|
||||
|
||||
yawCorner = Vec3.sum(boundsCenter, Vec3.sum(Vec3.sum(projUP[0], projRIGHT[1]), projFRONT[1]));
|
||||
|
||||
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);
|
||||
|
||||
|
||||
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;
|
||||
|
@ -3433,7 +3327,7 @@ SelectionDisplay = (function() {
|
|||
|
||||
// FUNCTION: UPDATE ROTATION DEGREES OVERLAY
|
||||
function updateRotationDegreesOverlay(angleFromZero, handleRotation, centerPosition) {
|
||||
var wantDebug = false;
|
||||
var wantDebug = true;
|
||||
if (wantDebug) {
|
||||
print("---> updateRotationDegreesOverlay ---");
|
||||
print(" AngleFromZero: " + angleFromZero);
|
||||
|
|
Loading…
Reference in a new issue