[Fix] Stop player controls from going crazy when switched from world

view.
This commit is contained in:
Rtch90 2017-12-24 13:02:44 +00:00
parent cbd18023da
commit e67e7f12f2
7 changed files with 44 additions and 18 deletions

View File

@ -443,11 +443,11 @@ static void SphereBlobTess(vector3d& center, std::vector<vector3d>& edgeVerts) {
v2 = v3;
do { v3 = (v3 + 1)%s; } while(vDead[v3]);
}
if(++iters > 1000) { printf("Brokend %d(%d),%d(%d),%d(%d)!\n",v1,vDead[v1],v2,vDead[v2],v3,vDead[v3]); break; }
if(++iters > 1000) break;
} while((v1 != v2) && (v2 != v3) && (v3 != v1));
int notDead = 0;
for(unsigned int i = 0; i < vDead.size(); i++) if(!vDead[i]) notDead++;
printf("%d not dead (%d iters)\n", notDead, iters);
if(notDead > 2) printf("Strange sphere tesselator: %d not dead (%d iters)\n", notDead, iters);
}
static int exp2i(int foo) { int n = 2; while(--foo) n*=2; return n; }

View File

@ -57,6 +57,23 @@ void Player::ApplyExternalViewRotation(void) {
glRotatef(-m_external_view_roty, 0, 1, 0);
}
void Player::TimeStepUpdate(const float timeStep) {
/* When world view not selected. */
if(!polledControlsThisTurn) {
const float time_accel = L3D::GetTimeAccel();
const float ta2 = time_accel*time_accel;
ClearThrusterState();
/* Still must apply rotation damping. */
vector3d damping = CalcRotDamping();
damping *= 1.0f/ta2;
SetAngThrusterState(0, -damping.x);
SetAngThrusterState(1, -damping.y);
SetAngThrusterState(2, -damping.z);
}
polledControlsThisTurn = false;
Ship::TimeStepUpdate(timeStep);
}
#define MOUSE_CTRL_AREA 10.0f
#define MOUSE_RESTITUTION 0.01f
@ -65,9 +82,7 @@ void Player::PollControls(void) {
float time_accel = L3D::GetTimeAccel();
float ta2 = time_accel*time_accel;
SetAngThrusterState(0, 0.0f);
SetAngThrusterState(1, 0.0f);
SetAngThrusterState(2, 0.0f);
polledControlsThisTurn = true;
if(L3D::GetCamType() == L3D::CAM_EXTERNAL) {
if(L3D::KeyState(SDLK_UP)) m_external_view_rotx -= 1;
@ -83,6 +98,8 @@ void Player::PollControls(void) {
return;
}
ClearThrusterState();
vector3f angThrust(0.0f);
if(L3D::MouseButtonState(3)) {
@ -96,7 +113,6 @@ void Player::PollControls(void) {
angThrust.x = m_mouseCMov[1] / MOUSE_CTRL_AREA;
}
ClearThrusterState();
if(L3D::KeyState(SDLK_w)) SetThrusterState(ShipType::THRUSTER_REAR, 1.0f);
if(L3D::KeyState(SDLK_s)) SetThrusterState(ShipType::THRUSTER_FRONT, 1.0f);
if(L3D::KeyState(SDLK_2)) SetThrusterState(ShipType::THRUSTER_TOP, 1.0f);
@ -117,16 +133,11 @@ void Player::PollControls(void) {
if(L3D::KeyState(SDLK_DOWN)) angThrust.x += 1;
}
/* Rotation damping. */
const dReal* _av = dBodyGetAngularVel(m_body);
vector3d angVel(_av[0], _av[1], _av[2]);
matrix4x4d rot;
GetRotMatrix(rot);
angVel = rot.InverseOf() * angVel;
vector3d damping = CalcRotDamping();
angVel *= 0.6;
angThrust.x -= angVel.x;
angThrust.y -= angVel.y;
angThrust.z -= angVel.z;
angThrust.x -= damping.x;
angThrust.y -= damping.y;
angThrust.z -= damping.z;
/*
* Divided by time step so controls don't go totally insane when

View File

@ -12,11 +12,13 @@ public:
virtual void SetDockedWith(SpaceStation*);
vector3d GetExternalViewTranslation(void);
void ApplyExternalViewRotation(void);
void TimeStepUpdate(const float timeStep);
private:
void DrawTargetSquares();
void DrawTargetSquare(const Body* const target);
float m_mouseCMov[2];
float m_external_view_rotx, m_external_view_roty;
float m_external_view_dist;
bool polledControlsThisTurn;
};

View File

@ -53,11 +53,26 @@ void Ship::UpdateMass(void) {
dBodySetMass(m_body, &m_mass);
}
vector3d Ship::CalcRotDamping(void) {
/* Rotation damping. */
const dReal* _av = dBodyGetAngularVel(m_body);
vector3d angVel(_av[0], _av[1], _av[2]);
matrix4x4d rot;
GetRotMatrix(rot);
angVel = rot.InverseOf() * angVel;
return angVel * 0.6;
}
void Ship::SetThrusterState(enum ShipType::Thruster t, float level) {
m_thrusters[t] = level;
}
void Ship::ClearThrusterState(void) {
SetAngThrusterState(0, 0.0f);
SetAngThrusterState(1, 0.0f);
SetAngThrusterState(2, 0.0f);
for(int i = 0; i < ShipType::THRUSTER_MAX; i++) m_thrusters[i] = 0;
}
@ -153,7 +168,6 @@ void Ship::SetDockedWith(SpaceStation* s) {
m_dockedWith->GetRotMatrix(stationRot);
vector3d port_y = vector3d::Cross(-m_dockedWith->port.horiz, m_dockedWith->port.normal);
matrix4x4d rot = stationRot * matrix4x4d::MakeRotMatrix(m_dockedWith->port.horiz, port_y, m_dockedWith->port.normal);
rot.Print();
vector3d pos = m_dockedWith->GetPosition() + stationRot*m_dockedWith->port.center;
SetPosition(pos);
SetRotation(rot);

View File

@ -32,6 +32,7 @@ public:
const ShipType& GetShipType(void);
void CalcStats(shipstats_t* stats);
void UpdateMass(void);
vector3d CalcRotDamping();
void SetWheelState(bool down);
float GetDockingTimer(void) { return dockingTimer; }
void SetDockingTimer(float t) { dockingTimer = t; }

View File

@ -159,7 +159,6 @@ static bool _OnCollision(dGeomID g1, dGeomID g2, Object* o1, Object* o2,
flags |= static_cast<ModelBody::Geom*>(o2)->flags;
} else pb2 = static_cast<Body*>(o2);
printf("Collision flags %x\n", flags);
if((pb1 && !pb1->OnCollision(pb2, flags)) || (pb2 && !pb2->OnCollision(pb1, flags))) return false;
}
return true;

View File

@ -32,7 +32,6 @@ SpaceStationView::SpaceStationView(void) : View() {
}
void SpaceStationView::OnClickRequestLaunch(void) {
printf("Launching!\n");
L3D::player->SetDockedWith(0);
L3D::SetView(L3D::world_view);
}