mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
if two people grab an enitity at once, don't forget about the original gravity
This commit is contained in:
parent
aade273b6c
commit
237eb72bec
1 changed files with 38 additions and 6 deletions
|
@ -27,7 +27,7 @@ var ANGULAR_DAMPING_RATE = 0.40;
|
|||
var SCREEN_TO_METERS = 0.001;
|
||||
var currentPosition, currentVelocity, cameraEntityDistance, currentRotation;
|
||||
var velocityTowardTarget, desiredVelocity, addedVelocity, newVelocity, dPosition, camYaw, distanceToTarget, targetPosition;
|
||||
var originalGravity;
|
||||
var originalGravity = {x: 0, y: 0, z: 0};
|
||||
var shouldRotate = false;
|
||||
var dQ, theta, axisAngle, dT;
|
||||
var angularVelocity = {
|
||||
|
@ -56,6 +56,15 @@ var dropLine = Overlays.addOverlay("line3d", {
|
|||
});
|
||||
|
||||
|
||||
function vectorIsZero(v) {
|
||||
return v.x == 0 && v.y == 0 && v.z == 0;
|
||||
}
|
||||
|
||||
function vectorToString(v) {
|
||||
return "(" + v.x + ", " + v.y + ", " + v.z + ")"
|
||||
}
|
||||
|
||||
|
||||
function mousePressEvent(event) {
|
||||
if (!event.isLeftButton) {
|
||||
return;
|
||||
|
@ -67,10 +76,16 @@ function mousePressEvent(event) {
|
|||
var props = Entities.getEntityProperties(grabbedEntity)
|
||||
isGrabbing = true;
|
||||
originalGravity = props.gravity;
|
||||
print("mouse-press setting originalGravity " + originalGravity + " " + vectorToString(originalGravity));
|
||||
targetPosition = props.position;
|
||||
currentPosition = props.position;
|
||||
currentVelocity = props.velocity;
|
||||
updateDropLine(targetPosition);
|
||||
|
||||
Entities.editEntity(grabbedEntity, {
|
||||
gravity: {x: 0, y: 0, z: 0}
|
||||
});
|
||||
|
||||
Audio.playSound(grabSound, {
|
||||
position: props.position,
|
||||
volume: 0.4
|
||||
|
@ -99,9 +114,20 @@ function mouseReleaseEvent() {
|
|||
if (isGrabbing) {
|
||||
isGrabbing = false;
|
||||
|
||||
Entities.editEntity(grabbedEntity, {
|
||||
gravity: originalGravity
|
||||
});
|
||||
// only restore the original gravity if it's not zero. This is to avoid...
|
||||
// 1. interface A grabs an entity and locally saves off its gravity
|
||||
// 2. interface A sets the entity's gravity to zero
|
||||
// 3. interface B grabs the entity and saves off its gravity (which is zero)
|
||||
// 4. interface A releases the entity and puts the original gravity back
|
||||
// 5. interface B releases the entity and puts the original gravity back (to zero)
|
||||
if (!vectorIsZero(originalGravity)) {
|
||||
print("mouse-release restoring originalGravity" + vectorToString(originalGravity));
|
||||
Entities.editEntity(grabbedEntity, {
|
||||
gravity: originalGravity
|
||||
});
|
||||
} else {
|
||||
print("mouse-release not restoring originalGravity of zero");
|
||||
}
|
||||
|
||||
Overlays.editOverlay(dropLine, {
|
||||
visible: false
|
||||
|
@ -117,6 +143,13 @@ function mouseReleaseEvent() {
|
|||
|
||||
function mouseMoveEvent(event) {
|
||||
if (isGrabbing) {
|
||||
// see if something added/restored gravity
|
||||
var props = Entities.getEntityProperties(grabbedEntity);
|
||||
if (!vectorIsZero(props.gravity)) {
|
||||
originalGravity = props.gravity;
|
||||
print("mouse-move adopting originalGravity" + vectorToString(originalGravity));
|
||||
}
|
||||
|
||||
deltaMouse.x = event.x - prevMouse.x;
|
||||
if (!moveUpDown) {
|
||||
deltaMouse.z = event.y - prevMouse.y;
|
||||
|
@ -211,8 +244,7 @@ function update(deltaTime) {
|
|||
|
||||
Entities.editEntity(grabbedEntity, {
|
||||
velocity: newVelocity,
|
||||
angularVelocity: angularVelocity,
|
||||
gravity: {x: 0, y: 0, z: 0}
|
||||
angularVelocity: angularVelocity
|
||||
})
|
||||
updateDropLine(targetPosition);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue