Go to the documentation of this file.00001
00007 #include "SO3ContactCallBack.h"
00008 #include "SO3Body.h"
00009 #include "../SO3PhysicGraph/SO3MaterialPair.h"
00010 #include "../SO3SceneGraph/SO3NodeScol.h"
00011 #include "../SO3SceneGraph/SO3Scene.h"
00012 #include "../SCOLPack/SO3SCOL.h"
00013
00014 extern HWND hwndScol;
00015 extern mmachine mm;
00016 extern int SO3_MATERIALPAIR_FLUID_CONTACT;
00017 extern int getMaterialOverlapStartedCallback(mmachine m, int id, MCOLL * result);
00018 extern int getMaterialContactCallback(mmachine m, int id, MCOLL * result);
00019
00020
00021 SContactCallback::SContactCallback(SMaterialPair* matPair): OgreNewt::ContactCallback()
00022 {
00023 this->matPair = matPair;
00024 }
00025
00026
00027 SContactCallback::~SContactCallback()
00028 {
00029 }
00030
00031 int SContactCallback::onAABBOverlap(OgreNewt::Body* body0, OgreNewt::Body* body1, int threadIndex )
00032 {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 return 1;
00068 }
00069
00070 void SContactCallback::contactsProcess(OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
00071 {
00072 SNode* nodeScol0 = Ogre::any_cast<SNode*>(contactJoint.getBody0()->getUserData());
00073 SNode* nodeScol1 = Ogre::any_cast<SNode*>(contactJoint.getBody1()->getUserData());
00074
00075 if(nodeScol0 != NULL && nodeScol1 != NULL)
00076 {
00077 SBody* b0;
00078 SBody* b1;
00079 SScene* mScene = nodeScol0->GetParentScene();
00080
00081
00082 BodyPairMap::iterator iBodyPairSearched = mScene->bodyPairMap.find(nodeScol0->nodeBody);
00083 if(iBodyPairSearched == mScene->bodyPairMap.end())
00084 {
00085 iBodyPairSearched = mScene->bodyPairMap.find(nodeScol1->nodeBody);
00086 if(iBodyPairSearched == mScene->bodyPairMap.end())
00087 {
00088
00089 MCOLL* mCollResult = (MCOLL*)malloc(sizeof (MCOLL));
00090 mCollResult->body0 = nodeScol0->nodeBody;
00091 mCollResult->body1 = nodeScol1->nodeBody;
00092 mCollResult->curScene = mScene;
00093
00094
00095 mScene->bodyPairMap.insert(BodyPairMap::value_type(nodeScol0->nodeBody, nodeScol1->nodeBody));
00096 getMaterialOverlapStartedCallback(mm, (int)this->matPair, mCollResult);
00097
00098
00099 free(mCollResult);
00100 }
00101 }
00102
00103
00104 for (OgreNewt::Contact contact = contactJoint.getFirstContact(); contact; contact = contact.getNext())
00105 {
00106 b0 = nodeScol0->nodeBody;
00107 b1 = nodeScol1->nodeBody;
00108
00109 Ogre::Vector3 pos;
00110 Ogre::Vector3 normal;
00111 contact.getPositionAndNormal(pos, normal);
00112
00113 MCOLL* mCollResult = (MCOLL*)malloc(sizeof (MCOLL));
00114 mCollResult->body0 = b0;
00115 mCollResult->body1 = b1;
00116 mCollResult->position = pos;
00117 mCollResult->normal = normal;
00118 mCollResult->normalspeed = contact.getNormalSpeed();
00119 mCollResult->force = contact.getForce();
00120 mCollResult->curScene = mScene;
00121
00122
00123 getMaterialContactCallback(mm, (int)this->matPair, mCollResult);
00124
00125
00126 free(mCollResult);
00127 }
00128 }
00129 }