[Change] Hack to deal with high ang velocity and long ode timesteps.
This commit is contained in:
		
							parent
							
								
									054630982c
								
							
						
					
					
						commit
						65b737bfba
					
				@ -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]);
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/main.cpp
									
									
									
									
									
								
							@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user