Added documentation, and properly #ifdef'ed cushioning debug output.
This commit is contained in:
parent
12095d6fcd
commit
cdfdab7db3
42
src/physics/btKart.cpp
Executable file → Normal file
42
src/physics/btKart.cpp
Executable file → Normal file
@ -26,6 +26,10 @@
|
||||
#include "karts/kart.hpp"
|
||||
#include "karts/kart_model.hpp"
|
||||
#include "karts/kart_properties.hpp"
|
||||
#undef DEBUG_CUSHIONING
|
||||
#ifdef DEBUG_CUSHIONING
|
||||
#include "modes/world.hpp"
|
||||
#endif
|
||||
#include "physics/triangle_mesh.hpp"
|
||||
#include "tracks/terrain_info.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
@ -517,18 +521,20 @@ void btKart::updateVehicle( btScalar step )
|
||||
}
|
||||
}
|
||||
|
||||
// Cushioning test: if the kart
|
||||
// Cushioning test: if the kart is falling fast, the suspension might
|
||||
// not be strong enough to prevent the chassis from hitting the ground.
|
||||
// Try to detect this upcoming crash, and apply an upward impulse if
|
||||
// necessary that will slow down the falling speed.
|
||||
bool needed_cushioning = false;
|
||||
//const btVector3 &v = m_chassisBody->getLinearVelocity();
|
||||
btVector3 v =
|
||||
m_chassisBody->getVelocityInLocalPoint(m_wheelInfo[wheel_index].m_chassisConnectionPointCS);
|
||||
m_chassisBody->getVelocityInLocalPoint(m_wheelInfo[wheel_index]
|
||||
.m_chassisConnectionPointCS);
|
||||
btVector3 down = -m_chassisBody->getGravity();
|
||||
down.normalize();
|
||||
btVector3 v_down = (v * down) * down;
|
||||
btScalar offset=0.1f;
|
||||
|
||||
#ifdef DEBUG_CUSHIONING
|
||||
// If the downward speed is too fast to be caught by the suspension,
|
||||
// slow down the falling speed by applying an appropriately impulse:)
|
||||
Log::verbose("physics",
|
||||
"World %d wheel %d lsuspl %f vdown %f overall speed %f lenght %f",
|
||||
World::getWorld()->getTimeTicks(),
|
||||
@ -536,25 +542,34 @@ void btKart::updateVehicle( btScalar step )
|
||||
m_wheelInfo[wheel_index].m_raycastInfo.m_suspensionLength,
|
||||
-v_down.getY(),
|
||||
-v_down.getY() + 9.8*step,
|
||||
step * (-v_down.getY() + 9.8*step)+0.1f);
|
||||
step * (-v_down.getY() + 9.8*step)+offset);
|
||||
#endif
|
||||
// If the speed should be upwards, don't cushion (which would accelerate
|
||||
// the kart downward again).
|
||||
// If the kart is falling, estimate the distance the kart will fall
|
||||
// in the next time step: the speed gets increased by the gravity*dt.
|
||||
// This approximation is still not good enough (either because of
|
||||
// kart rotation that can be changed, or perhaps because of the
|
||||
// collision threshold used by bullet) - i.e. it would sometimes not
|
||||
// predict the upcoming collision correcty - so we add an offset
|
||||
// to the predicted kart movement, which was found experimentally:
|
||||
btScalar gravity = m_chassisBody->getGravity().length();
|
||||
if (v_down.getY()<0 &&
|
||||
m_wheelInfo[wheel_index].m_raycastInfo.m_suspensionLength
|
||||
< step * (-v_down.getY()+9.8*step)+0.1f)
|
||||
< step * (-v_down.getY()+gravity*step)+offset)
|
||||
{
|
||||
needed_cushioning = true;
|
||||
btVector3 impulse = down * (-v_down.getY() + 9.8f*step)
|
||||
btVector3 impulse = down * (-v_down.getY() + gravity*step)
|
||||
/ m_chassisBody->getInvMass();
|
||||
#ifdef DEBUG_CUSHIONING
|
||||
float v_old = m_chassisBody->getLinearVelocity().getY();
|
||||
#endif
|
||||
m_chassisBody->applyCentralImpulse(impulse);
|
||||
#ifdef DEBUG_CUSHIONING
|
||||
Log::verbose("physics",
|
||||
"World %d Cushioning imp %f vdown %f max_comp %f from %f m/s to %f m/s contact %f kart %f susp %f relspeed %f",
|
||||
"World %d Cushioning imp %f vdown %f from %f m/s to %f m/s "
|
||||
"contact %f kart %f susp %f relspeed %f",
|
||||
World::getWorld()->getTimeTicks(),
|
||||
impulse.getY(),
|
||||
-v_down.getY(), max_compensate_speed,
|
||||
-v_down.getY(),
|
||||
v_old,
|
||||
m_chassisBody->getLinearVelocity().getY(),
|
||||
m_wheelInfo[wheel_index].m_raycastInfo.m_isInContact ?
|
||||
@ -562,7 +577,8 @@ void btKart::updateVehicle( btScalar step )
|
||||
: -100,
|
||||
m_chassisBody->getWorldTransform().getOrigin().getY(),
|
||||
m_wheelInfo[wheel_index].m_raycastInfo.m_suspensionLength,
|
||||
m_chassisBody->getVelocityInLocalPoint(m_wheelInfo[wheel_index].m_chassisConnectionPointCS)
|
||||
m_chassisBody->getVelocityInLocalPoint(m_wheelInfo[wheel_index]
|
||||
.m_chassisConnectionPointCS)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user