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.
 
void finalize ()
 Operation performed at the end of the simulation.
 
void initialize ()
 Initialize the World, it doesn't do anything if it's already initialized.
 
void pause ()
 Pause the World.
 
int play ()
 run the World calling advance as fast as possibile (return the timerId)
 
void stop ()
 Stop the World.
 

Signals

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

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

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 222 of file world.h.

Member Enumeration Documentation

anonymous enum

Custom Event Types.

Definition at line 450 of file world.h.

enum w_state

define the state of the World

Definition at line 372 of file world.h.

Constructor & Destructor Documentation

World ( QString  worldname,
bool  LocalYarpPorts = false 
)

Constructor.

Parameters
worldnameis the reference name for the World, in particular it will be the root yarp port for all YarpObject (Devices) contained into this world
LocalYarpPortsset a boolean variable that setup YARP network in local mode if true

Definition at line 156 of file world.cpp.

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

~World ( )
virtual

Destructor.

Definition at line 203 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 242 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 377 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 549 of file world.cpp.

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

Referenced by World::smartCheckContacts().

void cleanUpMemory ( )

Clean up memory.

Definition at line 525 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 673 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 622 of file world.cpp.

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

const contactMap & contacts ( )

return the contact map

Definition at line 545 of file world.cpp.

void customEvent ( QEvent *  e)
protected

Custom Events.

Definition at line 314 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 408 of file world.cpp.

real elapsedTime ( ) const

Get the elapsed time.

Definition at line 339 of file world.cpp.

References World::time.

void enableCollision ( PhyObject obj1,
PhyObject obj2 
)

Enable collision.

Definition at line 413 of file world.cpp.

void finalize ( )
slot

Operation performed at the end of the simulation.

Definition at line 276 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 392 of file world.cpp.

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

real gravityForce ( ) const

Return the gravity force.

Definition at line 373 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 229 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 351 of file world.cpp.

const QLinkedList< PhyJoint * > joints ( )

Return the vector of joints present in this world.

Definition at line 400 of file world.cpp.

References World::jointsv.

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

Map object -> joints.

Definition at line 404 of file world.cpp.

References World::mapObjJoints.

MaterialDB& materials ( )
inline

return the MaterialDB object for managing World's materials

Definition at line 335 of file world.h.

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

QString name ( ) const

Return the name.

Definition at line 225 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 388 of file world.cpp.

References World::objs.

Referenced by RenderWObjectContainer::resourceChanged().

void pause ( )
slot

Pause the World.

Definition at line 292 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 284 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 343 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 428 of file world.cpp.

void setGravityForce ( real  g)

Set the gravity force.

Definition at line 369 of file world.cpp.

References World::gforce.

void setIsRealTime ( bool  b)

Enable/Disable Real-time advance.

Definition at line 347 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 359 of file world.cpp.

void setMultiThread ( int  numThreads)

Set the multi-thread functionality.

Definition at line 438 of file world.cpp.

References farsa::max().

void setSize ( const wVector minPoint,
const wVector maxPoint 
)

See Physic Engine Documentation.

Definition at line 445 of file world.cpp.

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

void setSolverModel ( QString  model)

See Physic Engine Documentation.

Definition at line 418 of file world.cpp.

void setTimeStep ( real  ts)

Set the time step.

Definition at line 355 of file world.cpp.

References World::timestepv.

void size ( wVector minPoint,
wVector maxPoint 
)

Get the bounding box of the world.

Definition at line 454 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 591 of file world.cpp.

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

w_state status ( )
inline

return the actual state

Definition at line 374 of file world.h.

void stop ( )
slot

Stop the World.

Definition at line 300 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 309 of file world.cpp.

References World::advance().

real timeStep ( ) const
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 646 of file world.cpp.

Referenced by SingleIR::update().

Member Data Documentation

real gforce
protected

Gravity Force.

Definition at line 424 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 440 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 442 of file world.h.

Referenced by World::mapObjectsToJoints().

wVector minP
protected

Size of the Newton world.

Definition at line 426 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 436 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 420 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 422 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: