mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:37:49 +02:00
Use Picks API and orbit about point in space if no intersection
This commit is contained in:
parent
f5c1906479
commit
37b7a9c5f4
1 changed files with 33 additions and 26 deletions
|
@ -59,6 +59,13 @@ var detachedMode = 4;
|
||||||
|
|
||||||
var mode = noMode;
|
var mode = noMode;
|
||||||
|
|
||||||
|
var pick = Picks.createPick(PickType.Ray, {
|
||||||
|
filter: Picks.PICK_DOMAIN_ENTITIES | Picks.PICK_AVATAR_ENTITIES | Picks.PICK_AVATARS
|
||||||
|
| Picks.PICK_INCLUDE_COLLIDABLE | Picks.PICK_INCLUDE_NONCOLLIDABLE | Picks.PICK_PRECISE,
|
||||||
|
joint: "Mouse",
|
||||||
|
enabled: false
|
||||||
|
});
|
||||||
|
|
||||||
var mouseLastX = 0;
|
var mouseLastX = 0;
|
||||||
var mouseLastY = 0;
|
var mouseLastY = 0;
|
||||||
|
|
||||||
|
@ -221,6 +228,7 @@ function keyPressEvent(event) {
|
||||||
if (event.text === "ALT") {
|
if (event.text === "ALT") {
|
||||||
alt = true;
|
alt = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
Picks.enablePick(pick);
|
||||||
}
|
}
|
||||||
if (event.text === "CONTROL") {
|
if (event.text === "CONTROL") {
|
||||||
control = true;
|
control = true;
|
||||||
|
@ -248,6 +256,7 @@ function keyReleaseEvent(event) {
|
||||||
if (event.text === "ALT") {
|
if (event.text === "ALT") {
|
||||||
alt = false;
|
alt = false;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
Picks.disablePick(pick);
|
||||||
}
|
}
|
||||||
if (event.text === "CONTROL") {
|
if (event.text === "CONTROL") {
|
||||||
control = false;
|
control = false;
|
||||||
|
@ -268,34 +277,32 @@ function mousePressEvent(event) {
|
||||||
mouseLastX = event.x;
|
mouseLastX = event.x;
|
||||||
mouseLastY = event.y;
|
mouseLastY = event.y;
|
||||||
|
|
||||||
// Compute trajectories related values
|
position = Camera.position;
|
||||||
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
|
|
||||||
var modelIntersection = Entities.findRayIntersection(pickRay, true);
|
|
||||||
var avatarIntersection = AvatarList.findRayIntersection(pickRay);
|
|
||||||
|
|
||||||
position = Camera.getPosition();
|
var pickResult = Picks.getPrevPickResult(pick);
|
||||||
|
if (pickResult.intersects) {
|
||||||
if (avatarIntersection.intersects || (modelIntersection.intersects && modelIntersection.accurate)) {
|
// Orbit about intersection.
|
||||||
if (avatarIntersection.intersects) {
|
center = pickResult.intersection;
|
||||||
center = avatarIntersection.intersection;
|
} else {
|
||||||
} else {
|
// Orbit about point in space.
|
||||||
center = modelIntersection.intersection;
|
var ORBIT_DISTANCE = 10.0;
|
||||||
}
|
center = Vec3.sum(position, Vec3.multiply(ORBIT_DISTANCE, pickResult.searchRay.direction));
|
||||||
// We've selected our target, now orbit towards it automatically
|
|
||||||
rotatingTowardsTarget = true;
|
|
||||||
// calculate our target cam rotation
|
|
||||||
Script.setTimeout(function () {
|
|
||||||
rotatingTowardsTarget = false;
|
|
||||||
}, LOOK_AT_TIME);
|
|
||||||
|
|
||||||
vector = Vec3.subtract(position, center);
|
|
||||||
targetCamOrientation = orientationOf(vector);
|
|
||||||
radius = Vec3.length(vector);
|
|
||||||
azimuth = Math.atan2(vector.z, vector.x);
|
|
||||||
altitude = Math.asin(vector.y / Vec3.length(vector));
|
|
||||||
|
|
||||||
isActive = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We've selected our target, now orbit towards it automatically
|
||||||
|
rotatingTowardsTarget = true;
|
||||||
|
// calculate our target cam rotation
|
||||||
|
Script.setTimeout(function () {
|
||||||
|
rotatingTowardsTarget = false;
|
||||||
|
}, LOOK_AT_TIME);
|
||||||
|
|
||||||
|
vector = Vec3.subtract(position, center);
|
||||||
|
targetCamOrientation = orientationOf(vector);
|
||||||
|
radius = Vec3.length(vector);
|
||||||
|
azimuth = Math.atan2(vector.z, vector.x);
|
||||||
|
altitude = Math.asin(vector.y / Vec3.length(vector));
|
||||||
|
|
||||||
|
isActive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue