31 SPhysicWorld::SPhysicWorld()
35 SPhysicWorld::SPhysicWorld(
SScene* scene): mscene(scene)
45 if(worldDebuggerIsInit)
50 worldDebuggerIsInit =
false;
62 SO3_SAFE_DELETE(worldDebugger);
63 SO3_SAFE_DELETE(world);
66 void SPhysicWorld::initNewtonWorld()
70 mResetPhysicWorld =
false;
71 mGravity = Ogre::Vector3(0.0f, -9.81f, 0.0f);
72 worldIsEnabled =
false;
83 worldDebuggerIsInit =
false;
124 return worldIsEnabled;
129 worldIsEnabled = enable;
131 if (world && worldDebugger)
139 worldDebuggerIsInit =
false;
160 if (worldDebuggerIsInit)
166 worldDebuggerIsInit =
false;
174 worldDebugger->
init(
const_cast<SScene*
>(mscene)->GetOgreScenePointer());
176 worldDebuggerIsInit =
true;
183 return worldDebugger;
198 std::vector<MCOLL*> lOverlapStartCp;
199 std::vector<MCOLL*> lOverlapStopCp;
200 std::vector<MCOLL*> lContactCp;
208 catch (std::exception &)
223 PhysicContactMap::const_iterator iOverlapStartMap = lOverlapStart.begin();
224 while (iOverlapStartMap != lOverlapStart.end())
226 MCOLL* mCollResult = iOverlapStartMap->second;
227 lOverlapStartCp.push_back(mCollResult);
230 physicContactOverlapStartMap.clear();
234 PhysicContactMap::const_iterator iContactMap = lContacts.begin();
235 while (iContactMap != lContacts.end())
237 MCOLL* mCollResult = iContactMap->second;
238 lContactCp.push_back(mCollResult);
241 physicContactMap.clear();
245 BodyPairMap::const_iterator iBodyPairMap = bodyPairList.begin();
246 while (iBodyPairMap != bodyPairList.end())
249 bool bodiesInContact =
false;
250 SBody** bpair = iBodyPairMap->second;
251 SBody* fbody0 = bpair[0];
252 SBody* fbody1 = bpair[1];
253 if ((fbody0 != NULL) && (fbody1 != NULL))
258 if ((nbody0 != NULL) && (nbody1 != NULL))
262 NewtonJoint* contactJoint = NewtonBodyGetFirstContactJoint(b0);
264 while((contactJoint) && (!bodiesInContact))
267 NewtonBody* b0Bis = NewtonJointGetBody0(contactJoint);
268 NewtonBody* b1Bis = NewtonJointGetBody1(contactJoint);
269 int colstate = NewtonJointIsActive(contactJoint);
273 if(colstate && ((b0Bis == b0)&&(b1Bis == b1)) || ((b0Bis == b1)&&(b1Bis == b0)))
274 bodiesInContact =
true;
276 contactJoint = NewtonBodyGetNextContactJoint(b0, contactJoint);
285 SMaterialPairMap::const_iterator iMaterialPairList = materialPairList.begin();
286 while((iMaterialPairList != materialPairList.end()) && (!matPair))
290 matPair = *iMaterialPairList;
302 mCollResult->
matPair = matPair;
304 lOverlapStopCp.push_back(mCollResult);
309 bodyPairMap.erase(iBodyPairMap->first);
322 for (i = 0; i < lOverlapStartCp.size(); i++)
324 MCOLL* mCollResult = lOverlapStartCp[i];
332 for (i = 0; i < lContactCp.size(); i++)
334 MCOLL* mCollResult = lContactCp[i];
342 for (i = 0; i < lOverlapStopCp.size(); i++)
344 MCOLL* mCollResult = lOverlapStopCp[i];
381 SNodeMap::const_iterator iNodeList = mscene->
GetNodeList().begin();
384 SNode* curNode = iNodeList->second;
396 SNodeMap::const_iterator iNodeList = mscene->
GetNodeList().begin();
399 SNode* curNode = iNodeList->second;
461 return mResetPhysicWorld;
466 mResetPhysicWorld = state;
492 std::vector<MRAYINFO> lray;
495 for (
int i = 0; i < nbHits; i++)
508 lray.push_back(mray);
615 if(iBodyPairSearched == bodyPairMap.end())
618 if(iBodyPairSearched == bodyPairMap.end())
627 bodyPairMap.insert(BodyPairMap::value_type(name, pair));
632 return bodyPairMap.size();
642 BodyPairMap::const_iterator iBodyPairSearched = bodyMapList.begin();
643 while (iBodyPairSearched != bodyMapList.end())
645 SBody** bpair = iBodyPairSearched->second;
646 if ((bpair[0] == body) || (bpair[1] == body))
649 bodyPairMap.erase(iBodyPairSearched->first);
661 BodyPairMap::const_iterator iBodyMap = bodyListCopy.begin();
662 while (iBodyMap != bodyListCopy.end())
664 free(iBodyMap->second);
665 bodyPairMap.erase(iBodyMap->first);
672 physicContraintList.insert(contraint);
677 physicContraintList.erase(contraint);
683 return physicContraintList;
689 PhysicContraintList::const_iterator it;
690 for (it = list.begin(); it != list.end(); ++it)
693 physicContraintList.erase(it);
700 PhysicContraintList::const_iterator it;
701 for (it = list.begin(); it != list.end(); ++it)
703 if (((*it)->GetParentBody() == body) || ((*it)->GetSonBody() == body))
705 if ((*it)->GetParentBody() == body)
707 (*it)->SetParentBody(0);
711 (*it)->SetSonBody(0);
721 PhysicContactMap::const_iterator iOverlapStartMap = lOverlapStart.begin();
722 while (iOverlapStartMap != lOverlapStart.end())
724 MCOLL* mCollResult = iOverlapStartMap->second;
730 physicContactOverlapStartMap.clear();
736 physicContactOverlapStartMap.insert(PhysicContactMap::value_type(name, coll));
743 PhysicContactMap::const_iterator iContact = lContact.begin();
744 while (iContact != lContact.end())
746 MCOLL* mCollResult = iContact->second;
752 physicContactMap.clear();
759 if(iBodyContactSearched == physicContactMap.end())
762 if (iBodyContactSearched != physicContactMap.end())
764 delete (iBodyContactSearched->second);
765 iBodyContactSearched->second = coll;
776 const NewtonWorld* newtonWorld = NewtonBodyGetWorld(body);
778 const NewtonCollision* collision = NewtonBodyGetCollision(body);
785 NewtonBodyGetMassMatrix(body, &mass, &Ixx, &Iyy, &Izz);
786 mass = std::max(0.9f, mass);
789 NewtonBodyGetMatrix(body, &matrix[0][0]);
790 Ogre::Vector3 contact;
791 Ogre::Vector3 normal;
793 if (NewtonCollisionPointDistance(newtonWorld, &data->
position.x, collision, &matrix[0][0], &contact.x, &normal.x, 0))
795 float distance = (contact - data->
position).squaredLength();
796 if (distance <= data->radius)
798 Ogre::Vector3 impulse = (normal * (-data->
strenght * (1.0f - distance / data->
radius))) / mass;
799 NewtonBodyAddImpulse(body, &impulse[0], &contact[0]);
808 Ogre::Vector3 vmin = pos - radius;
809 Ogre::Vector3 vmax = pos + radius;
812 data.
radius = radius * radius;
int getMaterialOverlapEndedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Physic Material Overlap callback.
SMaterialPair * getMaterialPairByWorld(SPhysicWorld *world, int ID1, int ID2)
function to check if a material ID exists
int getMaterialOverlapStartedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Physic Material Overlap callback.
int getMaterialContactCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the callback a body leave the physic world.
float mod(float _a, float _b)
int getMaterialOverlapEndedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Physic Material Overlap callback.
SMaterialPair * getMaterialPairByWorld(SPhysicWorld *world, int ID1, int ID2)
function to check if a material ID exists
int getMaterialOverlapStartedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Physic Material Overlap callback.
int SCENE_PRE_RENDER_PHYSIC_EVENT
int getMaterialContactCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the callback a body leave the physic world.
SCOL_EXPORT void SCOL_PTR_TYPE param
int SO3PHYSICSMATERIALPAIR
simple class that represents a single raycast rigid body intersection.
Ogre::Vector3 getNormal()
OgreNewt::Body * getBody()
Basic implementation of the raycast.
BasicRaycastInfo getInfoAt(unsigned int hitnum) const
retrieve the raycast info for a specific hit.
int getHitCount() const
how many bodies did we hit?
BasicRaycastInfo getFirstHit() const
get the closest body hit by the ray.
main class for all Rigid Bodies in the system.
const Ogre::Any & getUserData() const
retrieve pointer to previously set user data.
void setMaterialGroupID(const MaterialID *ID)
set the material for the body
const OgreNewt::MaterialID * getMaterialGroupID() const
get a pointer to the Material assigned to this body.
Body * getNext() const
use this function to iterate through all bodies
NewtonBody * getNewtonBody() const
get a pointer to the NewtonBody object
For viewing the Newton rigid bodies visually.
void showDebugInformation()
show the newton world
void init(Ogre::SceneManager *smgr)
init the debugger.
void hideDebugInformation()
remove lines and text drawn
void deInit()
de-init the debugger (cleantup)
void stopRaycastRecording()
disables raycast-debugging
void startRaycastRecording(bool markhitbodies=false)
enable additional raycast-debugging (this also enables displaying of recorded raycasts!...
int getID() const
get Newton-assigned material ID.
represents a physics world.
void setPreListener(std::string name, void *const listenerUserData, NewtonWorldUpdateListenerCallback update)
const MaterialID * getDefaultMaterialID() const
get the default materialID object.
void setpostListener(std::string name, void *const listenerUserData, NewtonWorldUpdateListenerCallback update)
int update(Ogre::Real t_step)
update the world by the specified time_step.
void setThreadCount(int threads)
set the number of threads for the physics simulation to use, don't do this while world update
void setSolverModel(int model)
set the physics solver model
Debugger & getDebugger() const
get the debugger for this world
NewtonWorld * getNewtonWorld() const
retrieves a pointer to the NewtonWorld
void setUpdateFPS(Ogre::Real desiredFps, int maxUpdatesPerFrames)
set simulation frames per and max updated per updates
Body * getFirstBody() const
to iterate through all bodies call this function and then use body->getNext()
void waitForUpdateToFinish() const
int getPlatformArchitecture(Ogre::String &description)
get the architecture used for physics calculations.
void invalidateCache()
invalidate internal cache
OgreNewt::Body * getOgreNewtBodyPointer()
const OgreNewt::MaterialID * GetMaterialID()
std::string GetName() const
bool GetOverlapStartedCallbackActivated()
bool GetOverlapEndedCallbackActivated()
bool GetContactCallbackActivated()
SBody * GetSceneNodeBody()
virtual void StoreInitialPRS()
const SScene * GetScene()
SMaterialPair * CreatePhysicMaterialPair(SMaterialID *mat1, SMaterialID *mat2)
static void PostUpdate(const NewtonWorld *const world, void *const listenerUserData, dFloat timestep)
bool GetPhysicDebugEnable()
SMaterialPairMap listOfPhysicsMaterialPair
static int ImpulsePointCallback(const NewtonBody *const body, void *const userData)
void SetPhysicWorldSize(const Ogre::Vector3 &minsize, const Ogre::Vector3 &maxsize)
void ClearContactActivated()
void LeaveWorldCallBack(OgreNewt::Body *, int threadIndex)
static void PreUpdate(const NewtonWorld *const world, void *const listenerUserData, dFloat timestep)
void RemoveBodyPair(SBody *body)
void AddBodyPair(std::string name, SBody **pair)
void SetPhysicDebugEnable(const bool &enable)
void UpdatePhysic(const float &frameTime)
void AddPhysicContraint(SPhysicContraint *contraint)
SMaterialID * CreatePhysicMaterialID(const std::string &materialIdName)
void ClearContactOverlapStart()
void SetPhysicPlatformArchitecture(const int &mod)
void SetPhysicSolverModel(const int &mod)
void GetPhysicWorldSize(Ogre::Vector3 &minsize, Ogre::Vector3 &maxsize)
bool GetPhysicWorldEnable()
void SetContactActivated(SBody *b0, SBody *b1, MCOLL *coll)
unsigned int GetBodyPairSize()
bool GetBodyPairExist(SBody *b0, SBody *b1)
void SetPhysicWorldEnable(const bool &enable)
void SetPhysicFPS(const int &fps)
void SetResetPhysicWorld(const bool &state)
void ApplyImpulsePoint(Ogre::Vector3 pos, Ogre::Real radius, Ogre::Real strength)
SMaterialIDMap listOfMaterialID
void RemovePhysicContraint(SPhysicContraint *contraint)
OgreNewt::Debugger * GetPhysicDebugger()
PhysicContraintList GetPhysicContraintList()
int GetPhysicSolverModel()
int GetPhysicPlatformArchitecture()
OgreNewt::World * GetPhysicWorld()
void SetPhysicBodiesInitialState()
SBody * PhysicsRayCast(const Ogre::Vector3 &src, const Ogre::Vector3 &dir, const Ogre::Real &maxdist, Ogre::Real &hitdistance, Ogre::Vector3 &hitnormal)
bool GetResetPhysicWorld()
void RemoveBodyContraint(SBody *body)
void ClearPhysicContraint()
Ogre::Vector3 GetPhysicGravity()
void SetPhysicGravity(const Ogre::Vector3 &gravity)
void AddContactOverlapStart(std::string name, MCOLL *coll)
void DeletePhysicMaterialID(SMaterialID *matID)
void DeletePhysicMaterialPair(SMaterialPair *matpair)
unsigned int GetMaxBodyPair()
const SNodeMap & GetNodeList() const
std::unordered_set< SMaterialPair * > SMaterialPairMap
std::set< SPhysicContraint * > PhysicContraintList
std::unordered_map< std::string, MCOLL * > PhysicContactMap
std::unordered_map< std::string, SBody ** > BodyPairMap