Move updatePhysics after material raycast updated

This commit is contained in:
Benau 2018-10-17 14:26:22 +08:00
parent d87cd364db
commit 76602ac65a

View File

@ -1490,24 +1490,47 @@ void Kart::update(int ticks)
m_attachment->update(ticks);
PROFILER_PUSH_CPU_MARKER("Kart::updatePhysics", 0x60, 0x34, 0x7F);
updatePhysics(ticks);
PROFILER_POP_CPU_MARKER();
if(!m_controls.getFire()) m_fire_clicked = 0;
if(m_controls.getFire() && !m_fire_clicked && !m_kart_animation)
// Make sure that the ray doesn't hit the kart. This is done by
// resetting the collision filter group, so that this collision
// object is ignored during raycasting.
short int old_group = 0;
if (m_body->getBroadphaseHandle())
{
if (m_powerup->getType() != PowerupManager::POWERUP_NOTHING)
{
setLastUsedPowerup(m_powerup->getType());
}
// use() needs to be called even if there currently is no collecteable
// since use() can test if something needs to be switched on/off.
m_powerup->use() ;
World::getWorld()->onFirePressed(getController());
m_fire_clicked = 1;
old_group = m_body->getBroadphaseHandle()->m_collisionFilterGroup;
m_body->getBroadphaseHandle()->m_collisionFilterGroup = 0;
}
// After the physics step was done, the position of the wheels (as stored
// in wheelInfo) is actually outdated, since the chassis was moved
// according to the force acting from the wheels. So the center of the
// chassis is not at the center of the wheels anymore, it is somewhat
// moved forward (depending on speed and fps). In very extreme cases
// (see bug 2246) the center of the chassis can actually be ahead of the
// front wheels. So if we do a raycast to detect the terrain from the
// current chassis, that raycast might be ahead of the wheels - which
// results in incorrect rescues (the wheels are still on the ground,
// but the raycast happens ahead of the front wheels and are over
// a rescue texture).
// To avoid this problem, we do the raycast for terrain detection from
// the center of the 4 wheel positions (in world coordinates).
Vec3 from(0.0f, 0.0f, 0.0f);
for (unsigned int i = 0; i < 4; i++)
from += m_vehicle->getWheelInfo(i).m_raycastInfo.m_hardPointWS;
// Add a certain epsilon (0.3) to the height of the kart. This avoids
// problems of the ray being cast from under the track (which happened
// e.g. on tux tollway when jumping down from the ramp, when the chassis
// partly tunnels through the track). While tunneling should not be
// happening (since Z velocity is clamped), the epsilon is left in place
// just to be on the safe side (it will not hit the chassis itself).
from = from/4 + (getTrans().getBasis() * Vec3(0.0f, 0.3f, 0.0f));
m_terrain_info->update(getTrans().getBasis(), from);
if (m_body->getBroadphaseHandle())
{
m_body->getBroadphaseHandle()->m_collisionFilterGroup = old_group;
}
// Check if a kart is (nearly) upside down and not moving much -->
@ -1543,15 +1566,26 @@ void Kart::update(int ticks)
}
}
// Make sure that the ray doesn't hit the kart. This is done by
// resetting the collision filter group, so that this collision
// object is ignored during raycasting.
short int old_group = 0;
if(m_body->getBroadphaseHandle())
// Update physics from newly updated material
PROFILER_PUSH_CPU_MARKER("Kart::updatePhysics", 0x60, 0x34, 0x7F);
updatePhysics(ticks);
PROFILER_POP_CPU_MARKER();
if(!m_controls.getFire()) m_fire_clicked = 0;
if(m_controls.getFire() && !m_fire_clicked && !m_kart_animation)
{
old_group = m_body->getBroadphaseHandle()->m_collisionFilterGroup;
m_body->getBroadphaseHandle()->m_collisionFilterGroup = 0;
if (m_powerup->getType() != PowerupManager::POWERUP_NOTHING)
{
setLastUsedPowerup(m_powerup->getType());
}
// use() needs to be called even if there currently is no collecteable
// since use() can test if something needs to be switched on/off.
m_powerup->use() ;
World::getWorld()->onFirePressed(getController());
m_fire_clicked = 1;
}
#undef XX
#ifdef XX
Log::verbose("physicsafter", "%s t %f %d xyz(9-11) %f %f %f %f %f %f "
@ -1583,38 +1617,6 @@ void Kart::update(int ticks)
m_bubblegum_torque // 47
);
#endif
// After the physics step was done, the position of the wheels (as stored
// in wheelInfo) is actually outdated, since the chassis was moved
// according to the force acting from the wheels. So the center of the
// chassis is not at the center of the wheels anymore, it is somewhat
// moved forward (depending on speed and fps). In very extreme cases
// (see bug 2246) the center of the chassis can actually be ahead of the
// front wheels. So if we do a raycast to detect the terrain from the
// current chassis, that raycast might be ahead of the wheels - which
// results in incorrect rescues (the wheels are still on the ground,
// but the raycast happens ahead of the front wheels and are over
// a rescue texture).
// To avoid this problem, we do the raycast for terrain detection from
// the center of the 4 wheel positions (in world coordinates).
Vec3 from(0, 0, 0);
for (unsigned int i = 0; i < 4; i++)
from += m_vehicle->getWheelInfo(i).m_raycastInfo.m_hardPointWS;
// Add a certain epsilon (0.3) to the height of the kart. This avoids
// problems of the ray being cast from under the track (which happened
// e.g. on tux tollway when jumping down from the ramp, when the chassis
// partly tunnels through the track). While tunneling should not be
// happening (since Z velocity is clamped), the epsilon is left in place
// just to be on the safe side (it will not hit the chassis itself).
from = from/4 + (getTrans().getBasis() * Vec3(0,0.3f,0));
m_terrain_info->update(getTrans().getBasis(), from);
if(m_body->getBroadphaseHandle())
{
m_body->getBroadphaseHandle()->m_collisionFilterGroup = old_group;
}
PROFILER_PUSH_CPU_MARKER("Kart::Update (material)", 0x60, 0x34, 0x7F);
const Material* material=m_terrain_info->getMaterial();