World class. More...

Inheritance diagram for World:

Public Types

enum  { E_Advance = 1200, E_Play = 1201, E_Stop = 1202, E_Pause = 1203 }
 Custom Event Types. More...
 
enum  w_state { playingS, pausedS, stoppedS }
 define the state of the World More...
 

Public Slots

void advance ()
 Do a step of the World. More...
 
void finalize ()
 Operation performed at the end of the simulation. More...
 
void initialize ()
 Initialize the World, it doesn't do anything if it's already initialized. More...
 
void pause ()
 Pause the World. More...
 
int play ()
 run the World calling advance as fast as possibile (return the timerId) More...
 
void stop ()
 Stop the World. More...
 

Signals

void addedJoint (PhyJoint *)
 emitted when an PhyJoint has been added More...
 
void addedObject (WObject *)
 emitted when an WObject has been added More...
 
void advanced ()
 When exit from advance method. More...
 
void finished ()
 When exit from finalize method. More...
 
void initialized ()
 When exit from initialize method. More...
 
void paused ()
 When the stop method is called. More...
 
void removedJoint (PhyJoint *)
 emitted when an PhyJoint has been removed More...
 
void removedObject (WObject *)
 emitted when an WObject has been removed More...
 
void resized ()
 emitted when the World change its size More...
 
void stopped ()
 When the stopped method is called. More...
 

Public Member Functions

 World (QString worldname)
 Constructor. More...
 
virtual ~World ()
 Destructor. More...
 
