First try to prevent #1566: kart chassis appears inside of terrain.

This commit is contained in:
hiker 2014-11-08 11:43:06 +11:00
parent 833f162d1a
commit 5401e7f3b7
4 changed files with 73 additions and 14 deletions

View File

@ -155,8 +155,15 @@
otherwise obstricts too much of the view. -->
<camera distance="1.0" forward-up-angle="15"
backward-up-angle="5"/>
<!-- Additional offset to move graphical chassis with regards to the physics. -->
<graphics y-offset="0.0"/>
<!-- Options to affect the graphical chassis:
y-offset: Additional offset to move graphical chassis with regards
to the physics, used to reduce frequencey of graphical
chassis in terrain.
prevent-chassis-in-terrain: a hard flag to prevent nearly all instances
of chassis in terrain. Can (atm) cause some stuttering. -->
<graphics y-offset="0.0"
prevent-chassis-in-terrain="true"
/>
<!-- Jump animation related values:
animation-time: only if the estimated time for a jump is larger

View File

@ -2581,6 +2581,45 @@ void Kart::updateGraphics(float dt, const Vec3& offset_xyz,
float xx = fabsf(m_speed)* getKartProperties()->getDownwardImpulseFactor()*0.0006f;
Vec3 center_shift = Vec3(0, m_skidding->getGraphicalJumpOffset()
+ lean_height +m_graphical_y_offset+xx, 0);
// Try to prevent the graphical chassis to be inside of the terrain:
if(m_kart_properties->getPreventChassisInTerrain())
{
// Get the shortest suspension length (=closest point to terrain).
float min_susp_len = 99.9f;
for (int i = 0; i < getVehicle()->getNumWheels(); i++)
{
float susp_len = getVehicle()->getWheelInfo(i).m_raycastInfo
.m_suspensionLength;
if (susp_len < min_susp_len)
min_susp_len = susp_len;
} // for i<num_wheels
const btWheelInfo &w = getVehicle()->getWheelInfo(0);
// Recompute the default average suspension length, see
// kartIsInRestNow() how to get from y-offset to susp. len.
float av_sus_len = -m_graphical_y_offset
+ w.m_chassisConnectionPointCS.getY()
- w.m_wheelsRadius;
float delta = av_sus_len - min_susp_len;
// If the suspension length is so short, that it is less than the
// lowest point of the kart, it indicates that the graphical chassis
// would be inside of the track:
if (delta > m_kart_model->getLowestPoint())
{
center_shift.setY(center_shift.getY() + delta - m_kart_model->getLowestPoint());
}
// FIXME: for now, debug output in case we have to debug it
//Log::verbose("kart", "min %f y off %f overall off %f lowest %f delta %f asl %f",
// min_susp_len, m_graphical_y_offset, center_shift.getY(),
// m_kart_model->getLowestPoint(),
// delta,
// av_sus_len
// );
}
center_shift = getTrans().getBasis() * center_shift;
Moveable::updateGraphics(dt, center_shift,

View File

@ -105,6 +105,7 @@ KartProperties::KartProperties(const std::string &filename)
m_gravity_center_shift = Vec3(UNDEFINED);
m_bevel_factor = Vec3(UNDEFINED);
m_exp_spring_response = false;
m_prevent_chassis_in_terrain = false;
m_version = 0;
m_color = video::SColor(255, 0, 0, 0);
m_shape = 32; // close enough to a circle.
@ -618,6 +619,8 @@ void KartProperties::getAllData(const XMLNode * root)
if(const XMLNode *graphics_node = root->getNode("graphics"))
{
graphics_node->get("y-offset", &m_graphical_y_offset);
graphics_node->get("prevent-chassis-in-terrain",
&m_prevent_chassis_in_terrain);
}
if(m_kart_model)

View File

@ -208,6 +208,9 @@ private:
* chassis. Useful for karts that don't have enough space for suspension
* compression. */
float m_graphical_y_offset;
/** A hard flag that moves the graphical chassis higher if it's insde
* the track. Might cause stuttering. */
bool m_prevent_chassis_in_terrain;
/** If the kart is supposed to have random wheel rotation at start. */
bool m_has_rand_wheels;
/** Max. length of plunger rubber band. */
@ -578,6 +581,13 @@ public:
* compression. */
float getGraphicalYOffset() const {return m_graphical_y_offset; }
// ------------------------------------------------------------------------
/** A hard flag that moves the graphical chassis higher if it's insde
* the track. Might cause stuttering. */
bool getPreventChassisInTerrain() const
{
return m_prevent_chassis_in_terrain;
} // getPreventChassisInTerrain
// ------------------------------------------------------------------------
/** Returns parameters for the speed-weighted objects */
const SpeedWeightedObject::Properties& getSpeedWeightedObjectProperties() const
{