[Change] Hack to deal with high ang velocity and long ode timesteps.

This commit is contained in:
Allanis 2018-01-13 16:02:59 +00:00
parent a66869c16f
commit c8a7e1ac94
5 changed files with 27 additions and 0 deletions

View File

@ -53,6 +53,19 @@ DynamicBody::~DynamicBody(void) {
dBodyDestroy(m_body);
}
void DynamicBody::TimeStepUpdate(const float timeStep) {
/*
* XXX Horrible hack.
* Prevent large ang velocities because ode hates them!
*/
const dReal* v = dBodyGetAngularVel(m_body);
vector3d vel;
vel.x = CLAMP(v[0], -50.0, 50.0);
vel.y = CLAMP(v[1], -50.0, 50.0);
vel.z = CLAMP(v[2], -50.0, 50.0);
dBodySetAngularVel(m_body, vel.x, vel.y, vel.z);
}
vector3d DynamicBody::GetVelocity(void) {
const dReal* v = dBodyGetLinearVel(m_body);
return vector3d(v[0], v[1], v[2]);

View File

@ -18,6 +18,7 @@ public:
virtual bool OnCollision(Body* b, Uint32 flags) { return true; }
vector3d GetAngularMomentum(void);
void SetMassDistributionFromCollMesh(const CollMesh* m);
virtual void TimeStepUpdate(const float timeStep);
virtual void Disable(void);
virtual void Enable(void);

View File

@ -153,6 +153,16 @@ void L3D::HandleEvents(void) {
switch(event.type) {
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_q) L3D::Quit();
#ifdef DEBUG
if(event.key.keysym.sym == SDLK_F12) {
/* Add test object. */
Ship* body = new Ship(ShipType::LADYBIRD);
body->SetLabel("A friend");
body->SetFrame(L3D::player->GetFrame());
body->SetPosition(L3D::player->GetPosition()+vector3d(0,0,-1000));
Space::AddBody(body);
}
#endif
if(event.key.keysym.sym == SDLK_F11) SDL_WM_ToggleFullScreen(L3D::scrSurface);
if(event.key.keysym.sym == SDLK_F10) L3D::SetView(L3D::objectViewerView);
L3D::keyState[event.key.keysym.sym] = 1;

View File

@ -101,6 +101,8 @@ void ModelBody::GetRotMatrix(matrix4x4d& m) {
}
void ModelBody::TransformToModelCoords(const Frame* camFrame) {
printf("ModelBody::TransformToMOdelCoords(): Warning! This becomes horribly",
"inaccurate if the Body is in the root frame, and a few AUs out.\n");
const vector3d pos = GetPosition();
const dReal* r = dGeomGetRotation(geoms[0]);
matrix4x4d m;

View File

@ -98,6 +98,7 @@ void Ship::CalcStats(shipstats_t* stats) {
}
void Ship::TimeStepUpdate(const float timeStep) {
DynamicBody::TimeStepUpdate(timeStep);
dockingTimer = (dockingTimer-timeStep > 0 ? dockingTimer-timeStep : 0);
/* ODE tri mesh likes to know our old position. */
TriMeshUpdateLastPos();