Allow tracks to set their friction (defaults to the bullet default 0f 0.5).

This commit is contained in:
hiker 2017-03-21 16:24:29 +11:00
parent 6ac6d9ebfe
commit 5bbacfc72d
4 changed files with 17 additions and 4 deletions

View File

@ -174,10 +174,13 @@ void TriangleMesh::createCollisionShape(bool create_collision_object, const char
* removed and all objects together with the track is converted again into
* a single rigid body. This avoids using irrlicht (or the graphics engine)
* for height of terrain detection).
* @param serializedBhv if non-NULL, the bhv is deserialized instead of
* \param friction Friction to be used for this TriangleMesh.
* \param flags Additional collision flags (default 0).
* \param serializedBhv if non-NULL, the bhv is deserialized instead of
* being calculated on the fly
*/
void TriangleMesh::createPhysicalBody(btCollisionObject::CollisionFlags flags,
void TriangleMesh::createPhysicalBody(float friction,
btCollisionObject::CollisionFlags flags,
const char* serializedBhv)
{
// We need the collision shape, but not the collision object (since
@ -189,6 +192,8 @@ void TriangleMesh::createPhysicalBody(btCollisionObject::CollisionFlags flags,
btRigidBody::btRigidBodyConstructionInfo info(0.0f, m_motion_state,
m_collision_shape);
info.m_restitution = 0.8f;
info.m_friction = friction;
m_body=new btRigidBody(info);
Physics::getInstance()->addBody(m_body);

View File

@ -57,7 +57,8 @@ public:
const btVector3 &n2, const btVector3 &n3,
const Material* m);
void createCollisionShape(bool create_collision_object=true, const char* serialized_bhv=NULL);
void createPhysicalBody(btCollisionObject::CollisionFlags flags=
void createPhysicalBody(float friction,
btCollisionObject::CollisionFlags flags=
(btCollisionObject::CollisionFlags)0,
const char* serializedBhv = NULL);
void removeAll();

View File

@ -480,6 +480,7 @@ void Track::loadTrackInfo()
m_fog_height_start = 0.0f;
m_fog_height_end = 100.0f;
m_gravity = 9.80665f;
m_friction = 0.5f;
m_smooth_normals = false;
m_godrays = false;
m_godrays_opacity = 1.0f;
@ -514,6 +515,7 @@ void Track::loadTrackInfo()
getMusicInformation(filenames, m_music);
root->get("screenshot", &m_screenshot);
root->get("gravity", &m_gravity);
root->get("friction", &m_friction);
root->get("soccer", &m_is_soccer);
root->get("arena", &m_is_arena);
root->get("max-arena-players", &m_max_arena_players);
@ -836,7 +838,7 @@ void Track::createPhysicsModel(unsigned int main_track_count)
{
convertTrackToBullet(m_all_nodes[i]);
}
m_track_mesh->createPhysicalBody();
m_track_mesh->createPhysicalBody(m_friction);
m_gfx_effect_mesh->createCollisionShape();
} // createPhysicsModel

View File

@ -104,7 +104,12 @@ private:
unsigned int m_magic_number;
#endif
/* Gravity to be used for this track. */
float m_gravity;
/** Friction to be used for the track. */
float m_friction;
std::string m_ident;
std::string m_screenshot;
bool m_is_day;