mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-05 10:07:43 +02:00
added oldMode as global vairable
This commit is contained in:
parent
986eea7c86
commit
ce1ccf1c40
1 changed files with 233 additions and 192 deletions
|
@ -25,8 +25,18 @@ var ALTITUDE_RATE = 200.0;
|
||||||
var RADIUS_RATE = 1.0 / 100.0;
|
var RADIUS_RATE = 1.0 / 100.0;
|
||||||
var PAN_RATE = 50.0;
|
var PAN_RATE = 50.0;
|
||||||
|
|
||||||
var Y_AXIS = { x: 0, y: 1, z: 0 };
|
var Y_AXIS = {
|
||||||
var X_AXIS = { x: 1, y: 0, z: 0 };
|
x: 0,
|
||||||
|
y: 1,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
var X_AXIS = {
|
||||||
|
x: 1,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
var LOOK_AT_TIME = 500;
|
||||||
|
|
||||||
var alt = false;
|
var alt = false;
|
||||||
var shift = false;
|
var shift = false;
|
||||||
|
@ -34,6 +44,7 @@ var control = false;
|
||||||
|
|
||||||
var isActive = false;
|
var isActive = false;
|
||||||
|
|
||||||
|
var oldMode = Camera.mode;
|
||||||
var noMode = 0;
|
var noMode = 0;
|
||||||
var orbitMode = 1;
|
var orbitMode = 1;
|
||||||
var radialMode = 2;
|
var radialMode = 2;
|
||||||
|
@ -46,9 +57,21 @@ var mouseLastX = 0;
|
||||||
var mouseLastY = 0;
|
var mouseLastY = 0;
|
||||||
|
|
||||||
|
|
||||||
var center = { x: 0, y: 0, z: 0 };
|
var center = {
|
||||||
var position = { x: 0, y: 0, z: 0 };
|
x: 0,
|
||||||
var vector = { x: 0, y: 0, z: 0 };
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
var position = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
var vector = {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
var radius = 0.0;
|
var radius = 0.0;
|
||||||
var azimuth = 0.0;
|
var azimuth = 0.0;
|
||||||
var altitude = 0.0;
|
var altitude = 0.0;
|
||||||
|
@ -56,6 +79,10 @@ var altitude = 0.0;
|
||||||
var avatarPosition;
|
var avatarPosition;
|
||||||
var avatarOrientation;
|
var avatarOrientation;
|
||||||
|
|
||||||
|
var rotatingTowardsTarget = false;
|
||||||
|
var targetCamOrientation;
|
||||||
|
var oldPosition, oldOrientation;
|
||||||
|
|
||||||
|
|
||||||
function orientationOf(vector) {
|
function orientationOf(vector) {
|
||||||
var direction,
|
var direction,
|
||||||
|
@ -76,9 +103,11 @@ function handleRadialMode(dx, dy) {
|
||||||
radius = 1;
|
radius = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector = { x: (Math.cos(altitude) * Math.cos(azimuth)) * radius,
|
vector = {
|
||||||
|
x: (Math.cos(altitude) * Math.cos(azimuth)) * radius,
|
||||||
y: Math.sin(altitude) * radius,
|
y: Math.sin(altitude) * radius,
|
||||||
z: (Math.cos(altitude) * Math.sin(azimuth)) * radius };
|
z: (Math.cos(altitude) * Math.sin(azimuth)) * radius
|
||||||
|
};
|
||||||
position = Vec3.sum(center, vector);
|
position = Vec3.sum(center, vector);
|
||||||
Camera.setPosition(position);
|
Camera.setPosition(position);
|
||||||
Camera.setOrientation(orientationOf(vector));
|
Camera.setOrientation(orientationOf(vector));
|
||||||
|
@ -94,9 +123,11 @@ function handleOrbitMode(dx, dy) {
|
||||||
altitude = -PI / 2.0;
|
altitude = -PI / 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector = { x:(Math.cos(altitude) * Math.cos(azimuth)) * radius,
|
vector = {
|
||||||
|
x: (Math.cos(altitude) * Math.cos(azimuth)) * radius,
|
||||||
y: Math.sin(altitude) * radius,
|
y: Math.sin(altitude) * radius,
|
||||||
z:(Math.cos(altitude) * Math.sin(azimuth)) * radius };
|
z: (Math.cos(altitude) * Math.sin(azimuth)) * radius
|
||||||
|
};
|
||||||
position = Vec3.sum(center, vector);
|
position = Vec3.sum(center, vector);
|
||||||
Camera.setPosition(position);
|
Camera.setPosition(position);
|
||||||
Camera.setOrientation(orientationOf(vector));
|
Camera.setOrientation(orientationOf(vector));
|
||||||
|
@ -119,13 +150,17 @@ function handlePanMode(dx, dy) {
|
||||||
|
|
||||||
function saveCameraState() {
|
function saveCameraState() {
|
||||||
oldMode = Camera.mode;
|
oldMode = Camera.mode;
|
||||||
var oldPosition = Camera.getPosition();
|
oldPosition = Camera.getPosition();
|
||||||
|
oldOrientation = Camera.getOrientation();
|
||||||
|
|
||||||
Camera.mode = "independent";
|
Camera.mode = "independent";
|
||||||
Camera.setPosition(oldPosition);
|
Camera.setPosition(oldPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreCameraState() {
|
function restoreCameraState() {
|
||||||
Camera.mode = oldMode;
|
Camera.mode = oldMode;
|
||||||
|
Camera.setPosition(oldPosition);
|
||||||
|
Camera.setOrientation(oldOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleModes() {
|
function handleModes() {
|
||||||
|
@ -202,6 +237,8 @@ function keyReleaseEvent(event) {
|
||||||
if (event.text == "ALT") {
|
if (event.text == "ALT") {
|
||||||
alt = false;
|
alt = false;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
mode = noMode;
|
||||||
|
restoreCameraState();
|
||||||
}
|
}
|
||||||
if (event.text == "CONTROL") {
|
if (event.text == "CONTROL") {
|
||||||
control = false;
|
control = false;
|
||||||
|
@ -226,7 +263,7 @@ function mousePressEvent(event) {
|
||||||
|
|
||||||
// Compute trajectories related values
|
// Compute trajectories related values
|
||||||
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
|
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
|
||||||
var modelIntersection = Entities.findRayIntersection(pickRay);
|
var modelIntersection = Entities.findRayIntersection(pickRay, true);
|
||||||
|
|
||||||
position = Camera.getPosition();
|
position = Camera.getPosition();
|
||||||
|
|
||||||
|
@ -238,29 +275,25 @@ function mousePressEvent(event) {
|
||||||
|
|
||||||
if (modelIntersection.intersects && modelIntersection.accurate) {
|
if (modelIntersection.intersects && modelIntersection.accurate) {
|
||||||
distance = modelIntersection.distance;
|
distance = modelIntersection.distance;
|
||||||
center = modelIntersection.properties.position;
|
center = modelIntersection.intersection;
|
||||||
string = "Inspecting model";
|
string = "Inspecting model";
|
||||||
}
|
//We've selected our target, now orbit towards it automatically
|
||||||
|
rotatingTowardsTarget = true;
|
||||||
if ((distance == -1 || Vec3.length(Vec3.subtract(avatarTarget, position)) < distance) &&
|
//calculate our target cam rotation
|
||||||
(avatarTarget.x != 0 || avatarTarget.y != 0 || avatarTarget.z != 0)) {
|
Script.setTimeout(function() {
|
||||||
distance = Vec3.length(Vec3.subtract(avatarTarget, position));
|
rotatingTowardsTarget = false;
|
||||||
center = avatarTarget;
|
}, LOOK_AT_TIME);
|
||||||
string = "Inspecting avatar";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (distance == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector = Vec3.subtract(position, center);
|
vector = Vec3.subtract(position, center);
|
||||||
|
targetCamOrientation = orientationOf(vector);
|
||||||
radius = Vec3.length(vector);
|
radius = Vec3.length(vector);
|
||||||
azimuth = Math.atan2(vector.z, vector.x);
|
azimuth = Math.atan2(vector.z, vector.x);
|
||||||
altitude = Math.asin(vector.y / Vec3.length(vector));
|
altitude = Math.asin(vector.y / Vec3.length(vector));
|
||||||
|
|
||||||
print(string);
|
|
||||||
isActive = true;
|
isActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
|
@ -270,7 +303,7 @@ function mouseReleaseEvent(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseMoveEvent(event) {
|
function mouseMoveEvent(event) {
|
||||||
if (isActive && mode != noMode) {
|
if (isActive && mode != noMode && !rotatingTowardsTarget) {
|
||||||
if (mode == radialMode) {
|
if (mode == radialMode) {
|
||||||
handleRadialMode(event.x - mouseLastX, event.y - mouseLastY);
|
handleRadialMode(event.x - mouseLastX, event.y - mouseLastY);
|
||||||
}
|
}
|
||||||
|
@ -281,13 +314,21 @@ function mouseMoveEvent(event) {
|
||||||
handlePanMode(event.x - mouseLastX, event.y - mouseLastY);
|
handlePanMode(event.x - mouseLastX, event.y - mouseLastY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
mouseLastX = event.x;
|
mouseLastX = event.x;
|
||||||
mouseLastY = event.y;
|
mouseLastY = event.y;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
handleModes();
|
handleModes();
|
||||||
|
if (rotatingTowardsTarget) {
|
||||||
|
rotateTowardsTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rotateTowardsTarget() {
|
||||||
|
var newOrientation = Quat.mix(Camera.getOrientation(), targetCamOrientation, .1);
|
||||||
|
Camera.setOrientation(newOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
function scriptEnding() {
|
function scriptEnding() {
|
||||||
|
|
Loading…
Reference in a new issue