SO3Engine
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes | List of all members
OgreNewt::World Class Reference

represents a physics world. More...

#include <OgreNewt_World.h>

Public Types

enum  SolverModelMode {
  SM_EXACT = 0 , SM_FASTEST = 1 , SM_MEDIUM = 4 , SM_SLOW = 8 ,
  SM_RIDICULUS = 16
}
 physics solver mode. More...
 
enum  FrictionModelMode { FM_EXACT = 0 , FM_ADAPTIVE = 1 }
 friction solver mode. More...
 
enum  PlatformArchitecture { PF_DETERMINISTIC_UNOPTIMIZED = 0 , PF_COMMON_OPTIMIZED = 1 , PF_BEST_POSSIBLE = 2 }
 platform mode More...
 
typedef std::function< void(OgreNewt::Body *, int threadIndex)> LeaveWorldCallback
 leave world callback.
 

Public Member Functions

 World (Ogre::Real desiredFps=100.0f, int maxUpdatesPerFrames=5, Ogre::String name="main")
 Constructor, creates the world and gives it a name.
 
 ~World ()
 Standard Destructor, destroys the world.
 
CustomTriggerController * CreateController (const dMatrix &matrix, NewtonCollision *const convexShape)
 
void DestroyController (CustomTriggerController *const controller)
 
void setPreListener (std::string name, void *const listenerUserData, NewtonWorldUpdateListenerCallback update)
 
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 invalidateCache ()
 invalidate internal cache
 
void setUpdateFPS (Ogre::Real desiredFps, int maxUpdatesPerFrames)
 set simulation frames per and max updated per updates
 
Ogre::Real getUpdateFPS () const
 returns desired update frames per second
 
void setDefaultLinearDamping (Ogre::Real defaultLinearDamping)
 sets default linear damping
 
Ogre::Real getDefaultLinearDamping () const
 return default linear damping
 
void setDefaultAngularDamping (Ogre::Vector3 defaultAngularDamping)
 sets default angular damping
 
Ogre::Vector3 getDefaultAngularDamping () const
 return default angular damping
 
NewtonWorld * getNewtonWorld () const
 retrieves a pointer to the NewtonWorld
 
const MaterialIDgetDefaultMaterialID () const
 get the default materialID object.
 
void destroyAllBodies ()
 remove all bodies from the world.
 
void setSolverModel (int model)
 set the physics solver model
 
void setFrictionModel (int model)
 set the physics friction model
 
void setPlatformArchitecture (int mode)
 specify a specific architecture to use for physics calculations.
 
int getPlatformArchitecture (Ogre::String &description)
 get the architecture used for physics calculations.
 
int getBodyCount () const
 get the number of bodies in the simulation.
 
int getConstraintCount () const
 get the number of constaints in the simulation
 
void setMultithreadSolverOnSingleIsland (int mode)
 multithread settings
 
int getMultithreadSolverOnSingleIsland () const
 get multithread settings
 
void setThreadCount (int threads)
 set the number of threads for the physics simulation to use, don't do this while world update
 
int getThreadCount () const
 get the number of threads the simulation is using.
 
void criticalSectionLock () const
 notify an entrance to a critical section of code.
 
void criticalSectionUnlock () const
 notify the exit of a critical section of code.
 
void waitForUpdateToFinish () const
 
void setMinimumFrameRate (Ogre::Real frame)
 set minimum framerate
 
int getVersion () const
 get the Newton SDK version.
 
BodygetFirstBody () const
 to iterate through all bodies call this function and then use body->getNext()
 
const BodyInAABBIteratorgetBodyInAABBIterator () const
 get a bodyInAABBIterator for this world
 
DebuggergetDebugger () const
 get the debugger for this world
 

Static Public Member Functions

static void setAllocators (NewtonAllocMemory newtonAlloc, NewtonFreeMemory newtonFree)
 Set the newton world allocators,.
 

Protected Types

typedef std::vector< OgreNewt::Body * > BodyVector
 
typedef std::vector< BodyVectorBodyVectorVector
 

Protected Attributes

int m_maxTicksPerFrames
 
Ogre::Real m_timestep
 
Ogre::Real m_invTimestep
 
Ogre::Real m_timeAcumulator
 
Ogre::Real m_updateFPS
 
Ogre::Vector3 m_defaultAngularDamping
 
Ogre::Real m_defaultLinearDamping
 
NewtonWorld * m_world
 
MaterialIDm_defaultMatID
 
BodyInAABBIterator m_bodyInAABBIterator
 
WorldTriggerManagerm_triggerManager
 
Debuggerm_debugger
 

Detailed Description

represents a physics world.

this class represents a NewtonWorld, which is the basic space in which physics elements can exist. It can have various Rigid Bodies, connected by joints, and other constraints.

Definition at line 141 of file OgreNewt_World.h.

Member Typedef Documentation

◆ BodyVector

typedef std::vector< OgreNewt::Body* > OgreNewt::World::BodyVector
protected

Definition at line 408 of file OgreNewt_World.h.

◆ BodyVectorVector

typedef std::vector< BodyVector > OgreNewt::World::BodyVectorVector
protected

Definition at line 409 of file OgreNewt_World.h.

◆ LeaveWorldCallback

typedef std::function<void(OgreNewt::Body*, int threadIndex)> OgreNewt::World::LeaveWorldCallback

leave world callback.

this function is called when a body leaves the OgreNewt::World. you can use this to destroy bodies that have left the scene, or re-position them, reflect them, do whatever you want.

callback binding to member classes is exactly the same as the various callbacks for the Body class.

Definition at line 193 of file OgreNewt_World.h.

Member Enumeration Documentation

◆ FrictionModelMode

friction solver mode.

like the physics solver mode, these options allow you to reduce the accuracy of the friction model in exchange for speed.

Enumerator
FM_EXACT 

exact friction model (default).

FM_ADAPTIVE 

adaptive friction mode. (faster but less accurate)

Definition at line 163 of file OgreNewt_World.h.

◆ PlatformArchitecture

platform mode

This function allows the application to configure the Newton to take advantage for specific hardware architecture in the same platform.

PF_DETERMINISTIC_UNOPTIMIZED = 0 - force the hardware lower common denominator for the running platform. PF_OPTIMIZED = 1 - will try to use common floating point enhancement like spacial instruction set on the specific architecture. This mode made lead to result that differ from mode 1 and 2 as the accumulation round off errors maybe different. PF_BEST_POSSIBLE = 2 - the engine will try to use the best possible hardware setting found in the current platform this is the default configuration. This mode made lead to result that differ from mode 1 and 2 as the accumulation round off errors maybe different.

The only hardware mode guarantee to work is mode 0. all other are only hints to the engine, for example setting mode 1 will take not effect on CPUs without specially floating point instructions set.

Enumerator
PF_DETERMINISTIC_UNOPTIMIZED 
PF_COMMON_OPTIMIZED 
PF_BEST_POSSIBLE 

Definition at line 179 of file OgreNewt_World.h.

◆ SolverModelMode

physics solver mode.

you can adjust the accuracy of the solver (and therefore the speed of the solver) using these, or a simple int >= 2. a value >= 2 represents the number of passes you want the engine to take when attempting to reconcile joints.

Enumerator
SM_EXACT 

the most accurate simulation.

SM_FASTEST 

still accurate, but faster.

SM_MEDIUM 

more accurate, stronger joints, but still liner

SM_SLOW 

even more accurate, stronger joints, but still linear

SM_RIDICULUS 

you better use teh quadric solver

Definition at line 150 of file OgreNewt_World.h.

Constructor & Destructor Documentation

◆ World()

OgreNewt::World::World ( Ogre::Real  desiredFps = 100.0f,
int  maxUpdatesPerFrames = 5,
Ogre::String  name = "main" 
)

Constructor, creates the world and gives it a name.

The name can later be used to get world reference using OgreNewt::World::get(name)

Definition at line 34 of file OgreNewt_World.cpp.

◆ ~World()

OgreNewt::World::~World ( )

Standard Destructor, destroys the world.

Definition at line 61 of file OgreNewt_World.cpp.

Member Function Documentation

◆ CreateController()

CustomTriggerController * OgreNewt::World::CreateController ( const dMatrix &  matrix,
NewtonCollision *const  convexShape 
)

Definition at line 82 of file OgreNewt_World.cpp.

◆ criticalSectionLock()

void OgreNewt::World::criticalSectionLock ( ) const
inline

notify an entrance to a critical section of code.

Definition at line 356 of file OgreNewt_World.h.

◆ criticalSectionUnlock()

void OgreNewt::World::criticalSectionUnlock ( ) const
inline

notify the exit of a critical section of code.

Definition at line 359 of file OgreNewt_World.h.

◆ destroyAllBodies()

void OgreNewt::World::destroyAllBodies ( )
inline

remove all bodies from the world.

destroys all Rigid Bodies and Joints in the world. the bodies are properly deleted, so don't try and access any pointers you have lying around!

Definition at line 297 of file OgreNewt_World.h.

◆ DestroyController()

void OgreNewt::World::DestroyController ( CustomTriggerController *const  controller)

Definition at line 90 of file OgreNewt_World.cpp.

◆ getBodyCount()

int OgreNewt::World::getBodyCount ( ) const
inline

get the number of bodies in the simulation.

returns the number of bodies in the simulation.

Definition at line 338 of file OgreNewt_World.h.

◆ getBodyInAABBIterator()

const BodyInAABBIterator & OgreNewt::World::getBodyInAABBIterator ( ) const
inline

get a bodyInAABBIterator for this world

Definition at line 379 of file OgreNewt_World.h.

◆ getConstraintCount()

int OgreNewt::World::getConstraintCount ( ) const
inline

get the number of constaints in the simulation

Definition at line 341 of file OgreNewt_World.h.

◆ getDebugger()

Debugger & OgreNewt::World::getDebugger ( ) const
inline

get the debugger for this world

the debugger needs to be initialized (Debugger::init(...) ) in order to work correctly

Definition at line 385 of file OgreNewt_World.h.

◆ getDefaultAngularDamping()

Ogre::Vector3 OgreNewt::World::getDefaultAngularDamping ( ) const
inline

return default angular damping

Returns
default angular damping

Definition at line 277 of file OgreNewt_World.h.

◆ getDefaultLinearDamping()

Ogre::Real OgreNewt::World::getDefaultLinearDamping ( ) const
inline

return default linear damping

Returns
default linear damping

Definition at line 261 of file OgreNewt_World.h.

◆ getDefaultMaterialID()

const MaterialID * OgreNewt::World::getDefaultMaterialID ( ) const
inline

get the default materialID object.

when you create a world, a default material is created, which is by default applied to all new rigid bodies. you might need this pointer when assigning material callbacks, etc.

Returns
pointer to a MaterialID* representing the default material.

Definition at line 291 of file OgreNewt_World.h.

◆ getFirstBody()

Body * OgreNewt::World::getFirstBody ( ) const

to iterate through all bodies call this function and then use body->getNext()

Definition at line 191 of file OgreNewt_World.cpp.

◆ getMultithreadSolverOnSingleIsland()

int OgreNewt::World::getMultithreadSolverOnSingleIsland ( ) const
inline

get multithread settings

Definition at line 347 of file OgreNewt_World.h.

◆ getNewtonWorld()

NewtonWorld * OgreNewt::World::getNewtonWorld ( ) const
inline

retrieves a pointer to the NewtonWorld

in most cases you shouldn't need this... but in case you want to implement something not yet in the library, you can use this to get a pointer to the NewtonWorld object.

Returns
pointer to NewtonWorld

Definition at line 284 of file OgreNewt_World.h.

◆ getPlatformArchitecture()

int OgreNewt::World::getPlatformArchitecture ( Ogre::String &  description)
inline

get the architecture used for physics calculations.

Parameters
descriptionreturns a description-string for the currently used mode
Returns
int representing the current mode

Definition at line 332 of file OgreNewt_World.h.

◆ getThreadCount()

int OgreNewt::World::getThreadCount ( ) const
inline

get the number of threads the simulation is using.

Definition at line 353 of file OgreNewt_World.h.

◆ getUpdateFPS()

Ogre::Real OgreNewt::World::getUpdateFPS ( ) const
inline

returns desired update frames per second

Returns
desired update rate

Definition at line 245 of file OgreNewt_World.h.

◆ getVersion()

int OgreNewt::World::getVersion ( ) const
inline

get the Newton SDK version.

Definition at line 368 of file OgreNewt_World.h.

◆ invalidateCache()

void OgreNewt::World::invalidateCache ( )
inline

invalidate internal cache

this function completely resets the cache that Newton uses to improve simulation performance. This is useful for situations where you have reset the simulation to a previous point in time, or reset all bodies, and do not want the state of the world from the previous frame affecting the next frame.

Definition at line 232 of file OgreNewt_World.h.

◆ setAllocators()

void OgreNewt::World::setAllocators ( NewtonAllocMemory  newtonAlloc,
NewtonFreeMemory  newtonFree 
)
static

Set the newton world allocators,.

Is is no necessary to call this function allocations default to malloc and free but if an application
then it must call this once before the creation of any Newton world

Definition at line 124 of file OgreNewt_World.cpp.

◆ setDefaultAngularDamping()

void OgreNewt::World::setDefaultAngularDamping ( Ogre::Vector3  defaultAngularDamping)
inline

sets default angular damping

default damping is used when creating new bodies and changing this applies only to bodies created after calling this method. default damping is also timestep-dependant, the value you set here is for 60fps and scales down if using larger physics update rate.

Parameters
defaultLinearDampingOgre::Real default linear damping to use

Definition at line 271 of file OgreNewt_World.h.

◆ setDefaultLinearDamping()

void OgreNewt::World::setDefaultLinearDamping ( Ogre::Real  defaultLinearDamping)
inline

sets default linear damping

default damping is used when creating new bodies and changing this applies only to bodies created after calling this method. default damping is also timestep-dependant, the value you set here is for 60fps and scales down if using larger physics update rate.

Parameters
defaultLinearDampingOgre::Real default linear damping to use

Definition at line 255 of file OgreNewt_World.h.

◆ setFrictionModel()

void OgreNewt::World::setFrictionModel ( int  model)
inline

set the physics friction model

setting the friction model allows sacrificing accuracy and realism for speed, good for games, etc. for a more detailed description of how to use this function, see the Newton documentation.

Parameters
modelint representing friction model. you can also pass the enum values I've included.
See also
FrictionModelMode

Definition at line 313 of file OgreNewt_World.h.

◆ setMinimumFrameRate()

void OgreNewt::World::setMinimumFrameRate ( Ogre::Real  frame)
inline

set minimum framerate

Definition at line 364 of file OgreNewt_World.h.

◆ setMultithreadSolverOnSingleIsland()

void OgreNewt::World::setMultithreadSolverOnSingleIsland ( int  mode)
inline

multithread settings

Definition at line 344 of file OgreNewt_World.h.

◆ setPlatformArchitecture()

void OgreNewt::World::setPlatformArchitecture ( int  mode)
inline

specify a specific architecture to use for physics calculations.

Setting to a specific architecture can allow for deterministic physics calculations on systems with different cpus, which is particularly useful for multiplayer systems where deterministic physics are absolutely vital.

Definition at line 320 of file OgreNewt_World.h.

◆ setpostListener()

void OgreNewt::World::setpostListener ( std::string  name,
void *const  listenerUserData,
NewtonWorldUpdateListenerCallback  update 
)

Definition at line 100 of file OgreNewt_World.cpp.

◆ setPreListener()

void OgreNewt::World::setPreListener ( std::string  name,
void *const  listenerUserData,
NewtonWorldUpdateListenerCallback  update 
)

Definition at line 95 of file OgreNewt_World.cpp.

◆ setSolverModel()

void OgreNewt::World::setSolverModel ( int  model)

set the physics solver model

setting the solver model allows sacrificing accuracy and realism for speed, good for games, etc. for a more detailed description of how to use this function, see the Newton documentation.

Parameters
modelint representing the physics model. you can also pass the enum values I've included.
See also
SolverModelMode

Definition at line 200 of file OgreNewt_World.cpp.

◆ setThreadCount()

void OgreNewt::World::setThreadCount ( int  threads)

set the number of threads for the physics simulation to use, don't do this while world update

Definition at line 129 of file OgreNewt_World.cpp.

◆ setUpdateFPS()

void OgreNewt::World::setUpdateFPS ( Ogre::Real  desiredFps,
int  maxUpdatesPerFrames 
)

set simulation frames per and max updated per updates

this function set the update rate of the simulation plus the maximum number of update per frame the simulation can execute in order to catch up.

Definition at line 105 of file OgreNewt_World.cpp.

◆ update()

int OgreNewt::World::update ( Ogre::Real  t_step)

update the world by the specified time_step.

this function is clamped between values representing fps [60,600]. if you pass a smaller value, it is internally clamped to 60fps. likewise a value higher than 600fps is treated as 600fs.

Parameters
t_stepReal value representing the time elapsed in seconds.
Returns
How many times was the actual physics updated

Definition at line 135 of file OgreNewt_World.cpp.

◆ waitForUpdateToFinish()

void OgreNewt::World::waitForUpdateToFinish ( ) const
inline

Definition at line 361 of file OgreNewt_World.h.

Member Data Documentation

◆ m_bodyInAABBIterator

BodyInAABBIterator OgreNewt::World::m_bodyInAABBIterator
protected

Definition at line 406 of file OgreNewt_World.h.

◆ m_debugger

Debugger* OgreNewt::World::m_debugger
mutableprotected

Definition at line 412 of file OgreNewt_World.h.

◆ m_defaultAngularDamping

Ogre::Vector3 OgreNewt::World::m_defaultAngularDamping
protected

Definition at line 400 of file OgreNewt_World.h.

◆ m_defaultLinearDamping

Ogre::Real OgreNewt::World::m_defaultLinearDamping
protected

Definition at line 401 of file OgreNewt_World.h.

◆ m_defaultMatID

MaterialID* OgreNewt::World::m_defaultMatID
protected

Definition at line 404 of file OgreNewt_World.h.

◆ m_invTimestep

Ogre::Real OgreNewt::World::m_invTimestep
protected

Definition at line 396 of file OgreNewt_World.h.

◆ m_maxTicksPerFrames

int OgreNewt::World::m_maxTicksPerFrames
protected

Definition at line 394 of file OgreNewt_World.h.

◆ m_timeAcumulator

Ogre::Real OgreNewt::World::m_timeAcumulator
protected

Definition at line 397 of file OgreNewt_World.h.

◆ m_timestep

Ogre::Real OgreNewt::World::m_timestep
protected

Definition at line 395 of file OgreNewt_World.h.

◆ m_triggerManager

WorldTriggerManager* OgreNewt::World::m_triggerManager
protected

Definition at line 411 of file OgreNewt_World.h.

◆ m_updateFPS

Ogre::Real OgreNewt::World::m_updateFPS
protected

Definition at line 398 of file OgreNewt_World.h.

◆ m_world

NewtonWorld* OgreNewt::World::m_world
protected

Definition at line 403 of file OgreNewt_World.h.


The documentation for this class was generated from the following files: