📄 gim_trimesh.h
字号:
//! Trimesh Trimesh Collisions
/*!
Before use this function you must update each trimesh:
\code
gim_trimesh_update(TriMesh1);
gim_trimesh_update(TriMesh2);
\endcode
Then you must use the trimesh collision in this way:
\code
int collide_trimeshes(GIM_TRIMESH * TriMesh1, GIM_TRIMESH * TriMesh2)
{
//Create contact list
GDYNAMIC_ARRAY trimeshcontacts;
GIM_CREATE_CONTACT_LIST(trimeshcontacts);
//Collide trimeshes
gim_trimesh_trimesh_collision(TriMesh1,TriMesh2,&trimeshcontacts);
if(trimeshcontacts.m_size == 0) //do nothing
{
GIM_DYNARRAY_DESTROY(trimeshcontacts);//clean contact array
return 0;
}
//Getting a pointer to the contact array
GIM_CONTACT * ptrimeshcontacts = GIM_DYNARRAY_POINTER(GIM_CONTACT,trimeshcontacts);
int contactcount = trimeshcontacts.m_size;
int i;
//Process contacts
for (i=0;i<contactcount ;i++)
{
//Do something with the contact (ptrimeshcontacts)
......
......
// Like creating joints or anything else
......
......
ptrimeshcontacts++;
}
GIM_DYNARRAY_DESTROY(trimeshcontacts);
return contactcount;
}
\endcode
In each contact
<ul>
<li> m_handle1 points to trimesh1.
<li> m_handle2 points to trimesh2.
<li> m_feature1 Is a triangle index of trimesh1.
<li> m_feature2 Is a triangle index of trimesh2.
</ul>
\param trimesh1 Collider
\param trimesh2 Collidee
\param contacts A GIM_CONTACT array. Must be initialized
*/
void gim_trimesh_trimesh_collision(GIM_TRIMESH * trimesh1, GIM_TRIMESH * trimesh2, GDYNAMIC_ARRAY * contacts);
//! Trimesh Sphere Collisions
/*!
Before use this function you must update the trimesh:
\code
gim_trimesh_update(trimesh);
\endcode
Then you must use this function in this way:
\code
int collide_trimesh_sphere(GIM_TRIMESH * trimesh, vec3f center,GREAL radius)
{
//Create contact list
GDYNAMIC_ARRAY trimeshcontacts;
GIM_CREATE_CONTACT_LIST(trimeshcontacts);
//Collide trimeshes
gim_trimesh_sphere_collision(trimesh,center,radius,&trimeshcontacts);
if(trimeshcontacts.m_size == 0) //do nothing
{
GIM_DYNARRAY_DESTROY(trimeshcontacts);//clean contact array
return 0;
}
//Getting a pointer to the contact array
GIM_CONTACT * ptrimeshcontacts = GIM_DYNARRAY_POINTER(GIM_CONTACT,trimeshcontacts);
int contactcount = trimeshcontacts.m_size;
int i;
//Process contacts
for (i=0;i<contactcount ;i++)
{
//Do something with the contact (ptrimeshcontacts)
......
......
// Like creating joints or anything else
......
......
ptrimeshcontacts++;
}
GIM_DYNARRAY_DESTROY(trimeshcontacts);
return contactcount;
}
\endcode
In each contact
<ul>
<li> m_handle1 points to trimesh.
<li> m_handle2 points to NULL.
<li> m_feature1 Is a triangle index of trimesh.
</ul>
\param trimesh
\param center
\param radius
\param contacts A GIM_CONTACT array. Must be initialized
*/
void gim_trimesh_sphere_collision(GIM_TRIMESH * trimesh,vec3f center,GREAL radius, GDYNAMIC_ARRAY * contacts);
//! Trimesh Capsule collision
/*!
Find the closest primitive collided by the ray.
Before use this function you must update the trimesh:
\code
gim_trimesh_update(trimesh);
\endcode
Then you must use this function in this way:
\code
int collide_trimesh_capsule(GIM_TRIMESH * trimesh, GIM_CAPSULE_DATA * capsule)
{
//Create contact list
GDYNAMIC_ARRAY trimeshcontacts;
GIM_CREATE_CONTACT_LIST(trimeshcontacts);
//Collide trimeshes
gim_trimesh_capsule_collision(trimesh,capsule,&trimeshcontacts);
if(trimeshcontacts.m_size == 0) //do nothing
{
GIM_DYNARRAY_DESTROY(trimeshcontacts);//clean contact array
return 0;
}
//Getting a pointer to the contact array
GIM_CONTACT * ptrimeshcontacts = GIM_DYNARRAY_POINTER(GIM_CONTACT,trimeshcontacts);
int contactcount = trimeshcontacts.m_size;
int i;
//Process contacts
for (i=0;i<contactcount ;i++)
{
//Do something with the contact (ptrimeshcontacts)
......
......
// Like creating joints or anything else
......
......
ptrimeshcontacts++;
}
GIM_DYNARRAY_DESTROY(trimeshcontacts);
return contactcount;
}
\endcode
In each contact
<ul>
<li> m_handle1 points to trimesh.
<li> m_handle2 points to NULL.
<li> m_feature1 Is a triangle index of trimesh.
</ul>
\param trimesh
\param capsule
\param contacts A GIM_CONTACT array. Must be initialized
*/
void gim_trimesh_capsule_collision(GIM_TRIMESH * trimesh, GIM_CAPSULE_DATA * capsule, GDYNAMIC_ARRAY * contacts);
///Function for create Trimesh Plane collision result
#define GIM_CREATE_TRIMESHPLANE_CONTACTS(dynarray) GIM_DYNARRAY_CREATE(vec4f,dynarray,G_ARRAY_GROW_SIZE)
//! Trimesh Plane Collisions
/*!
Before use this function you must update the trimesh:
\code
gim_trimesh_update(trimesh);
\endcode
Then you must use this function in this way:
\code
int collide_trimesh_plane(GIM_TRIMESH * trimesh, vec4f plane)
{
//Create contact list
GDYNAMIC_ARRAY tri_plane_contacts;
GIM_CREATE_TRIMESHPLANE_CONTACTS(tri_plane_contacts);
//Collide trimeshes
gim_trimesh_plane_collision(trimesh,plane,&tri_plane_contacts);
if(tri_plane_contacts.m_size == 0) //do nothing
{
GIM_DYNARRAY_DESTROY(tri_plane_contacts);//clean contact array
return 0;
}
//Getting a pointer to the contact array
vec4f * planecontacts = GIM_DYNARRAY_POINTER(vec4f,tri_plane_contacts);
int contactcount = tri_plane_contacts.m_size;
int i;
//Process contacts
for (i=0;i<contactcount ;i++)
{
vec3f contactpoint;
GREAL contactdis;
VEC_COPY(contactpoint,planecontacts[i]); //Get contact point
contactdis = planecontacts[i][3]; // Get distance depth
//Do something with the contact
......
......
// Like creating joints or anything else
......
......
}
GIM_DYNARRAY_DESTROY(tri_plane_contacts);
return contactcount;
}
\endcode
In each contact the 3 first coordinates refers to the contact point, the fourth refers to the distance depth and the normal is the normal of the plane.
\param trimesh
\param plane vec4f plane
\param contacts A vec4f array. Must be initialized (~100). Each element have the coordinate point in the first 3 elements, and vec4f[3] has the penetration depth.
*/
void gim_trimesh_plane_collision(GIM_TRIMESH * trimesh,vec4f plane, GDYNAMIC_ARRAY * contacts);
//! Trimesh Ray Collisions
/*!
\param trimesh
\param origin
\param dir
\param tmax
\param contact
\return 1 if the ray collides, else 0
*/
int gim_trimesh_ray_collision(GIM_TRIMESH * trimesh,vec3f origin,vec3f dir, GREAL tmax, GIM_TRIANGLE_RAY_CONTACT_DATA * contact);
//! Trimesh Ray Collisions closest
/*!
Find the closest primitive collided by the ray
\param trimesh
\param origin
\param dir
\param tmax
\param contact
\return 1 if the ray collides, else 0
*/
int gim_trimesh_ray_closest_collision(GIM_TRIMESH * trimesh,vec3f origin,vec3f dir, GREAL tmax, GIM_TRIANGLE_RAY_CONTACT_DATA * contact);
//! @}
#endif // GIM_TRIMESH_H_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -