[Add] More landing constraints.
[Fix?] Correct wheel behaviour when landed.
This commit is contained in:
parent
ff11777564
commit
d89e39e1c0
53
src/ship.cpp
53
src/ship.cpp
@ -29,7 +29,7 @@ Ship::Ship(ShipType::Type shipType) : DynamicBody() {
|
|||||||
m_wheelTransition = 0;
|
m_wheelTransition = 0;
|
||||||
m_wheelState = 0;
|
m_wheelState = 0;
|
||||||
m_dockedWith = 0;
|
m_dockedWith = 0;
|
||||||
dockingTimer = 0;
|
m_dockingTimer = 0;
|
||||||
m_navTarget = 0;
|
m_navTarget = 0;
|
||||||
m_combatTarget = 0;
|
m_combatTarget = 0;
|
||||||
m_shipType = shipType;
|
m_shipType = shipType;
|
||||||
@ -139,38 +139,45 @@ void Ship::TestLanded(void) {
|
|||||||
const double planetRadius = GetFrame()->m_astroBody->GetRadius();
|
const double planetRadius = GetFrame()->m_astroBody->GetRadius();
|
||||||
|
|
||||||
if(speed < 20) {
|
if(speed < 20) {
|
||||||
printf("Landed!\n");
|
/* Orient the damn thing right!
|
||||||
|
* Why is the inverse of the body rot matrix being used?!?!
|
||||||
/* Orient the damn thing right! */
|
* *shrugs* it just works this way.
|
||||||
|
*/
|
||||||
matrix4x4d rot;
|
matrix4x4d rot;
|
||||||
GetRotMatrix(rot);
|
GetRotMatrix(rot);
|
||||||
|
matrix4x4d invRot = rot.InverseOf();
|
||||||
|
|
||||||
vector3d up = vector3d::Normalize(GetPosition());
|
vector3d up = vector3d::Normalize(GetPosition());
|
||||||
|
|
||||||
/* Position at zero altitude. */
|
/* Check player is sortof sensibly oriented for landing. */
|
||||||
SetPosition(up * planetRadius);
|
const double dot = vector3d::Dot(vector3d::Normalize(vector3d(invRot[1], invRot[5], invRot[9])), up);
|
||||||
|
if(dot > 0.99) {
|
||||||
|
/* Position at zero altitude. */
|
||||||
|
SetPosition(up * planetRadius);
|
||||||
|
|
||||||
vector3d forward = rot * vector3d(0, 0, 1);
|
vector3d forward = rot * vector3d(0,0,1);
|
||||||
vector3d other = vector3d::Normalize(vector3d::Cross(up, forward));
|
vector3d other = vector3d::Normalize(vector3d::Cross(up, forward));
|
||||||
|
forward = vector3d::Cross(other, up);
|
||||||
|
|
||||||
rot = matrix4x4d::MakeRotMatrix(other, up, forward);
|
rot = matrix4x4d::MakeRotMatrix(other, up, forward);
|
||||||
rot = rot.InverseOf();
|
rot = rot.InverseOf();
|
||||||
SetRotMatrix(rot);
|
SetRotMatrix(rot);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We don'tuse DynamicBody::Disable because that also disables the geom
|
* We don't use DynamicBody::Disable because that also disables
|
||||||
* and that must still get collisions.
|
* the geom, and that must still get collisions.
|
||||||
*/
|
*/
|
||||||
dBodyDisable(m_body);
|
dBodyDisable(m_body);
|
||||||
ClearThrusterState();
|
ClearThrusterState();
|
||||||
m_flightState = LANDED;
|
m_flightState = LANDED;
|
||||||
m_testLanded = false;
|
m_testLanded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ship::TimeStepUpdate(const float timeStep) {
|
void Ship::TimeStepUpdate(const float timeStep) {
|
||||||
dockingTimer = (dockingTimer-timeStep > 0 ? dockingTimer-timeStep : 0);
|
m_dockingTimer = (m_dockingTimer-timeStep > 0 ? m_dockingTimer-timeStep : 0);
|
||||||
/* ODE tri mesh likes to know our old position. */
|
/* ODE tri mesh likes to know our old position. */
|
||||||
TriMeshUpdateLastPos();
|
TriMeshUpdateLastPos();
|
||||||
|
|
||||||
@ -255,7 +262,7 @@ void Ship::SetDockedWith(SpaceStation* s) {
|
|||||||
m_dockedWith = 0;
|
m_dockedWith = 0;
|
||||||
} else {
|
} else {
|
||||||
m_dockedWith = s;
|
m_dockedWith = s;
|
||||||
dockingTimer = 0.0f;
|
m_dockingTimer = 0.0f;
|
||||||
SetVelocity(vector3d(0, 0, 0));
|
SetVelocity(vector3d(0, 0, 0));
|
||||||
SetAngVelocity(vector3d(0, 0, 0));
|
SetAngVelocity(vector3d(0, 0, 0));
|
||||||
Disable();
|
Disable();
|
||||||
@ -266,9 +273,11 @@ void Ship::SetGunState(int idx, int state) {
|
|||||||
m_gunState[idx] = state;
|
m_gunState[idx] = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ship::SetWheelState(bool down) {
|
bool Ship::SetWheelState(bool down) {
|
||||||
|
if(m_flightState != FLYING) return false;
|
||||||
if(down) m_wheelTransition = 1;
|
if(down) m_wheelTransition = 1;
|
||||||
else m_wheelTransition = -1;
|
else m_wheelTransition = -1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ship::SetNavTarget(Body* const target) {
|
void Ship::SetNavTarget(Body* const target) {
|
||||||
|
@ -33,10 +33,10 @@ public:
|
|||||||
void CalcStats(shipstats_t* stats);
|
void CalcStats(shipstats_t* stats);
|
||||||
void UpdateMass(void);
|
void UpdateMass(void);
|
||||||
vector3d CalcRotDamping();
|
vector3d CalcRotDamping();
|
||||||
void SetWheelState(bool down);
|
bool SetWheelState(bool down); /* Returns success of state change, NOT state itself. */
|
||||||
void Blastoff(void);
|
void Blastoff(void);
|
||||||
float GetDockingTimer(void) { return dockingTimer; }
|
float GetDockingTimer(void) { return m_dockingTimer; }
|
||||||
void SetDockingTimer(float t) { dockingTimer = t; }
|
void SetDockingTimer(float t) { m_dockingTimer = t; }
|
||||||
virtual void TimeStepUpdate(const float timeStep);
|
virtual void TimeStepUpdate(const float timeStep);
|
||||||
virtual void NotifyDeath(const Body* const dyingBody);
|
virtual void NotifyDeath(const Body* const dyingBody);
|
||||||
virtual bool OnCollision(Body* b, Uint32 flags);
|
virtual bool OnCollision(Body* b, Uint32 flags);
|
||||||
@ -68,7 +68,7 @@ private:
|
|||||||
|
|
||||||
float m_thrusters[ShipType::THRUSTER_MAX];
|
float m_thrusters[ShipType::THRUSTER_MAX];
|
||||||
float m_angThrusters[3];
|
float m_angThrusters[3];
|
||||||
float dockingTimer;
|
float m_dockingTimer;
|
||||||
dGeomID m_tempLaserGeom[ShipType::GUNMOUNT_MAX];
|
dGeomID m_tempLaserGeom[ShipType::GUNMOUNT_MAX];
|
||||||
|
|
||||||
LaserObj m_laserCollisionObj;
|
LaserObj m_laserCollisionObj;
|
||||||
|
@ -72,7 +72,9 @@ WorldView::WorldView(void): View() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldView::OnChangeWheelsState(Gui::MultiStateImageButton* b) {
|
void WorldView::OnChangeWheelsState(Gui::MultiStateImageButton* b) {
|
||||||
L3D::player->SetWheelState(b->GetState());
|
if(!L3D::player->SetWheelState(b->GetState())) {
|
||||||
|
b->StatePrev();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldView::OnChangeLabelsState(Gui::MultiStateImageButton* b) {
|
void WorldView::OnChangeLabelsState(Gui::MultiStateImageButton* b) {
|
||||||
|
Loading…
Reference in New Issue
Block a user