From 027811e37cbba0cc211e0c54779a071d217241c1 Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 23 Sep 2013 22:53:35 -0700 Subject: [PATCH 1/3] Increase thrust while holding keys down to allow very fast speeds --- interface/src/Application.cpp | 2 +- interface/src/avatar/MyAvatar.cpp | 28 +++++++++++++++++++--------- interface/src/avatar/MyAvatar.h | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d90c82e6ca..079f8dfdc8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2820,7 +2820,7 @@ void Application::displayStats() { char avatarStats[200]; glm::vec3 avatarPos = _myAvatar.getPosition(); - sprintf(avatarStats, "Avatar position: %.3f, %.3f, %.3f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, _myAvatar.getBodyYaw()); + sprintf(avatarStats, "Avatar: pos %.3f, %.3f, %.3f, vel %.1f, yaw = %.2f", avatarPos.x, avatarPos.y, avatarPos.z, glm::length(_myAvatar.getVelocity()), _myAvatar.getBodyYaw()); drawtext(10, statsVerticalOffset + 55, 0.10f, 0, 1.0, 0, avatarStats); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 794ad7cf95..fd7701fd88 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -50,7 +50,8 @@ MyAvatar::MyAvatar(Node* owningNode) : _elapsedTimeSinceCollision(0.0f), _lastCollisionPosition(0, 0, 0), _speedBrakes(false), - _isThrustOn(false) + _isThrustOn(false), + _thrustMultiplier(1.0f) { for (int i = 0; i < MAX_DRIVE_KEYS; i++) { _driveKeys[i] = false; @@ -210,9 +211,10 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam const float STATIC_FRICTION_STRENGTH = _scale * 20.f; applyStaticFriction(deltaTime, _velocity, MAX_STATIC_FRICTION_VELOCITY, STATIC_FRICTION_STRENGTH); - const float LINEAR_DAMPING_STRENGTH = 1.0f; + const float LINEAR_DAMPING_STRENGTH = 0.5f; const float SPEED_BRAKE_POWER = _scale * 10.0f; - const float SQUARED_DAMPING_STRENGTH = 0.2f; + // Note: PER changed squared damping strength to zero + const float SQUARED_DAMPING_STRENGTH = 0.0f; if (_speedBrakes) { applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH * SPEED_BRAKE_POWER, SQUARED_DAMPING_STRENGTH * SPEED_BRAKE_POWER); } else { @@ -626,15 +628,23 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { const float THRUST_JUMP = 120.f; // Add Thrusts from keyboard - if (_driveKeys[FWD]) {_thrust += _scale * THRUST_MAG_FWD * deltaTime * front;} - if (_driveKeys[BACK]) {_thrust -= _scale * THRUST_MAG_BACK * deltaTime * front;} - if (_driveKeys[RIGHT]) {_thrust += _scale * THRUST_MAG_LATERAL * deltaTime * right;} - if (_driveKeys[LEFT]) {_thrust -= _scale * THRUST_MAG_LATERAL * deltaTime * right;} - if (_driveKeys[UP]) {_thrust += _scale * THRUST_MAG_UP * deltaTime * up;} - if (_driveKeys[DOWN]) {_thrust -= _scale * THRUST_MAG_DOWN * deltaTime * up;} + if (_driveKeys[FWD]) {_thrust += _scale * THRUST_MAG_FWD * _thrustMultiplier * deltaTime * front;} + if (_driveKeys[BACK]) {_thrust -= _scale * THRUST_MAG_BACK * _thrustMultiplier * deltaTime * front;} + if (_driveKeys[RIGHT]) {_thrust += _scale * THRUST_MAG_LATERAL * _thrustMultiplier * deltaTime * right;} + if (_driveKeys[LEFT]) {_thrust -= _scale * THRUST_MAG_LATERAL * _thrustMultiplier * deltaTime * right;} + if (_driveKeys[UP]) {_thrust += _scale * THRUST_MAG_UP * _thrustMultiplier * deltaTime * up;} + if (_driveKeys[DOWN]) {_thrust -= _scale * THRUST_MAG_DOWN * _thrustMultiplier * deltaTime * up;} if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;} if (_driveKeys[ROT_LEFT]) {_bodyYawDelta += YAW_MAG * deltaTime;} + // If thrust keys are being held down, slowly increase thrust to allow reaching great speeds + if (_driveKeys[FWD] || _driveKeys[BACK] || _driveKeys[RIGHT] || _driveKeys[LEFT] || _driveKeys[UP] || _driveKeys[DOWN]) { + const float THRUST_INCREASE_RATE = 1.0; + _thrustMultiplier *= 1.f + deltaTime* THRUST_INCREASE_RATE; + } else { + _thrustMultiplier = 1.f; + } + // Add one time jumping force if requested if (_shouldJump) { _thrust += _scale * THRUST_JUMP * up; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index f6ec055496..feea7f4e7a 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -71,6 +71,7 @@ public: glm::vec3 _lastCollisionPosition; bool _speedBrakes; bool _isThrustOn; + float _thrustMultiplier; float _collisionRadius; // private methods From 36104d0b06e37a6f97910994377c3a7b1ad0f8cf Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 23 Sep 2013 23:04:27 -0700 Subject: [PATCH 2/3] remove unused older voxel grab thrust --- interface/src/Application.cpp | 20 -------------------- interface/src/Application.h | 1 - 2 files changed, 21 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 079f8dfdc8..e5d36b40fd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1798,27 +1798,7 @@ void Application::update(float deltaTime) { _isHoverVoxelSounding = true; } } - - // If we are dragging on a voxel, add thrust according to the amount the mouse is dragging - const float VOXEL_GRAB_THRUST = 0.0f; - if (_mousePressed && (_mouseVoxel.s != 0)) { - glm::vec2 mouseDrag(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY); - glm::quat orientation = _myAvatar.getOrientation(); - glm::vec3 front = orientation * IDENTITY_FRONT; - glm::vec3 up = orientation * IDENTITY_UP; - glm::vec3 towardVoxel = getMouseVoxelWorldCoordinates(_mouseVoxelDragging) - - _myAvatar.getCameraPosition(); - towardVoxel = front * glm::length(towardVoxel); - glm::vec3 lateralToVoxel = glm::cross(up, glm::normalize(towardVoxel)) * glm::length(towardVoxel); - _voxelThrust = glm::vec3(0, 0, 0); - _voxelThrust += towardVoxel * VOXEL_GRAB_THRUST * deltaTime * mouseDrag.y; - _voxelThrust += lateralToVoxel * VOXEL_GRAB_THRUST * deltaTime * mouseDrag.x; - // Add thrust from voxel grabbing to the avatar - _myAvatar.addThrust(_voxelThrust); - - } - _mouseVoxel.s = 0.0f; if (Menu::getInstance()->isVoxelModeActionChecked() && (fabs(_myAvatar.getVelocity().x) + diff --git a/interface/src/Application.h b/interface/src/Application.h index e951afc735..940a311f1e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -297,7 +297,6 @@ private: float _pitchFromTouch; VoxelDetail _mouseVoxelDragging; - glm::vec3 _voxelThrust; bool _mousePressed; // true if mouse has been pressed (clear when finished) VoxelDetail _hoverVoxel; // Stuff about the voxel I am hovering or clicking From 6bbe34a8c49df395812c286b8a108b852094867c Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 23 Sep 2013 23:06:32 -0700 Subject: [PATCH 3/3] missing space --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index fd7701fd88..3c2ce3dcb5 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -640,7 +640,7 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { // If thrust keys are being held down, slowly increase thrust to allow reaching great speeds if (_driveKeys[FWD] || _driveKeys[BACK] || _driveKeys[RIGHT] || _driveKeys[LEFT] || _driveKeys[UP] || _driveKeys[DOWN]) { const float THRUST_INCREASE_RATE = 1.0; - _thrustMultiplier *= 1.f + deltaTime* THRUST_INCREASE_RATE; + _thrustMultiplier *= 1.f + deltaTime * THRUST_INCREASE_RATE; } else { _thrustMultiplier = 1.f; }