mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
fix bug related to camera lock for entity orbit and pan
This commit is contained in:
parent
f8956a853b
commit
84f0c404ad
2 changed files with 622 additions and 179 deletions
593
examples/edit.js
593
examples/edit.js
File diff suppressed because it is too large
Load diff
|
@ -118,8 +118,16 @@ CameraManager = function() {
|
||||||
that.targetYaw = 0;
|
that.targetYaw = 0;
|
||||||
that.targetPitch = 0;
|
that.targetPitch = 0;
|
||||||
|
|
||||||
that.focalPoint = { x: 0, y: 0, z: 0 };
|
that.focalPoint = {
|
||||||
that.targetFocalPoint = { x: 0, y: 0, z: 0 };
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
that.targetFocalPoint = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
|
||||||
easing = false;
|
easing = false;
|
||||||
easingTime = 0;
|
easingTime = 0;
|
||||||
|
@ -127,13 +135,18 @@ CameraManager = function() {
|
||||||
|
|
||||||
that.previousCameraMode = null;
|
that.previousCameraMode = null;
|
||||||
|
|
||||||
that.lastMousePosition = { x: 0, y: 0 };
|
that.lastMousePosition = {
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
|
||||||
that.enable = function() {
|
that.enable = function() {
|
||||||
if (Camera.mode == "independent" || that.enabled) return;
|
if (Camera.mode == "independent" || that.enabled) return;
|
||||||
|
|
||||||
for (var i = 0; i < CAPTURED_KEYS.length; i++) {
|
for (var i = 0; i < CAPTURED_KEYS.length; i++) {
|
||||||
Controller.captureKeyEvents({ text: CAPTURED_KEYS[i] });
|
Controller.captureKeyEvents({
|
||||||
|
text: CAPTURED_KEYS[i]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
that.enabled = true;
|
that.enabled = true;
|
||||||
|
@ -143,7 +156,7 @@ CameraManager = function() {
|
||||||
that.zoomDistance = INITIAL_ZOOM_DISTANCE;
|
that.zoomDistance = INITIAL_ZOOM_DISTANCE;
|
||||||
that.targetZoomDistance = that.zoomDistance + 3.0;
|
that.targetZoomDistance = that.zoomDistance + 3.0;
|
||||||
var focalPoint = Vec3.sum(Camera.getPosition(),
|
var focalPoint = Vec3.sum(Camera.getPosition(),
|
||||||
Vec3.multiply(that.zoomDistance, Quat.getFront(Camera.getOrientation())));
|
Vec3.multiply(that.zoomDistance, Quat.getFront(Camera.getOrientation())));
|
||||||
|
|
||||||
// Determine the correct yaw and pitch to keep the camera in the same location
|
// Determine the correct yaw and pitch to keep the camera in the same location
|
||||||
var dPos = Vec3.subtract(focalPoint, Camera.getPosition());
|
var dPos = Vec3.subtract(focalPoint, Camera.getPosition());
|
||||||
|
@ -169,7 +182,9 @@ CameraManager = function() {
|
||||||
if (!that.enabled) return;
|
if (!that.enabled) return;
|
||||||
|
|
||||||
for (var i = 0; i < CAPTURED_KEYS.length; i++) {
|
for (var i = 0; i < CAPTURED_KEYS.length; i++) {
|
||||||
Controller.releaseKeyEvents({ text: CAPTURED_KEYS[i] });
|
Controller.releaseKeyEvents({
|
||||||
|
text: CAPTURED_KEYS[i]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
that.enabled = false;
|
that.enabled = false;
|
||||||
|
@ -335,19 +350,27 @@ CameraManager = function() {
|
||||||
|
|
||||||
var hasDragged = false;
|
var hasDragged = false;
|
||||||
that.mousePressEvent = function(event) {
|
that.mousePressEvent = function(event) {
|
||||||
|
|
||||||
if (cameraTool.mousePressEvent(event)) {
|
if (cameraTool.mousePressEvent(event)) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!that.enabled) return;
|
if (!that.enabled) return;
|
||||||
|
|
||||||
if (event.isRightButton || (event.isLeftButton && event.isControl && !event.isShifted)) {
|
if (event.isRightButton || (event.isLeftButton && event.isControl && !event.isShifted)) {
|
||||||
|
|
||||||
that.mode = MODE_ORBIT;
|
that.mode = MODE_ORBIT;
|
||||||
} else if (event.isMiddleButton || (event.isLeftButton && event.isControl && event.isShifted)) {
|
} else if (event.isMiddleButton || (event.isLeftButton && event.isControl && event.isShifted)) {
|
||||||
|
|
||||||
|
|
||||||
that.mode = MODE_PAN;
|
that.mode = MODE_PAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (that.mode != MODE_INACTIVE) {
|
if (that.mode !== MODE_INACTIVE) {
|
||||||
|
|
||||||
|
|
||||||
hasDragged = false;
|
hasDragged = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -357,10 +380,12 @@ CameraManager = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
that.mouseReleaseEvent = function(event) {
|
that.mouseReleaseEvent = function(event) {
|
||||||
|
|
||||||
if (!that.enabled) return;
|
if (!that.enabled) return;
|
||||||
|
|
||||||
Window.setCursorVisible(true);
|
|
||||||
that.mode = MODE_INACTIVE;
|
that.mode = MODE_INACTIVE;
|
||||||
|
Window.setCursorVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
that.keyPressEvent = function(event) {
|
that.keyPressEvent = function(event) {
|
||||||
|
@ -396,15 +421,31 @@ CameraManager = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var yRot = Quat.angleAxis(that.yaw, { x: 0, y: 1, z: 0 });
|
var yRot = Quat.angleAxis(that.yaw, {
|
||||||
var xRot = Quat.angleAxis(that.pitch, { x: 1, y: 0, z: 0 });
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
});
|
||||||
|
var xRot = Quat.angleAxis(that.pitch, {
|
||||||
|
x: 1,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
});
|
||||||
var q = Quat.multiply(yRot, xRot);
|
var q = Quat.multiply(yRot, xRot);
|
||||||
|
|
||||||
var pos = Vec3.multiply(Quat.getFront(q), that.zoomDistance);
|
var pos = Vec3.multiply(Quat.getFront(q), that.zoomDistance);
|
||||||
Camera.setPosition(Vec3.sum(that.focalPoint, pos));
|
Camera.setPosition(Vec3.sum(that.focalPoint, pos));
|
||||||
|
|
||||||
yRot = Quat.angleAxis(that.yaw - 180, { x: 0, y: 1, z: 0 });
|
yRot = Quat.angleAxis(that.yaw - 180, {
|
||||||
xRot = Quat.angleAxis(-that.pitch, { x: 1, y: 0, z: 0 });
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
});
|
||||||
|
xRot = Quat.angleAxis(-that.pitch, {
|
||||||
|
x: 1,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
});
|
||||||
q = Quat.multiply(yRot, xRot);
|
q = Quat.multiply(yRot, xRot);
|
||||||
|
|
||||||
if (easing) {
|
if (easing) {
|
||||||
|
@ -483,7 +524,7 @@ CameraManager = function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Controller.keyReleaseEvent.connect(function (event) {
|
Controller.keyReleaseEvent.connect(function(event) {
|
||||||
if (event.text == "ESC" && that.enabled) {
|
if (event.text == "ESC" && that.enabled) {
|
||||||
Camera.mode = lastAvatarCameraMode;
|
Camera.mode = lastAvatarCameraMode;
|
||||||
cameraManager.disable(true);
|
cameraManager.disable(true);
|
||||||
|
@ -503,9 +544,21 @@ CameraManager = function() {
|
||||||
CameraTool = function(cameraManager) {
|
CameraTool = function(cameraManager) {
|
||||||
var that = {};
|
var that = {};
|
||||||
|
|
||||||
var RED = { red: 191, green: 78, blue: 38 };
|
var RED = {
|
||||||
var GREEN = { red: 26, green: 193, blue: 105 };
|
red: 191,
|
||||||
var BLUE = { red: 0, green: 131, blue: 204 };
|
green: 78,
|
||||||
|
blue: 38
|
||||||
|
};
|
||||||
|
var GREEN = {
|
||||||
|
red: 26,
|
||||||
|
green: 193,
|
||||||
|
blue: 105
|
||||||
|
};
|
||||||
|
var BLUE = {
|
||||||
|
red: 0,
|
||||||
|
green: 131,
|
||||||
|
blue: 204
|
||||||
|
};
|
||||||
|
|
||||||
var BORDER_WIDTH = 1;
|
var BORDER_WIDTH = 1;
|
||||||
|
|
||||||
|
@ -513,10 +566,10 @@ CameraTool = function(cameraManager) {
|
||||||
var ORIENTATION_OVERLAY_HALF_SIZE = ORIENTATION_OVERLAY_SIZE / 2;
|
var ORIENTATION_OVERLAY_HALF_SIZE = ORIENTATION_OVERLAY_SIZE / 2;
|
||||||
var ORIENTATION_OVERLAY_CUBE_SIZE = 10.5,
|
var ORIENTATION_OVERLAY_CUBE_SIZE = 10.5,
|
||||||
|
|
||||||
var ORIENTATION_OVERLAY_OFFSET = {
|
var ORIENTATION_OVERLAY_OFFSET = {
|
||||||
x: 30,
|
x: 30,
|
||||||
y: 30,
|
y: 30,
|
||||||
}
|
}
|
||||||
|
|
||||||
var UI_WIDTH = 70;
|
var UI_WIDTH = 70;
|
||||||
var UI_HEIGHT = 70;
|
var UI_HEIGHT = 70;
|
||||||
|
@ -536,7 +589,11 @@ CameraTool = function(cameraManager) {
|
||||||
height: UI_HEIGHT + BORDER_WIDTH * 2,
|
height: UI_HEIGHT + BORDER_WIDTH * 2,
|
||||||
alpha: 0,
|
alpha: 0,
|
||||||
text: "",
|
text: "",
|
||||||
backgroundColor: { red: 101, green: 101, blue: 101 },
|
backgroundColor: {
|
||||||
|
red: 101,
|
||||||
|
green: 101,
|
||||||
|
blue: 101
|
||||||
|
},
|
||||||
backgroundAlpha: 1.0,
|
backgroundAlpha: 1.0,
|
||||||
visible: false,
|
visible: false,
|
||||||
});
|
});
|
||||||
|
@ -548,7 +605,11 @@ CameraTool = function(cameraManager) {
|
||||||
height: UI_HEIGHT,
|
height: UI_HEIGHT,
|
||||||
alpha: 0,
|
alpha: 0,
|
||||||
text: "",
|
text: "",
|
||||||
backgroundColor: { red: 51, green: 51, blue: 51 },
|
backgroundColor: {
|
||||||
|
red: 51,
|
||||||
|
green: 51,
|
||||||
|
blue: 51
|
||||||
|
},
|
||||||
backgroundAlpha: 1.0,
|
backgroundAlpha: 1.0,
|
||||||
visible: false,
|
visible: false,
|
||||||
});
|
});
|
||||||
|
@ -556,7 +617,11 @@ CameraTool = function(cameraManager) {
|
||||||
var defaultCubeProps = {
|
var defaultCubeProps = {
|
||||||
size: ORIENTATION_OVERLAY_CUBE_SIZE,
|
size: ORIENTATION_OVERLAY_CUBE_SIZE,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
color: { red: 255, green: 0, blue: 0 },
|
color: {
|
||||||
|
red: 255,
|
||||||
|
green: 0,
|
||||||
|
blue: 0
|
||||||
|
},
|
||||||
solid: true,
|
solid: true,
|
||||||
visible: true,
|
visible: true,
|
||||||
drawOnHUD: true,
|
drawOnHUD: true,
|
||||||
|
@ -564,10 +629,26 @@ CameraTool = function(cameraManager) {
|
||||||
var defaultLineProps = {
|
var defaultLineProps = {
|
||||||
lineWidth: 1.5,
|
lineWidth: 1.5,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
position: { x: 0, y: 0, z: 0 },
|
position: {
|
||||||
start: { x: 0, y: 0, z: 0 },
|
x: 0,
|
||||||
end: { x: 0, y: 0, z: 0 },
|
y: 0,
|
||||||
color: { red: 255, green: 0, blue: 0 },
|
z: 0
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
red: 255,
|
||||||
|
green: 0,
|
||||||
|
blue: 0
|
||||||
|
},
|
||||||
visible: false,
|
visible: false,
|
||||||
drawOnHUD: true,
|
drawOnHUD: true,
|
||||||
};
|
};
|
||||||
|
@ -582,30 +663,66 @@ CameraTool = function(cameraManager) {
|
||||||
|
|
||||||
var OOHS = ORIENTATION_OVERLAY_HALF_SIZE;
|
var OOHS = ORIENTATION_OVERLAY_HALF_SIZE;
|
||||||
var cubeX = orientationOverlay.createOverlay("cube", mergeObjects(defaultCubeProps, {
|
var cubeX = orientationOverlay.createOverlay("cube", mergeObjects(defaultCubeProps, {
|
||||||
position: { x: -OOHS, y: OOHS, z: OOHS },
|
position: {
|
||||||
|
x: -OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
color: RED,
|
color: RED,
|
||||||
}));
|
}));
|
||||||
var cubeY = orientationOverlay.createOverlay("cube", mergeObjects(defaultCubeProps, {
|
var cubeY = orientationOverlay.createOverlay("cube", mergeObjects(defaultCubeProps, {
|
||||||
position: { x: OOHS, y: -OOHS, z: OOHS },
|
position: {
|
||||||
|
x: OOHS,
|
||||||
|
y: -OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
color: GREEN,
|
color: GREEN,
|
||||||
}));
|
}));
|
||||||
var cubeZ = orientationOverlay.createOverlay("cube", mergeObjects(defaultCubeProps, {
|
var cubeZ = orientationOverlay.createOverlay("cube", mergeObjects(defaultCubeProps, {
|
||||||
position: { x: OOHS, y: OOHS, z: -OOHS },
|
position: {
|
||||||
|
x: OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: -OOHS
|
||||||
|
},
|
||||||
color: BLUE,
|
color: BLUE,
|
||||||
}));
|
}));
|
||||||
orientationOverlay.createOverlay("line3d", mergeObjects(defaultLineProps, {
|
orientationOverlay.createOverlay("line3d", mergeObjects(defaultLineProps, {
|
||||||
start: { x: -OOHS, y: OOHS, z: OOHS },
|
start: {
|
||||||
end: { x: OOHS, y: OOHS, z: OOHS },
|
x: -OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
x: OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
color: RED,
|
color: RED,
|
||||||
}));
|
}));
|
||||||
orientationOverlay.createOverlay("line3d", mergeObjects(defaultLineProps, {
|
orientationOverlay.createOverlay("line3d", mergeObjects(defaultLineProps, {
|
||||||
start: { x: OOHS, y: -OOHS, z: OOHS },
|
start: {
|
||||||
end: { x: OOHS, y: OOHS, z: OOHS },
|
x: OOHS,
|
||||||
|
y: -OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
x: OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
color: GREEN,
|
color: GREEN,
|
||||||
}));
|
}));
|
||||||
orientationOverlay.createOverlay("line3d", mergeObjects(defaultLineProps, {
|
orientationOverlay.createOverlay("line3d", mergeObjects(defaultLineProps, {
|
||||||
start: { x: OOHS, y: OOHS, z: -OOHS },
|
start: {
|
||||||
end: { x: OOHS, y: OOHS, z: OOHS },
|
x: OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: -OOHS
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
x: OOHS,
|
||||||
|
y: OOHS,
|
||||||
|
z: OOHS
|
||||||
|
},
|
||||||
color: BLUE,
|
color: BLUE,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -645,7 +762,10 @@ CameraTool = function(cameraManager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
that.mousePressEvent = function(event) {
|
that.mousePressEvent = function(event) {
|
||||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
|
var clickedOverlay = Overlays.getOverlayAtPoint({
|
||||||
|
x: event.x,
|
||||||
|
y: event.y
|
||||||
|
});
|
||||||
|
|
||||||
if (clickedOverlay == cubeX) {
|
if (clickedOverlay == cubeX) {
|
||||||
targetPitch = 0;
|
targetPitch = 0;
|
||||||
|
@ -666,12 +786,18 @@ CameraTool = function(cameraManager) {
|
||||||
};
|
};
|
||||||
|
|
||||||
that.setVisible = function(visible) {
|
that.setVisible = function(visible) {
|
||||||
orientationOverlay.setProperties({ visible: visible });
|
orientationOverlay.setProperties({
|
||||||
Overlays.editOverlay(background, { visible: visible });
|
visible: visible
|
||||||
Overlays.editOverlay(backgroundBorder, { visible: visible });
|
});
|
||||||
|
Overlays.editOverlay(background, {
|
||||||
|
visible: visible
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(backgroundBorder, {
|
||||||
|
visible: visible
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
that.setVisible(false);
|
that.setVisible(false);
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
Loading…
Reference in a new issue