SuperTuxKart
|
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 Material * | getMaterial (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. | |
A special class to store a triangle mesh with a separate material per triangle.
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.
t1,t2,t3 | Points of the triangle. |
n1,n2,n3 | Normals at the corresponding points. |
m | Material used for this triangle |
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.
from/to | The from and to position for the raycast. |
xyz | The position in world where the ray hit. |
material | The material of the mesh that was hit. |
normal | The intrapolated normal at that position. |
interpolate_normal | If 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). |
A special ray result class that stores the index of the triangle that was hit.
Stores the index of the triangle that was hit.
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.
serialized_bhv | if non-null, load the serialized bhv from file instead of builing it on the fly |
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).
friction | Friction to be used for this TriangleMesh. |
flags | Additional collision flags (default 0). |
serializedBhv | if non-NULL, the bhv is deserialized instead of being calculated on the fly |
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.
index | Index of the triangle to use. |
position | The position for which to interpolate the normal. |
|
inline |
Returns the normals of the triangle with the given index.
indx | Index of the triangle to get the three normals of. |
|
inline |
Returns the points of the 'indx' triangle.
indx | Index of the triangle to get. |
p1,p2,p3 | On return the three points of the triangle. |
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.
|
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).