[Change] Allow ship rotation controls at high time accel.
[Change] Force gears down on docking.
This commit is contained in:
parent
5afece9c00
commit
2243d82e64
@ -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);
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -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; }
|
||||
|
12
src/main.cpp
12
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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user