Added support for bevelled collision shapes using
a convex hull collision shape. Disabled by default, set bevel-factor in stk-config (e.g. to 0.3 0.3 0.3). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10466 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
2f89789c56
commit
13bca2e3d4
@ -291,9 +291,17 @@
|
||||
problem that the amount of push a hit kart receives depends on
|
||||
the orientation - if a kart is pushed in the direction it is
|
||||
driving, it will be more (no friction from tires), while when
|
||||
pushed to the side, hardly anything happens. -->
|
||||
<collision impulse="300" impulse-time="0.2" side-impulse="900"
|
||||
restitution="0.5"/>
|
||||
pushed to the side, hardly anything happens.
|
||||
bevel-factor: the X and Y coordinate of each point of the kart
|
||||
chassis (box) are multiplied with (1-bevelX) and (1-bevelY),
|
||||
and the Z coordinate is multiplied with (1+bevelZ). The
|
||||
resulting point is then added to the chassis collision shape.
|
||||
This gives a bevelled box shape. A value of 0 for all bevel
|
||||
coordinates disables bevelling, and uses a simple box shape.
|
||||
As an example, a value of 1 for x and z will result in a
|
||||
sharp 'arrow' like shape. -->
|
||||
<collision impulse="150" impulse-time="0.1" side-impulse="600"
|
||||
restitution="1.0" bevel-factor="0 0 0" />
|
||||
|
||||
<!-- Kart-specific plunger and rubber band handling: max-length is
|
||||
the maximum length of rubber band before it snaps. force is
|
||||
|
@ -242,10 +242,43 @@ void Kart::createPhysics()
|
||||
{
|
||||
kart_height = kart_length*0.6f;
|
||||
}
|
||||
|
||||
btBoxShape *shape = new btBoxShape(btVector3(0.5f*kart_width,
|
||||
0.5f*kart_height,
|
||||
0.5f*kart_length));
|
||||
|
||||
btCollisionShape *shape;
|
||||
const Vec3 &bevel = m_kart_properties->getBevelFactor();
|
||||
if(bevel.getX() || bevel.getY() || bevel.getZ())
|
||||
{
|
||||
Vec3 bevel_factor(1.0f-bevel.getX(),
|
||||
1.0f-bevel.getY(),
|
||||
1.0f+bevel.getZ() );
|
||||
btConvexHullShape *hull = new btConvexHullShape();
|
||||
for(int x=-1; x<=1; x+=2)
|
||||
{
|
||||
for(int y=-1; y<=1; y+=2)
|
||||
{
|
||||
for(int z=-1; z<=1; z+=2)
|
||||
{
|
||||
btVector3 p(x*getKartModel()->getWidth() *0.5f,
|
||||
y*getKartModel()->getHeight()*0.5f,
|
||||
z*getKartModel()->getLength()*0.5f);
|
||||
|
||||
hull->addPoint(p);
|
||||
p *= bevel_factor;
|
||||
hull->addPoint(p);
|
||||
} // for z
|
||||
} // for y
|
||||
} // for x
|
||||
|
||||
// This especially enables proper drawing of the point cloud
|
||||
hull->initializePolyhedralFeatures();
|
||||
shape = hull;
|
||||
} // bevel.getX()!=0
|
||||
else
|
||||
{
|
||||
shape = new btBoxShape(btVector3(0.5f*kart_width,
|
||||
0.5f*kart_height,
|
||||
0.5f*kart_length));
|
||||
}
|
||||
|
||||
btTransform shiftCenterOfGravity;
|
||||
shiftCenterOfGravity.setIdentity();
|
||||
// Shift center of gravity downwards, so that the kart
|
||||
|
@ -98,6 +98,7 @@ KartProperties::KartProperties(const std::string &filename)
|
||||
m_squash_duration = m_downward_impulse_factor = UNDEFINED;
|
||||
|
||||
m_gravity_center_shift = Vec3(UNDEFINED);
|
||||
m_bevel_factor = Vec3(UNDEFINED);
|
||||
m_exp_spring_response = false;
|
||||
m_has_skidmarks = true;
|
||||
m_version = 0;
|
||||
@ -432,6 +433,7 @@ void KartProperties::getAllData(const XMLNode * root)
|
||||
collision_node->get("impulse-time", &m_collision_impulse_time);
|
||||
collision_node->get("side-impulse", &m_collision_side_impulse);
|
||||
collision_node->get("restitution", &m_restitution );
|
||||
collision_node->get("bevel-factor", &m_bevel_factor );
|
||||
}
|
||||
|
||||
//TODO: wheel front right and wheel front left is not loaded, yet is listed as an attribute in the xml file after wheel-radius
|
||||
@ -600,6 +602,9 @@ void KartProperties::checkAllSet(const std::string &filename)
|
||||
CHECK_NEG(m_collision_impulse_time, "collision impulse-time" );
|
||||
CHECK_NEG(m_restitution, "collision restitution" );
|
||||
CHECK_NEG(m_collision_side_impulse, "collision side-impulse" );
|
||||
CHECK_NEG(m_bevel_factor.getX(), "collision bevel-factor" );
|
||||
CHECK_NEG(m_bevel_factor.getY(), "collision bevel-factor" );
|
||||
CHECK_NEG(m_bevel_factor.getZ(), "collision bevel-factor" );
|
||||
CHECK_NEG(m_upright_tolerance, "upright tolerance" );
|
||||
CHECK_NEG(m_upright_max_force, "upright max-force" );
|
||||
CHECK_NEG(m_plunger_in_face_duration[0],"plunger in-face-time[0]" );
|
||||
|
@ -125,7 +125,9 @@ private:
|
||||
/** Increase of turn angle with speed. */
|
||||
std::vector<float> m_speed_angle_increase;
|
||||
|
||||
|
||||
/** If != 0 a bevelled box shape is used by using a point cloud as a
|
||||
* collision shape. */
|
||||
Vec3 m_bevel_factor;
|
||||
|
||||
/** Time a kart is moved upwards after when it is rescued. */
|
||||
float m_rescue_time;
|
||||
@ -181,7 +183,7 @@ private:
|
||||
float m_wheel_base;
|
||||
/** Nitro power boost. */
|
||||
float m_nitro_power_boost;
|
||||
/**< Nitro consumption. */
|
||||
/** Nitro consumption. */
|
||||
float m_nitro_consumption;
|
||||
/** Nitro amount for small bottle. */
|
||||
float m_nitro_small_container;
|
||||
@ -693,6 +695,9 @@ public:
|
||||
float getSquashSlowdown() const {return m_squash_slowdown; }
|
||||
|
||||
bool hasRandomWheels() const { return m_has_rand_wheels; }
|
||||
|
||||
/** Returns the bevel factor (!=0 indicates to use a bevelled box). */
|
||||
const Vec3 &getBevelFactor() const { return m_bevel_factor; }
|
||||
}; // KartProperties
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user