Made the restitution settable for karts.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10409 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-12-12 10:40:09 +00:00
parent dde603030c
commit a69e94767e
11 changed files with 36 additions and 16 deletions

View File

@ -280,7 +280,8 @@
<!-- collision
impulse: an additional impulse to be applied in a non-frontal
collision to push two karts away from each other.
side-impulse is an additional (artificial) impulse that
resitution: restitution value to be used for the kart rigid bodies.
side-impulse: an additional (artificial) impulse that
pushes the slower kart out of the way of the faster karts (i.e.
sideways to the faster kart) when a collision happens. This is
for now disabled since it needs tuning and additionally has the
@ -288,7 +289,7 @@
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="0" side-impulse="0"/>
<collision impulse="0" restitution="0.5" side-impulse="0"/>
<!-- Kart-specific plunger and rubber band handling: max-length is
the maximum length of rubber band before it snaps. force is

View File

@ -49,6 +49,7 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, PowerupManager::POWERUP_BOWLING,
createPhysics(y_offset, btVector3(0.0f, 0.0f, m_speed*2),
new btSphereShape(0.5f*m_extend.getY()),
1.0f /*restitution*/,
-70.0f /*gravity*/,
true /*rotates*/);
// Even if the ball is fired backwards, m_speed must be positive,

View File

@ -87,7 +87,8 @@ Cake::Cake (Kart *kart) : Flyable(kart, PowerupManager::POWERUP_CAKE)
m_initial_velocity = Vec3(0.0f, up_velocity, m_speed);
createPhysics(forward_offset, m_initial_velocity,
new btCylinderShape(0.5f*m_extend), -m_gravity,
new btCylinderShape(0.5f*m_extend),
0.5f /* restitution */, -m_gravity,
true /* rotation */, false /* backwards */, &trans);
}
else
@ -100,7 +101,8 @@ Cake::Cake (Kart *kart) : Flyable(kart, PowerupManager::POWERUP_CAKE)
m_initial_velocity = Vec3(0.0f, up_velocity, m_speed);
createPhysics(forward_offset, m_initial_velocity,
new btCylinderShape(0.5f*m_extend), -m_gravity,
new btCylinderShape(0.5f*m_extend),
0.5f /* restitution */, -m_gravity,
true /* rotation */, backwards, &trans);
}

View File

@ -98,7 +98,8 @@ Flyable::Flyable(Kart *kart, PowerupManager::PowerupType type, float mass)
* otherwise the kart's heading will be used.
*/
void Flyable::createPhysics(float forw_offset, const Vec3 &velocity,
btCollisionShape *shape, const float gravity,
btCollisionShape *shape,
float restitution, const float gravity,
const bool rotates, const bool turn_around,
const btTransform* custom_direction)
{
@ -126,7 +127,7 @@ void Flyable::createPhysics(float forw_offset, const Vec3 &velocity,
trans *= offset_transform;
m_shape = shape;
createBody(m_mass, trans, m_shape);
createBody(m_mass, trans, m_shape, restitution);
m_user_pointer.set(this);
World::getWorld()->getPhysics()->addBody(getBody());

View File

@ -153,6 +153,7 @@ protected:
void createPhysics(float y_offset,
const Vec3 &velocity,
btCollisionShape *shape,
float restitution,
const float gravity=0.0f,
const bool rotates=false,
const bool turn_around=false,

View File

@ -76,14 +76,16 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, PowerupManager::POWERUP_PLUNGER)
m_initial_velocity = btVector3(0.0f, up_velocity, plunger_speed);
createPhysics(forward_offset, m_initial_velocity,
new btCylinderShape(0.5f*m_extend), gravity,
/* rotates */false , /*turn around*/false, &trans );
new btCylinderShape(0.5f*m_extend),
0.5f /* restitution */ , gravity,
/* rotates */false , /*turn around*/false, &trans);
}
else
{
createPhysics(forward_offset, btVector3(pitch, 0.0f, plunger_speed),
new btCylinderShape(0.5f*m_extend), gravity,
false /* rotates */, m_reverse_mode, &kart_transform );
new btCylinderShape(0.5f*m_extend),
0.5f /* restitution */, gravity,
false /* rotates */, m_reverse_mode, &kart_transform);
}
//adjust height according to terrain

