From 027811e37cbba0cc211e0c54779a071d217241c1 Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 23 Sep 2013 22:53:35 -0700 Subject: [PATCH] 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