[Change] Allow ship rotation controls at high time accel.

[Change] Force gears down on docking.
This commit is contained in:
Rtch90 2018-01-21 15:58:17 +00:00
parent 43ce19d276
commit 7749676cda
6 changed files with 41 additions and 31 deletions

View File

@ -60,6 +60,10 @@ vector3d DynamicBody::GetAngularMomentum(void) {
return I * vector3d(dBodyGetAngularVel(m_body)); return I * vector3d(dBodyGetAngularVel(m_body));
} }
vector3d DynamicBody::GetAngVelocity(void) {
return vector3d(dBodyGetAngularVel(m_body));
}
DynamicBody::~DynamicBody(void) { DynamicBody::~DynamicBody(void) {
dBodyDestroy(m_body); dBodyDestroy(m_body);
} }

View File

@ -14,6 +14,7 @@ public:
virtual void GetRotMatrix(matrix4x4d& m); virtual void GetRotMatrix(matrix4x4d& m);
virtual void SetVelocity(vector3d v); virtual void SetVelocity(vector3d v);
virtual vector3d GetVelocity(void); virtual vector3d GetVelocity(void);
vector3d GetAngVelocity(void);
void SetAngVelocity(vector3d v); void SetAngVelocity(vector3d v);
void SetMesh(ObjMesh* m); void SetMesh(ObjMesh* m);
virtual bool OnCollision(Body* b, Uint32 flags) { return true; } virtual bool OnCollision(Body* b, Uint32 flags) { return true; }

View File

@ -44,7 +44,7 @@ public:
static void Quit(void); static void Quit(void);
static float GetFrameTime(void) { return frameTime; } static float GetFrameTime(void) { return frameTime; }
static double GetGameTime(void) { return gameTime; } 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 GetTimeAccel(void) { return timeAccel; }
static float GetTimeStep(void) { return timeAccel*frameTime; } static float GetTimeStep(void) { return timeAccel*frameTime; }
static int GetScrWidth(void) { return scrWidth; } static int GetScrWidth(void) { return scrWidth; }

View File

@ -129,6 +129,18 @@ void L3D::Quit(void) {
exit(0); 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) { void L3D::SetCamType(enum CamType c) {
camType = c; camType = c;
mapView = MAP_NOMAP; mapView = MAP_NOMAP;

View File

@ -73,7 +73,7 @@ void Player::TimeStepUpdate(const float timeStep) {
} }
#define MOUSE_CTRL_AREA 10.0f #define MOUSE_CTRL_AREA 10.0f
#define MOUSE_RESTITUTION 0.01f #define MOUSE_RESTITUTION 0.75f
void Player::PollControls(void) { void Player::PollControls(void) {
int mouseMotion[2]; int mouseMotion[2];
@ -108,12 +108,11 @@ void Player::PollControls(void) {
vector3f angThrust(0.0f); vector3f angThrust(0.0f);
if(L3D::MouseButtonState(3)) { if(L3D::MouseButtonState(3)) {
float restitution = powf(MOUSE_RESTITUTION, L3D::GetTimeStep());
L3D::GetMouseMotion(mouseMotion); L3D::GetMouseMotion(mouseMotion);
m_mouseCMov[0] += mouseMotion[0]; m_mouseCMov[0] += mouseMotion[0];
m_mouseCMov[1] += mouseMotion[1]; m_mouseCMov[1] += mouseMotion[1];
m_mouseCMov[0] = CLAMP(m_mouseCMov[0]*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]*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.y = -m_mouseCMov[0] / MOUSE_CTRL_AREA;
angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA; angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA;
} }
@ -128,8 +127,6 @@ void Player::PollControls(void) {
if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1); if(L3D::KeyState(SDLK_SPACE) || (L3D::MouseButtonState(1) && L3D::MouseButtonState(1) && L3D::MouseButtonState(3))) SetGunState(0,1);
else SetGunState(0,0); 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::GetCamType() != L3D::CAM_EXTERNAL) {
if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1; if(L3D::KeyState(SDLK_LEFT)) angThrust.y += 1;
if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1; if(L3D::KeyState(SDLK_RIGHT)) angThrust.y += -1;
@ -137,14 +134,13 @@ void Player::PollControls(void) {
if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1; if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1;
} }
/* Rotation damping. */ /* Rotation damping. */
vector3d damping = CalcRotDamping(); vector3d damping = time_accel*CalcRotDamping();
angThrust.x -= damping.x; angThrust.x -= damping.x;
angThrust.y -= damping.y; angThrust.y -= damping.y;
angThrust.z -= damping.z; angThrust.z -= damping.z;
/* /* Dividing by time step so controls don't go insane when
* Dividing by time step so controls don't go insane when
* used at 10x accel. * used at 10x accel.
*/ */
angThrust *= 1.0f/ta2; angThrust *= 1.0f/ta2;
@ -152,10 +148,6 @@ void Player::PollControls(void) {
SetAngThrusterState(1, angThrust.y); SetAngThrusterState(1, angThrust.y);
SetAngThrusterState(2, angThrust.z); SetAngThrusterState(2, angThrust.z);
} }
if(time_accel > 10) {
dBodySetAngularVel(m_body, 0, 0, 0);
}
}
} }
#define HUD_CROSSHAIR_SIZE 24.0f #define HUD_CROSSHAIR_SIZE 24.0f

View File

@ -271,6 +271,7 @@ void Ship::SetDockedWith(SpaceStation* s, int port) {
m_dockedWith = s; m_dockedWith = s;
m_dockedWithPort = port; m_dockedWithPort = port;
m_dockingTimer = 0.0f; m_dockingTimer = 0.0f;
m_wheelState = 1.0f;
if(s->IsGroundStation()) m_flightState = LANDED; if(s->IsGroundStation()) m_flightState = LANDED;
SetVelocity(vector3d(0, 0, 0)); SetVelocity(vector3d(0, 0, 0));
SetAngVelocity(vector3d(0, 0, 0)); SetAngVelocity(vector3d(0, 0, 0));