void advanceUntil (real time)
 Advance the World until the time passed is reached (approx. More...
 
bool checkContacts (PhyObject *obj1, PhyObject *obj2, int maxContacts=4, QVector< wVector > *contacts=NULL, QVector< wVector > *normals=NULL, QVector< real > *penetra=NULL)
 Checks whether two objects collide or not. More...
 
void cleanUpMemory ()
 Clean up memory. More...
 
bool closestPoints (PhyObject *objA, PhyObject *objB, wVector &pointA, wVector &pointB)
 calculate the two closest points between the two objects; More...
 
real collisionRayCast (PhyObject *obj, wVector start, wVector end, wVector *normal=NULL)
 Checks whether the ray from start to end intersects obj. More...
 
const contactMap & contacts ()
 return the contact map More...
 
void disableCollision (PhyObject *obj1, PhyObject *obj2)
 Disable collision between bodies. More...
 
real elapsedTime () const
 Get the elapsed time. More...
 
void enableCollision (PhyObject *obj1, PhyObject *obj2)
 Enable collision. More...
 
WObjectgetObject (QString name)
 Return the WObject with name specified, otherwise return NULL. More...
 
real gravityForce () const
 Return the gravity force. More...
 
bool isRealTime () const
 return true is real-time is enabled ; false otherwise More...
 
const QLinkedList< PhyJoint * > joints ()
 Return the vector of joints present in this world. More...
 
const QHash< WObject *, QList< PhyJoint * > > mapObjectsToJoints ()
 Map object -> joints. More...
 
MaterialDBmaterials ()
 return the MaterialDB object for managing World's materials More...
 
QString name () const
 Return the name. More...
 
const QLinkedList< WObject * > objects ()
 Return the vector of objects present in this world. More...
 
void popJoint (PhyJoint *)
 
void popObject (WObject *)
 
void pushJoint (PhyJoint *)
 
void pushObject (WObject *)
 
void resetElapsedTime ()
 Reset the time counter and restart from zero seconds. More...
 
void setFrictionModel (QString model)
 See Physic Engine Documentation. More...
 
void setGravityForce (real g)
 Set the gravity force. More...
 
void setIsRealTime (bool b)
 Enable/Disable Real-time advance. More...
 
void setMinimumFrameRate (unsigned int frames)
 Set the minimum frame rate; in other word the number of integration steps per seconds regardless the time step setted. More...
 
void setMultiThread (int numThreads)
 Set the multi-thread functionality. More...
 
void setSize (const wVector &minPoint, const wVector &maxPoint)
 See Physic Engine Documentation. More...
 
void setSolverModel (QString model)
 See Physic Engine Documentation. More...
 
void setTimeStep (real)
 Set the time step. More...
 
void size (wVector &minPoint, wVector &maxPoint)
 Get the bounding box of the world. More...
 
bool smartCheckContacts (PhyObject *obj1, PhyObject *obj2, int maxContacts=4, QVector< wVector > *contacts=NULL)
 Checks whether two objects collide or not. More...
 
w_state status ()
 return the actual state More...
 
real timeStep () const
 get the time step setted More...
 
rayCastHitVector worldRayCast (wVector start, wVector end, bool onlyClosest, const QSet< PhyObject * > &ignoredObjs=QSet< PhyObject * >())
 Returns the bodyes which intersect the ray from start to end. More...
 

Protected Member Functions

void customEvent (QEvent *e)
 Custom Events. More...
 
void timerEvent (QTimerEvent *e)
 Event for handling play/stop in order to stay syncronized with QT main thread. More...
 

Protected Attributes

real gforce
 Gravity Force. More...
 
QLinkedList< PhyJoint * > jointsv
 Vector of Joints inside the World. More...
 
QHash< WObject *, QList< PhyJoint * > > mapObjJoints
 Map object -> joints. More...
 
wVector maxP
 
wVector minP
 Size of the Newton world. More...
 
QLinkedList< WObject * > objs
 Vector of WObject inside the World. More...
 
real time
 The elapsed simulation-time from last calls of initialize() More...
 
real timestepv
 The time step. More...
 

Friends

class MaterialDB
 
class PhyJoint
 
class PhyObject
 
class WorldPrivate
 

Detailed Description

World class.

Motivation
The World represent the environment in which robots are inserted and interacts with.
The World contains all objects: actives and passives.
The World has a continuous temporal dimension. It's possibile set the time step of integration.
Description
Description coming soon
Warnings
Warnings

Definition at line 223 of file world.h.

Member Enumeration Documentation

anonymous enum

Custom Event Types.

Definition at line 449 of file world.h.

enum w_state

define the state of the World

Definition at line 371 of file world.h.

Constructor & Destructor Documentation

World ( QString  worldname)

Constructor.

Parameters
worldnameis the reference name for the World

Definition at line 146 of file world.cpp.

References World::gforce, World::minP, World::name(), World::time, and World::timestepv.

~World ( )
virtual

Destructor.

Definition at line 180 of file world.cpp.

References World::jointsv, World::objs, and Ownable::owner().

Member Function Documentation

void addedJoint ( PhyJoint )
signal

emitted when an PhyJoint has been added

void addedObject ( WObject )
signal

emitted when an WObject has been added

void advance ( )
slot

Do a step of the World.

Note
The sequence of actions here is: update motor controllers; call preUpdate on all objects; call preUpdate on all joints; perform the actual physical simulation step; call postUpdate on all objects; call postUpdate on all joints

Definition at line 219 of file world.cpp.

References World::advanced(), World::initialize(), World::jointsv, World::objs, SimpleTimer::tac(), SimpleTimer::tic(), World::time, and World::timestepv.

Referenced by World::advanceUntil(), World::customEvent(), and World::timerEvent().

void advanced ( )
signal

When exit from advance method.

Referenced by World::advance().

void advanceUntil ( real  time)

Advance the World until the time passed is reached (approx.

per difetto)

Warning
This method block the signals, so no signals will be emitted
this method ignore real-time settings, it always go as fast as possible

Definition at line 354 of file world.cpp.

References World::advance(), and World::time.

bool checkContacts ( PhyObject obj1,
PhyObject obj2,
int  maxContacts = 4,
QVector< wVector > *  contacts = NULL,
QVector< wVector > *  normals = NULL,
QVector< real > *  penetra = NULL 
)

Checks whether two objects collide or not.

Parameters
obj1first object
obj2second object
maxContactsthe maxium number of contacts to report
contactsif not null, the vector is filled with collision contact points in the world frame of reference
normalsif not null, the vector is filled with collision contact normals in the world frame of reference
penetraif not null, the vector is filled with collision penetration at each point
Returns
true if the two object are in contacts

Definition at line 526 of file world.cpp.

References WObject::matrix(), and PhyObject::priv.

Referenced by World::smartCheckContacts().

void cleanUpMemory ( )

Clean up memory.

Definition at line 502 of file world.cpp.

bool closestPoints ( PhyObject objA,
PhyObject objB,
wVector pointA,
wVector pointB 
)

calculate the two closest points between the two objects;

Parameters
objAfirst object
objBsecond object
pointAthe point on objA's shape closest to objB
pointBthe point on objB's shape closest to objA
Returns
true is the calculation has been done, false if the object are colliding In the case of colliding objects the points will be setted to zero

Definition at line 650 of file world.cpp.

References WObject::matrix(), and PhyObject::priv.

real collisionRayCast ( PhyObject obj,
wVector  start,
wVector  end,
wVector normal = NULL 
)

Checks whether the ray from start to end intersects obj.

Parameters
objthe object whose collision with the ray we have to check
startthe starting point of the ray (in the global frame of reference)
endthe ending point of the ray (in the global frame of reference)
normalif not null the pointed wVector will store the normal to the contact point
Returns
a value between 0.0 and 1.0 indicating the point along the ray which intersects the object (with 0.0 being the starting point and 1.0 the ending point). If the ray misses the objects, the returned value is greater than 1.0

Definition at line 599 of file world.cpp.

References wMatrix::inverse(), WObject::matrix(), PhyObject::priv, and wMatrix::transformVector().

const contactMap & contacts ( )

return the contact map

Definition at line 522 of file world.cpp.

void customEvent ( QEvent *  e)
protected

Custom Events.

Definition at line 291 of file world.cpp.

References World::advance(), World::pause(), World::play(), and World::stop().

void disableCollision ( PhyObject obj1,
PhyObject obj2 
)

Disable collision between bodies.

If you want create an object that doesn't collide with anything, set the nonCollidableMaterial to the object

Definition at line 385 of file world.cpp.

real elapsedTime ( ) const

Get the elapsed time.

Definition at line 316 of file world.cpp.

References World::time.

void enableCollision ( PhyObject obj1,
PhyObject obj2 
)

Enable collision.

Definition at line 390 of file world.cpp.

void finalize ( )
slot

Operation performed at the end of the simulation.

Definition at line 253 of file world.cpp.

References World::finished().

Referenced by World::initialize(), and World::stop().

void finished ( )
signal

When exit from finalize method.

Referenced by World::finalize().

WObject * getObject ( QString  name)

Return the WObject with name specified, otherwise return NULL.

Definition at line 369 of file world.cpp.

References WObject::name(), World::name(), and World::objs.

real gravityForce ( ) const

Return the gravity force.

Definition at line 350 of file world.cpp.

References World::gforce.

Referenced by MaterialDB::gravityForce().

void initialize ( )
slot

Initialize the World, it doesn't do anything if it's already initialized.

Definition at line 206 of file world.cpp.

References World::finalize(), World::initialized(), SimpleTimer::tic(), and World::time.

Referenced by World::advance().

void initialized ( )
signal

When exit from initialize method.

Referenced by World::initialize().

bool isRealTime ( ) const

return true is real-time is enabled ; false otherwise

Definition at line 328 of file world.cpp.

const QLinkedList< PhyJoint * > joints ( )

Return the vector of joints present in this world.

Definition at line 377 of file world.cpp.

References World::jointsv.

const QHash< WObject *, QList< PhyJoint * > > mapObjectsToJoints ( )

Map object -> joints.

Definition at line 381 of file world.cpp.

References World::mapObjJoints.

MaterialDB& materials ( )
inline

return the MaterialDB object for managing World's materials

Definition at line 334 of file world.h.

Referenced by PhyEpuck::PhyEpuck(), PhyKhepera::PhyKhepera(), and PhyMarXbot::PhyMarXbot().

QString name ( ) const

Return the name.

Definition at line 202 of file world.cpp.

Referenced by World::getObject(), and World::World().

const QLinkedList< WObject * > objects ( )

Return the vector of objects present in this world.

Definition at line 365 of file world.cpp.

References World::objs.

Referenced by RenderWObjectContainer::resourceChanged().

void pause ( )
slot

Pause the World.

Definition at line 269 of file world.cpp.

References World::paused().

Referenced by World::customEvent().

void paused ( )
signal

When the stop method is called.

Referenced by World::pause().

int play ( )
slot

run the World calling advance as fast as possibile (return the timerId)

Definition at line 261 of file world.cpp.

Referenced by World::customEvent().

void removedJoint ( PhyJoint )
signal

emitted when an PhyJoint has been removed

void removedObject ( WObject )
signal

emitted when an WObject has been removed

void resetElapsedTime ( )

Reset the time counter and restart from zero seconds.

Definition at line 320 of file world.cpp.

References World::time.

void resized ( )
signal

emitted when the World change its size

Referenced by World::setSize().

void setFrictionModel ( QString  model)

See Physic Engine Documentation.

Definition at line 405 of file world.cpp.

void setGravityForce ( real  g)

Set the gravity force.

Definition at line 346 of file world.cpp.

References World::gforce.

void setIsRealTime ( bool  b)

Enable/Disable Real-time advance.

Definition at line 324 of file world.cpp.

void setMinimumFrameRate ( unsigned int  frames)

Set the minimum frame rate; in other word the number of integration steps per seconds regardless the time step setted.

Definition at line 336 of file world.cpp.

void setMultiThread ( int  numThreads)

Set the multi-thread functionality.

Definition at line 415 of file world.cpp.

References farsa::max().

void setSize ( const wVector minPoint,
const wVector maxPoint 
)

See Physic Engine Documentation.

Definition at line 422 of file world.cpp.

References World::minP, and World::resized().

void setSolverModel ( QString  model)

See Physic Engine Documentation.

Definition at line 395 of file world.cpp.

void setTimeStep ( real  ts)

Set the time step.

Definition at line 332 of file world.cpp.

References World::timestepv.

void size ( wVector minPoint,
wVector maxPoint 
)

Get the bounding box of the world.

Definition at line 431 of file world.cpp.

References World::minP.

Referenced by RenderWObjectContainer::drawSkyGroundBox(), RenderWorld::init(), and RenderWorld::resourceChanged().

bool smartCheckContacts ( PhyObject obj1,
PhyObject obj2,
int  maxContacts = 4,
QVector< wVector > *  contacts = NULL 
)

Checks whether two objects collide or not.

This function uses checkContacts if at least one object is kinematic or if both objects are static, otherwise collision information are taken from contactMap

Parameters
obj1first object
obj2second object
maxContactsthe maxium number of contacts to report
contactsif not null, the vector is filled with collision contact points in the world frame of reference
Returns
true if the two object are in contacts

Definition at line 568 of file world.cpp.

References World::checkContacts(), PhyObject::getKinematic(), and PhyObject::getStatic().

w_state status ( )
inline

return the actual state

Definition at line 373 of file world.h.

void stop ( )
slot

Stop the World.

Definition at line 277 of file world.cpp.

References World::finalize(), and World::stopped().

Referenced by World::customEvent().

void stopped ( )
signal

When the stopped method is called.

Referenced by World::stop().

void timerEvent ( QTimerEvent *  e)
protected

Event for handling play/stop in order to stay syncronized with QT main thread.

Definition at line 286 of file world.cpp.

References World::advance().

real timeStep ( ) const

get the time step setted

Definition at line 342 of file world.cpp.

References World::timestepv.

Referenced by PhySlider::updateJointInfo(), PhySuspension::updateJointInfo(), and PhyHinge::updateJointInfo().

rayCastHitVector worldRayCast ( wVector  start,
wVector  end,
bool  onlyClosest,
const QSet< PhyObject * > &  ignoredObjs = QSet<PhyObject*>() 
)

Returns the bodyes which intersect the ray from start to end.

Parameters
startthe starting point of the ray (in the global frame of reference)
endthe ending point of the ray (in the global frame of reference)
onlyClosestif true only the object closest to the ray start is returned, otherwise all objects which intersect the ray are returned
ignoredObjsthe set of objects to ignore when checking collisions. They are never inserted in returned list of intersected objects. This means that if onlyClosest is true, the first colliding object that doesn't belong to this set is returned
Returns
the list of objects intersected by the ray. If onlyClosest is true the list contains at most one object (the intersected one closest to the ray start). If no object is intersected by the ray, an empty list is returned

Definition at line 623 of file world.cpp.

Referenced by SingleIR::update().

Member Data Documentation

real gforce
protected

Gravity Force.

Definition at line 423 of file world.h.

Referenced by World::gravityForce(), World::setGravityForce(), and World::World().

QLinkedList<PhyJoint*> jointsv
protected

Vector of Joints inside the World.

See objs description for an explanation of why we use QLinkedList.

Definition at line 439 of file world.h.

Referenced by World::advance(), World::joints(), and World::~World().

QHash<WObject*, QList<PhyJoint*> > mapObjJoints
protected

Map object -> joints.

Definition at line 441 of file world.h.

Referenced by World::mapObjectsToJoints().

wVector minP
protected

Size of the Newton world.

Definition at line 425 of file world.h.

Referenced by World::setSize(), World::size(), and World::World().

QLinkedList<WObject*> objs
protected

Vector of WObject inside the World.

Here we use QLinkedList because we need to modify the list while iterating on it. It could happend that during World destruction we destroy an object that owns other objects which follow it in the list. In this situation the destructor of the object would take care of destroying owned objects. Owned objects destructors would then call popObject() which must be able to remove the object from this list, otherwise World destructor would try to access already freed objects. If instead owned objects precede their owner they are automatically skipped

Definition at line 435 of file world.h.

Referenced by World::advance(), World::getObject(), World::objects(), and World::~World().

real time
protected

The elapsed simulation-time from last calls of initialize()

Definition at line 419 of file world.h.

Referenced by World::advance(), World::advanceUntil(), World::elapsedTime(), World::initialize(), World::resetElapsedTime(), and World::World().

real timestepv
protected

The time step.

Definition at line 421 of file world.h.

Referenced by World::advance(), World::setTimeStep(), World::timeStep(), and World::World().


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