diff --git a/src/dynamic_body.cpp b/src/dynamic_body.cpp index f1c12a9..13b50f8 100644 --- a/src/dynamic_body.cpp +++ b/src/dynamic_body.cpp @@ -60,6 +60,10 @@ vector3d DynamicBody::GetAngularMomentum(void) { return I * vector3d(dBodyGetAngularVel(m_body)); } +vector3d DynamicBody::GetAngVelocity(void) { + return vector3d(dBodyGetAngularVel(m_body)); +} + DynamicBody::~DynamicBody(void) { dBodyDestroy(m_body); } diff --git a/src/dynamic_body.h b/src/dynamic_body.h index 804b313..019cd42 100644 --- a/src/dynamic_body.h +++ b/src/dynamic_body.h @@ -14,6 +14,7 @@ public: virtual void GetRotMatrix(matrix4x4d& m); virtual void SetVelocity(vector3d v); virtual vector3d GetVelocity(void); + vector3d GetAngVelocity(void); void SetAngVelocity(vector3d v); void SetMesh(ObjMesh* m); virtual bool OnCollision(Body* b, Uint32 flags) { return true; } diff --git a/src/l3d.h b/src/l3d.h index 453fc36..9bea983 100644 --- a/src/l3d.h +++ b/src/l3d.h @@ -44,7 +44,7 @@ public: static void Quit(void); static float GetFrameTime(void) { return frameTime; } static double GetGameTime(void) { return gameTime; } - static void SetTimeAccel(float s) { timeAccel = s; } + static void SetTimeAccel(float s); static float GetTimeAccel(void) { return timeAccel; } static float GetTimeStep(void) { return timeAccel*frameTime; } static int GetScrWidth(void) { return scrWidth; } diff --git a/src/main.cpp b/src/main.cpp index 3c8e43b..efe88cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -129,6 +129,18 @@ void L3D::Quit(void) { exit(0); } +void L3D::SetTimeAccel(float s) { + /* We don't want player spinning like crazy when hitting time accel. */ + if(s > 10) { + player->SetAngVelocity(vector3d(0,0,0)); + dBodySetTorque(player->m_body, 0, 0, 0); + player->SetAngThrusterState(0, 0.0f); + player->SetAngThrusterState(1, 0.0f); + player->SetAngThrusterState(2, 0.0f); + } + timeAccel = s; +} + void L3D::SetCamType(enum CamType c) { camType = c; mapView = MAP_NOMAP; diff --git a/src/player.cpp b/src/player.cpp index be405e5..90b90e2 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -73,7 +73,7 @@ void Player::TimeStepUpdate(const float timeStep) { } #define MOUSE_CTRL_AREA 10.0f -#define MOUSE_RESTITUTION 0.01f +#define MOUSE_RESTITUTION 0.75f void Player::PollControls(void) { int mouseMotion[2]; @@ -108,12 +108,11 @@ void Player::PollControls(void) { vector3f angThrust(0.0f); if(L3D::MouseButtonState(3)) { - float restitution = powf(MOUSE_RESTITUTION, L3D::GetTimeStep()); L3D::GetMouseMotion(mouseMotion); m_mouseCMov[0] += mouseMotion[0]; m_mouseCMov[1] += mouseMotion[1]; - m_mouseCMov[0] = CLAMP(m_mouseCMov[0]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); - m_mouseCMov[1] = CLAMP(m_mouseCMov[1]*restitution, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); + m_mouseCMov[0] = CLAMP(m_mouseCMov[0]*MOUSE_RESTITUTION, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); + m_mouseCMov[1] = CLAMP(m_mouseCMov[1]*MOUSE_RESTITUTION, -MOUSE_CTRL_AREA, MOUSE_CTRL_AREA); angThrust.y = -m_mouseCMov[0] / MOUSE_CTRL_AREA; angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA; } @@ -128,33 +127,26 @@ void Player::PollControls(void) { if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1); else SetGunState(0,0); - /* No torques at huge time accels -- ODE doesn't like it. */ - if(time_accel <= 10) { - if(L3D::GetCamType() != L3D::CAM_EXTERNAL) { - if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1; - if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1; - if(L3D::KeyState(SDLK_UP)) angThrust.x += -1; - if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1; - } - /* Rotation damping. */ - vector3d damping = CalcRotDamping(); - - angThrust.x -= damping.x; - angThrust.y -= damping.y; - angThrust.z -= damping.z; - - /* - * Dividing by time step so controls don't go insane when - * used at 10x accel. - */ - angThrust *= 1.0f/ta2; - SetAngThrusterState(0, angThrust.x); - SetAngThrusterState(1, angThrust.y); - SetAngThrusterState(2, angThrust.z); - } - if(time_accel > 10) { - dBodySetAngularVel(m_body, 0, 0, 0); + if(L3D::GetCamType() != L3D::CAM_EXTERNAL) { + if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1; + if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1; + if(L3D::KeyState(SDLK_UP)) angThrust.x += -1; + if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1; } + /* Rotation damping. */ + vector3d damping = time_accel*CalcRotDamping(); + + angThrust.x -= damping.x; + angThrust.y -= damping.y; + angThrust.z -= damping.z; + + /* Dividing by time step so controls don't go insane when + * used at 10x accel. + */ + angThrust *= 1.0f/ta2; + SetAngThrusterState(0, angThrust.x); + SetAngThrusterState(1, angThrust.y); + SetAngThrusterState(2, angThrust.z); } } diff --git a/src/ship.cpp b/src/ship.cpp index 8e89c02..e7b129e 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -271,6 +271,7 @@ void Ship::SetDockedWith(SpaceStation* s, int port) { m_dockedWith = s; m_dockedWithPort = port; m_dockingTimer = 0.0f; + m_wheelState = 1.0f; if(s->IsGroundStation()) m_flightState = LANDED; SetVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0));