View File

@ -261,7 +261,8 @@ void Kart::createPhysics()
// --------------------
btTransform trans;
trans.setIdentity();
createBody(mass, trans, &m_kart_chassis);
createBody(mass, trans, &m_kart_chassis,
m_kart_properties->getRestitution());
m_user_pointer.set(this);
m_body->setDamping(m_kart_properties->getChassisLinearDamping(),
m_kart_properties->getChassisAngularDamping() );

View File

@ -73,7 +73,7 @@ KartProperties::KartProperties(const std::string &filename)
m_chassis_angular_damping = m_suspension_rest =
m_max_speed_reverse_ratio =
m_rescue_vert_offset = m_upright_tolerance =
m_collision_side_impulse = m_collision_impulse =
m_collision_side_impulse = m_collision_impulse = m_restitution =
m_upright_max_force = m_suspension_travel_cm =
m_track_connection_accel =
m_rubber_band_max_length = m_rubber_band_force =
@ -429,6 +429,7 @@ void KartProperties::getAllData(const XMLNode * root)
{
collision_node->get("impulse", &m_collision_impulse );
collision_node->get("side-impulse", &m_collision_side_impulse);
collision_node->get("restitution", &m_restitution );
}
//TODO: wheel front right and wheel front left is not loaded, yet is listed as an attribute in the xml file after wheel-radius
@ -594,6 +595,7 @@ void KartProperties::checkAllSet(const std::string &filename)
CHECK_NEG(m_suspension_travel_cm, "suspension travel-cm" );
CHECK_NEG(m_max_suspension_force, "suspension max-force" );
CHECK_NEG(m_collision_impulse, "collision impulse" );
CHECK_NEG(m_restitution, "collision restitution" );
CHECK_NEG(m_collision_side_impulse, "collision side-impulse" );
CHECK_NEG(m_upright_tolerance, "upright tolerance" );
CHECK_NEG(m_upright_max_force, "upright max-force" );

View File

@ -257,6 +257,9 @@ private:
* side-side collision away from each other. */
float m_collision_impulse;
/** The restitution factor to be used in collsions for this kart. */
float m_restitution;
float m_upright_tolerance;
float m_upright_max_force;
@ -506,7 +509,10 @@ public:
/** Returns the (artificial) collision impulse this kart will apply
* to another kart in case of a non-frontal collision. */
float getCollisionImpulse () const {return m_collision_impulse;}
float getCollisionImpulse () const {return m_collision_impulse;}
/** Returns the restitution factor for this kart. */
float getRestitution () const { return m_restitution; }
/** Returns the vertical offset when rescuing karts to avoid karts being
* rescued in (or under) the track. */

View File

@ -141,7 +141,9 @@ void Moveable::update(float dt)
* \param shape Bullet collision shape for this object.
*/
void Moveable::createBody(float mass, btTransform& trans,
btCollisionShape *shape) {
btCollisionShape *shape,
float restitution)
{
btVector3 inertia;
shape->calculateLocalInertia(mass, inertia);
m_transform = trans;
@ -149,7 +151,7 @@ void Moveable::createBody(float mass, btTransform& trans,
btRigidBody::btRigidBodyConstructionInfo info(mass, m_motion_state,
shape, inertia);
info.m_restitution=0.5f;
info.m_restitution = restitution;
// Then create a rigid body
// ------------------------

View File

@ -105,7 +105,8 @@ public:
virtual void update(float dt) ;
btRigidBody *getBody() const {return m_body; }
void createBody(float mass, btTransform& trans,
btCollisionShape *shape);
btCollisionShape *shape,
float restitution);
const btTransform
&getTrans() const {return m_transform;}
void setTrans(const btTransform& t);