SO3Engine
SO3MaterialPair.cpp
Go to the documentation of this file.
1
12
13extern mmachine mm;
14
15namespace SO3
16{
17
19{
21 mScene = scene;
22 mMat1 = mat1;
23 mMat2 = mat2;
24 contactCallbackActivated = false;
25 overlapStartedCallbackActivated = false;
26 overlapEndedCallbackActivated = false;
27
28 //needed due to a bug in newton, this make the physcis lag without it
34
36}
37
42
44{
45 return mMat1->getID();
46}
47
49{
50 return mMat2->getID();
51}
52
54{
55 return contactCallbackActivated;
56}
57
59{
60 contactCallbackActivated = state;
61}
62
64{
65 return overlapStartedCallbackActivated;
66}
67
69{
70 overlapStartedCallbackActivated = state;
71}
72
74{
75 return overlapEndedCallbackActivated;
76}
77
79{
80 overlapEndedCallbackActivated = state;
81}
82
87
88void SMaterialPair::SetDefaultElasticity(const Ogre::Real& value)
89{
91}
92
93void SMaterialPair::SetDefaultFriction(const Ogre::Real& stat, const Ogre::Real& kin)
94{
95 //Use a minimum value instead of 0 to prevent a bug that make not possible to set greater values after setting to 0
96 O3MaterialPair->setDefaultFriction(stat == 0.0f ? 0.01f : stat, kin == 0.0f ? 0.01f : kin);
97}
98
99void SMaterialPair::SetDefaultSoftness(const Ogre::Real& value)
100{
102}
103
105{
106 O3MaterialPair->setDefaultCollidable(enable ? 1 : 0);
107}
108
113
115{
116 SNode* nodeScol0 = Ogre::any_cast<SNode*>(body0->getUserData());
117 SNode* nodeScol1 = Ogre::any_cast<SNode*>(body1->getUserData());
118
119 if((nodeScol0 != NULL) && (nodeScol1 != NULL))
120 {
121 SBody* b0 = nodeScol0->GetSceneNodeBody();
122 SBody* b1 = nodeScol1->GetSceneNodeBody();
123
124 // return no collision if any of the bodies have the ignore state
125 if(((b0 != NULL) && b0->GetIgnoreCollision()) || ((b1 != NULL) && b1->GetIgnoreCollision()))
126 return 0;
127 }
128
129 // Process further contact detection.
130 /*
131 SBody* b0;
132 SBody* b1;
133 SNode* nodeScol0 = Ogre::any_cast<SNode*>(body0->getUserData());
134 SNode* nodeScol1 = Ogre::any_cast<SNode*>(body1->getUserData());
135 b0 = nodeScol0->nodeBody;
136 b1 = nodeScol1->nodeBody;
137
138 if(b0->isFluid)
139 {
140 b1->setBuoyancyForce(b0);
141 // Construct CollResult
142 SScene* mScene = nodeScol0->GetParentScene();
143 MCOLL* mCollResult = (MCOLL*)malloc(sizeof (MCOLL));
144 mCollResult->body0 = nodeScol0->nodeBody;
145 mCollResult->body1 = nodeScol1->nodeBody;
146 mCollResult->curScene = mScene;
147 //SendMessage( hwndScol, SO3_MATERIALPAIR_FLUID_CONTACT, (int)b0,(LONG)mCollResult);
148 free(mCollResult);
149 }
150 else if(b1->isFluid)
151 {
152 b0->setBuoyancyForce(b1);
153 // Construct CollResult
154 SScene* mScene = nodeScol0->GetParentScene();
155 MCOLL* mCollResult = (MCOLL*)malloc(sizeof (MCOLL));
156 mCollResult->body0 = nodeScol1->nodeBody;
157 mCollResult->body1 = nodeScol0->nodeBody;
158 mCollResult->curScene = mScene;
159 //SendMessage( hwndScol, SO3_MATERIALPAIR_FLUID_CONTACT, (int)b1,(LONG)mCollResult);
160 free(mCollResult);
161 }
162*/
163 return 1;
164}
165
166void SMaterialPair::contactsProcess(OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
167{
168 SNode* nodeScol0 = Ogre::any_cast<SNode*>(contactJoint.getBody0()->getUserData());
169 SNode* nodeScol1 = Ogre::any_cast<SNode*>(contactJoint.getBody1()->getUserData());
170
171 if((nodeScol0 != NULL) && (nodeScol1 != NULL))
172 {
173 SBody* b0 = nodeScol0->GetSceneNodeBody();
174 SBody* b1 = nodeScol1->GetSceneNodeBody();
175
176 if(b0 != NULL && b1 != NULL)
177 {
178 SScene* mScene = nodeScol0->GetParentScene();
180
181 if (world->GetBodyPairSize() < world->GetMaxBodyPair())
182 {
183 // Contact begin detection
184 if (GetOverlapStartedCallbackActivated() && (!world->GetBodyPairExist(b0, b1)))
185 {
186 // Construct CollResult
187 MCOLL* mCollResult = new MCOLL();
188 mCollResult->matPair = this;
189 mCollResult->node0 = b0->GetParentNode()->GetName();
190 mCollResult->node1 = b1->GetParentNode()->GetName();
191 mCollResult->curScene = mScene;
192
193 SBody** bpair = (SBody**)malloc(sizeof(SBody*) * 2);
194 if (bpair == 0)
195 return;
196
197 bpair[0] = b0;
198 bpair[1] = b1;
199
200 // Contact begin
201 world->AddBodyPair(b0->GetParentNode()->GetName() + "|" + b1->GetParentNode()->GetName(), bpair);
202 world->AddContactOverlapStart(b0->GetParentNode()->GetName() + "|" + b1->GetParentNode()->GetName(), mCollResult);
203 }
204
205 // For each contact point between those two bodies.
207 {
208 int maxcontact = 3;
209 int nbcontact = 0;
210
211 for (OgreNewt::Contact contact = contactJoint.getFirstContact(); contact && nbcontact < maxcontact; contact = contact.getNext())
212 {
213 Ogre::Vector3 pos;
214 Ogre::Vector3 normal;
215 contact.getPositionAndNormal(pos, normal, b0->getOgreNewtBodyPointer());
216
217 MCOLL* mCollResult = new MCOLL();
218 mCollResult->matPair = this;
219 mCollResult->node0 = b0->GetParentNode()->GetName();
220 mCollResult->node1 = b1->GetParentNode()->GetName();
221 mCollResult->position = pos;
222 mCollResult->normal = normal;
223 mCollResult->normalspeed = contact.getNormalSpeed();
224 mCollResult->force = contact.getForce();
225 mCollResult->curScene = mScene;
226
227 world->SetContactActivated(b0, b1, mCollResult);
228 nbcontact++;
229 }
230 }
231 }
232 }
233 }
234}
235
236}
mmachine mm
Definition SO3SCOL.cpp:109
main class for all Rigid Bodies in the system.
const Ogre::Any & getUserData() const
retrieve pointer to previously set user data.
with the methods from this class you can set the behavior of each contac-point
Contact getNext() const
get the next contact from the parent contact-joint
with this class you can iterate through all contacts
Contact getFirstContact()
get the first contact
OgreNewt::Body * getBody0()
get the first body
OgreNewt::Body * getBody1()
get the second body
define interaction between materials
void setDefaultSoftness(Ogre::Real softness) const
set default softness for the material pair.
void setDefaultCollidable(int state) const
set default collision for the material pair.
void setDefaultElasticity(Ogre::Real elasticity) const
set default elasticity for the material pair.
void setContactCallback(OgreNewt::ContactCallback *callback)
assign a custom collision callback.
void setDefaultSurfaceThickness(float thickness) const
set the default thickness for this material pair
void setDefaultFriction(Ogre::Real stat, Ogre::Real kinetic) const
set default friction for the material pair.
OgreNewt::Body * getOgreNewtBodyPointer()
Definition SO3Body.cpp:340
SNode * GetParentNode()
Definition SO3Body.cpp:649
bool GetIgnoreCollision()
Definition SO3Body.cpp:784
std::string GetName() const
OgreNewt::MaterialID * getOgreNewtMaterialID()
SMaterialID * mMat1
SMaterialPair(SScene *scene, SMaterialID *mat1, SMaterialID *mat2)
void SetContactCallbackActivated(const bool &state)
virtual int onAABBOverlap(OgreNewt::Body *body0, OgreNewt::Body *body1, int threadIndex)
user-defined AABB-overlap function
bool GetOverlapStartedCallbackActivated()
SMaterialID * mMat2
void SetOverlapStartedCallbackActivated(const bool &state)
void SetDefaultSoftness(const Ogre::Real &value)
virtual void contactsProcess(OgreNewt::ContactJoint &contactJoint, Ogre::Real timeStep, int threadIndex)
user-defined Process function
OgreNewt::MaterialPair * O3MaterialPair
void SetDefaultElasticity(const Ogre::Real &value)
void SetOverlapEndedCallbackActivated(const bool &state)
bool GetOverlapEndedCallbackActivated()
void SetDefaultFriction(const Ogre::Real &stat, const Ogre::Real &kin)
void SetDefaultSurfaceThickness(const Ogre::Real &value)
void SetDefaultCollidable(const bool &enable)
SScene * GetParentScene()
SBody * GetSceneNodeBody()
void AddBodyPair(std::string name, SBody **pair)
void SetContactActivated(SBody *b0, SBody *b1, MCOLL *coll)
unsigned int GetBodyPairSize()
bool GetBodyPairExist(SBody *b0, SBody *b1)
OgreNewt::World * GetPhysicWorld()
void AddContactOverlapStart(std::string name, MCOLL *coll)
unsigned int GetMaxBodyPair()
SPhysicWorld * GetPhysicsWorld()
Ogre::Vector3 force
Definition SO3Physics.h:53
SMaterialPair * matPair
Definition SO3Physics.h:48
std::string node1
Definition SO3Physics.h:50
const SScene * curScene
Definition SO3Physics.h:47
std::string node0
Definition SO3Physics.h:49
Ogre::Vector3 normal
Definition SO3Physics.h:52
Ogre::Real normalspeed
Definition SO3Physics.h:54
Ogre::Vector3 position
Definition SO3Physics.h:51