Project

General

Profile

SO3Engine
OgreNewt_MaterialPair.cpp
Go to the documentation of this file.
4
5namespace OgreNewt
6{
7
8
9MaterialPair::MaterialPair( const World* world, const MaterialID* mat1, const MaterialID* mat2 )
10{
11 m_world = world;
12 id0 = mat1;
13 id1 = mat2;
14 m_contactcallback = NULL;
15}
16
20
21
23{
24 m_contactcallback = callback;
26 if( callback )
27 {
28 NewtonMaterialSetCollisionCallback( m_world->getNewtonWorld(), id0->getID(), id1->getID(), this,
29 collisionCallback_onAABBOverlap,
30 collisionCallback_contactsProcess);
31 }
32 else
33 {
34 NewtonMaterialSetCollisionCallback( m_world->getNewtonWorld(), id0->getID(), id1->getID(), NULL,
35 NULL,
36 NULL);
37 }
38}
39
40
41int _CDECL MaterialPair::collisionCallback_onAABBOverlap( const NewtonMaterial* material, const NewtonBody* newtonBody0, const NewtonBody* newtonBody1, int threadIndex )
42{
43 MaterialPair* me;
44 me = (MaterialPair*)NewtonMaterialGetMaterialPairUserData( material );
45
46 Body* body0 = (OgreNewt::Body*)NewtonBodyGetUserData( newtonBody0 );
47 Body* body1 = (OgreNewt::Body*)NewtonBodyGetUserData( newtonBody1 );
48
49 return me->m_contactcallback->onAABBOverlap( body0, body1, threadIndex );
50}
51
52void _CDECL MaterialPair::collisionCallback_contactsProcess(const NewtonJoint *newtonContactJoint, dFloat timestep, int threadIndex )
53{
54 ContactJoint contactJoint(newtonContactJoint);
55
56 MaterialPair* me = contactJoint.getMaterialPair();
57
58 if( me != NULL )
59 {
60 (me->m_contactcallback->contactsProcess)(contactJoint, timestep, threadIndex);
61 }
62}
63
64
65}
66
main class for all Rigid Bodies in the system.
virtual int onAABBOverlap(OgreNewt::Body *body0, OgreNewt::Body *body1, int threadIndex)
user-defined AABB-overlap function
represents a material
int getID() const
get Newton-assigned material ID.
define interaction between materials
MaterialPair(const World *world, const MaterialID *mat1, const MaterialID *mat2)
constructor
void setContactCallback(OgreNewt::ContactCallback *callback)
assign a custom collision callback.
OgreNewt::ContactCallback * m_contactcallback
represents a physics world.
NewtonWorld * getNewtonWorld() const
retrieves a pointer to the NewtonWorld
void waitForUpdateToFinish() const