SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Attributes | List of all members
TriangleMesh Class Reference

A special class to store a triangle mesh with a separate material per triangle. More...

#include <triangle_mesh.hpp>

Classes

class  RigidBodyTriangleMesh
 

Public Member Functions

 TriangleMesh (bool can_be_transformed)
 Constructor: Initialises all data structures with zero.
 
 ~TriangleMesh ()
 Destructor: delete all allocated data structures.
 
void addTriangle (const btVector3 &t1, const btVector3 &t2, const btVector3 &t3, const btVector3 &n1, const btVector3 &n2, const btVector3 &n3, const Material *m)
 Adds a triangle to the bullet mesh.
 
void createCollisionShape (bool create_collision_object=true, const char *serialized_bhv=NULL)
 Creates a collision body only, which can be used for raycasting, but has no physical properties.
 
void createPhysicalBody (float friction, btCollisionObject::CollisionFlags flags=(btCollisionObject::CollisionFlags) 0, const char *serializedBhv=NULL)
 Creates the physics body for this triangle mesh.
 
void removeAll ()
 Removes the created body and/or collision object from the physics world.
 
void removeCollisionObject ()
 
btVector3 getInterpolatedNormal (unsigned int index, const btVector3 &position) const
 Interpolates the normal at the given position for the triangle with a given index.
 
void setBody (btRigidBody *body)
 In case of physical objects of shape 'exact', the physical body is created outside of the mesh.
 
const btRigidBody * getBody () const
 
const MaterialgetMaterial (int n) const
 
const btCollisionShape & getCollisionShape () const
 
btCollisionShape & getCollisionShape ()
 
bool castRay (const btVector3 &from, const btVector3 &to, btVector3 *xyz, const Material **material, btVector3 *normal=NULL, bool interpolate_normal=false) const
 Casts a ray from 'from' to 'to'.
 
void getTriangle (unsigned int indx, btVector3 *p1, btVector3 *p2, btVector3 *p3) const
 Returns the points of the 'indx' triangle.
 
void getNormals (unsigned int indx, btVector3 *n1, btVector3 *n2, btVector3 *n3) const
 Returns the normals of the triangle with the given index.
 
float getP1P2P3 (unsigned int indx) const
 Returns basically the area of the triangle, which is needed when smoothing the normals.
 
void copyFrom (const TriangleMesh &tm)
 

Private Attributes

UserPointer m_user_pointer
 
std::vector< const Material * > m_triangleIndex2Material
 
btRigidBody * m_body
 
bool m_free_body
 Keep track if the physical body was created here or not.
 
btCollisionObject * m_collision_object
 
btTriangleMesh m_mesh
 
btVector3 dummy1
 
btVector3 dummy2
 
btDefaultMotionState * m_motion_state
 
btCollisionShape * m_collision_shape
 
AlignedArray< btVector3 > m_normals
 The three normals for each triangle.
 
AlignedArray< float > m_p1p2p3
 Pre-compute value used in smoothing.
 
bool m_can_be_transformed
 If the rigid body can be transformed (which means that normalising the normals need to update the vertices and normals used according to the current transform of the body.
 

Detailed Description

A special class to store a triangle mesh with a separate material per triangle.

Member Function Documentation

◆ addTriangle()

void TriangleMesh::addTriangle ( const btVector3 &  t1,
const btVector3 &  t2,
const btVector3 &  t3,
const btVector3 &  n1,
const btVector3 &  n2,
const btVector3 &  n3,
const Material m 
)

Adds a triangle to the bullet mesh.

It also stores the material used for this triangle, and the three normals.

Parameters
t1,t2,t3Points of the triangle.
n1,n2,n3Normals at the corresponding points.
mMaterial used for this triangle

◆ castRay()

bool TriangleMesh::castRay ( const btVector3 &  from,
const btVector3 &  to,
btVector3 *  xyz,
const Material **  material,
btVector3 *  normal = NULL,
bool  interpolate_normal = false 
) const

Casts a ray from 'from' to 'to'.

If a triangle of this mesh was hit, xyz and material will be set.

Parameters
from/toThe from and to position for the raycast.
xyzThe position in world where the ray hit.
materialThe material of the mesh that was hit.
normalThe intrapolated normal at that position.
interpolate_normalIf true, the returned normal is the interpolated based on the three normals of the triangle and the location of the hit point (which is more compute intensive, but results in much smoother results).
Returns
True if a triangle was hit, false otherwise (and no output variable will be set.

A special ray result class that stores the index of the triangle that was hit.

Stores the index of the triangle that was hit.

◆ createCollisionShape()

void TriangleMesh::createCollisionShape ( bool  create_collision_object = true,
const char *  serialized_bhv = NULL 
)

Creates a collision body only, which can be used for raycasting, but has no physical properties.

Parameters
serialized_bhvif non-null, load the serialized bhv from file instead of builing it on the fly

◆ createPhysicalBody()

void TriangleMesh::createPhysicalBody ( float  friction,
btCollisionObject::CollisionFlags  flags = (btCollisionObject::CollisionFlags)0,
const char *  serializedBhv = NULL 
)

Creates the physics body for this triangle mesh.

If the body already exists (because it was created by a previous call to createBody) it is first removed from the world. This is used by loading the track where a physics body is used to determine the height of terrain. To have an optimised rigid body including all static objects, the track is then 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).

Parameters
frictionFriction to be used for this TriangleMesh.
flagsAdditional collision flags (default 0).
serializedBhvif non-NULL, the bhv is deserialized instead of being calculated on the fly

◆ getInterpolatedNormal()

btVector3 TriangleMesh::getInterpolatedNormal ( unsigned int  index,
const btVector3 &  position 
) const

Interpolates the normal at the given position for the triangle with a given index.

The position must be inside of the given triangle.

Parameters
indexIndex of the triangle to use.
positionThe position for which to interpolate the normal.

◆ getNormals()

void TriangleMesh::getNormals ( unsigned int  indx,
btVector3 *  n1,
btVector3 *  n2,
btVector3 *  n3 
) const
inline

Returns the normals of the triangle with the given index.

Parameters
indxIndex of the triangle to get the three normals of.
Returns
n1,n2,n3 The three normals.

◆ getTriangle()

void TriangleMesh::getTriangle ( unsigned int  indx,
btVector3 *  p1,
btVector3 *  p2,
btVector3 *  p3 
) const
inline

Returns the points of the 'indx' triangle.

Parameters
indxIndex of the triangle to get.
p1,p2,p3On return the three points of the triangle.

◆ removeAll()

void TriangleMesh::removeAll ( )

Removes the created body and/or collision object from the physics world.

This is used when creating a temporary rigid body of the main track to get bullet raycasts. Then the main track is removed, and the track (main track including all additional objects which were loaded later) is converted again.

◆ setBody()

void TriangleMesh::setBody ( btRigidBody *  body)
inline

In case of physical objects of shape 'exact', the physical body is created outside of the mesh.

Since raycasts need the body's world transform, the body can be set using this function. This will also cause the body not to be freed (since it will be freed as part of the physical object).


The documentation for this class was generated from the following files: