Privacy
An open-source, flexible 3D physical simulation framework
mars::sim::WorldPhysics Class Reference

Declaration of the physical class, that implements the physics interface. More...

#include <WorldPhysics.h>

Public Member Functions

 WorldPhysics (interfaces::ControlCenter *control)
 The constructor for the physical world. More...
 
virtual ~WorldPhysics (void)
 Close ODE environment. More...
 
virtual void initTheWorld (void)
 This function initializes the ode world. More...
 
virtual void freeTheWorld (void)
 This functions destroys the ode world. More...
 
virtual void stepTheWorld (void)
 This function handles the calculation of a step in the world. More...
 
virtual bool existsWorld (void) const
 Returns if a world exists. More...
 
virtual const utils::Vector getCenterOfMass (const std::vector< interfaces::NodeInterface *> &nodes) const
 
virtual void update (std::vector< interfaces::draw_item > *drawItems)
 This is the update function that updates the position of the vertices of all draw_item structs contained in drawItems. More...
 
virtual int checkCollisions (void)
 
virtual interfaces::sReal getVectorCollision (const utils::Vector &pos, const utils::Vector &ray) const
 
dWorldID getWorld (void) const
 Returns the ode ID of the world object. More...
 
dSpaceID getSpace (void) const
 Returns the ode ID of the main space object. More...
 
bool getCompositeBody (int comp_group, dBodyID *body, NodePhysics *node)
 Sets the body pointer param to the body for the comp_group_id. More...
 
void destroyBody (dBodyID theBody, NodePhysics *node)
 Destroyes a body from a node: More...
 
dReal getWorldStep (void)
 Returns the stepsize for calculating a world step. More...
 
void resetCompositeMass (dBodyID theBody)
 resets the mass of a composite body More...
 
void moveCompositeMassCenter (dBodyID theBody, dReal x, dReal y, dReal z)
 
int handleCollision (dGeomID theGeom)
 
interfaces::sReal getCollisionDepth (dGeomID theGeom)
 
- Public Member Functions inherited from mars::interfaces::PhysicsInterface
virtual ~PhysicsInterface ()
 

Public Attributes

utils::Mutex iMutex
 
- Public Attributes inherited from mars::interfaces::PhysicsInterface
sReal ground_friction
 
sReal ground_cfm
 
sReal ground_erp
 
sReal step_size
 Step size in seconds. More...
 
utils::Vector world_gravity
 
bool fast_step
 
bool draw_contact_points
 
sReal world_cfm
 
sReal world_erp
 

Static Public Attributes

static interfaces::PhysicsError error = PHYSICS_NO_ERROR
 

Private Member Functions

void nearCallback (dGeomID o1, dGeomID o2)
 In this function the collision handling from ode is performed. More...
 
- Private Member Functions inherited from mars::interfaces::DrawInterface
virtual ~DrawInterface ()
 

Static Private Member Functions

static void callbackForward (void *data, dGeomID o1, dGeomID o2)
 This static function is used to project a normal function pointer to a method from a class. More...
 

Private Attributes

utils::Mutex drawLock
 
dSpaceID space
 
dWorldID world
 
dGeomID plane
 
dJointGroupID contactgroup
 
bool world_init
 
interfaces::ControlCentercontrol
 
utils::Vector old_gravity
 
interfaces::sReal old_cfm
 
interfaces::sReal old_erp
 
std::vector< body_nbr_tupelcomp_body_list
 
std::vector< interfaces::draw_itemdraw_intern
 
std::vector< interfaces::draw_itemdraw_extern
 
std::vector< dJointFeedback * > contact_feedback_list
 
bool create_contacts
 
bool log_contacts
 
int num_contacts
 
int ray_collision
 

Detailed Description

Declaration of the physical class, that implements the physics interface.

Definition at line 85 of file WorldPhysics.h.

Constructor & Destructor Documentation

◆ WorldPhysics()

mars::sim::WorldPhysics::WorldPhysics ( interfaces::ControlCenter control)

The constructor for the physical world.

pre:

  • none

post:

  • all private variables should be initialized correct should correct be spezified?
  • world, space, contactgroup and world_init to false (0)

Definition at line 85 of file WorldPhysics.cpp.

◆ ~WorldPhysics()

mars::sim::WorldPhysics::~WorldPhysics ( void  )
virtual

Close ODE environment.

pre:

  • none

post:

  • everthing that was created should be destroyed

Definition at line 131 of file WorldPhysics.cpp.

Member Function Documentation

◆ callbackForward()

void mars::sim::WorldPhysics::callbackForward ( void *  data,
dGeomID  o1,
dGeomID  o2 
)
staticprivate

This static function is used to project a normal function pointer to a method from a class.

pre:

  • data is a pointer to a correct object from type WorldPhysics

post:

  • the newCallback method of the data object should be called

Definition at line 752 of file WorldPhysics.cpp.

◆ checkCollisions()

int mars::sim::WorldPhysics::checkCollisions ( void  )
virtual

Implements mars::interfaces::PhysicsInterface.

Definition at line 875 of file WorldPhysics.cpp.

◆ destroyBody()

void mars::sim::WorldPhysics::destroyBody ( dBodyID  theBody,
NodePhysics node 
)

Destroyes a body from a node:

This function checks if not more than one geom is connected to the body and destroyes the body in that case. In the other case the counter of the connected geoms is decreased.

pre:

  • the body exists in the physical world

post:

  • if more than one geoms are connected to the body, decrease the counter of connected geoms
  • otherwise, if only one geom is connected to the body, destroy the body

Definition at line 375 of file WorldPhysics.cpp.

◆ existsWorld()

bool mars::sim::WorldPhysics::existsWorld ( void  ) const
virtual

Returns if a world exists.

pre:

  • none

post:

  • return state of world_init

Implements mars::interfaces::PhysicsInterface.

Definition at line 210 of file WorldPhysics.cpp.

◆ freeTheWorld()

void mars::sim::WorldPhysics::freeTheWorld ( void  )
virtual

This functions destroys the ode world.

pre:

  • world_init = true

post:

  • world, space and contactgroup have to be destroyed here
  • afte that, world_init have to become false

Implements mars::interfaces::PhysicsInterface.

Definition at line 189 of file WorldPhysics.cpp.

◆ getCenterOfMass()

const Vector mars::sim::WorldPhysics::getCenterOfMass ( const std::vector< interfaces::NodeInterface *> &  nodes) const
virtual

Implements mars::interfaces::PhysicsInterface.

Definition at line 805 of file WorldPhysics.cpp.

◆ getCollisionDepth()

double mars::sim::WorldPhysics::getCollisionDepth ( dGeomID  theGeom)

Definition at line 844 of file WorldPhysics.cpp.

◆ getCompositeBody()

bool mars::sim::WorldPhysics::getCompositeBody ( int  comp_group,
dBodyID *  body,
NodePhysics node 
)

Sets the body pointer param to the body for the comp_group_id.

The functions sets the body pointer to the body ID that represents the composite object. If no body is aviable for the composite group a body will be created. The functions return if an body allready exists or if one had been created.

Careful with this function, bad implementation. This function should be only called if a new geom will be conected to the given body.

pre:

  • comp_group > 0

post:

  • body pointer should be set to a regular body that is in the vector comp_body_list
  • retruned true if a body was created, otherwise retruned false

Definition at line 335 of file WorldPhysics.cpp.

◆ getSpace()

dSpaceID mars::sim::WorldPhysics::getSpace ( void  ) const

Returns the ode ID of the main space object.

pre:

  • none

post:

  • space ID returned

Definition at line 311 of file WorldPhysics.cpp.

◆ getVectorCollision()

double mars::sim::WorldPhysics::getVectorCollision ( const utils::Vector pos,
const utils::Vector ray 
) const
virtual

Implements mars::interfaces::PhysicsInterface.

Definition at line 883 of file WorldPhysics.cpp.

◆ getWorld()

dWorldID mars::sim::WorldPhysics::getWorld ( void  ) const

Returns the ode ID of the world object.

pre:

  • none

post:

  • world ID returned

Definition at line 298 of file WorldPhysics.cpp.

◆ getWorldStep()

dReal mars::sim::WorldPhysics::getWorldStep ( void  )

Returns the stepsize for calculating a world step.

pre:

  • none

post:

  • the step_size value should be returned

Definition at line 414 of file WorldPhysics.cpp.

◆ handleCollision()

int mars::sim::WorldPhysics::handleCollision ( dGeomID  theGeom)

Definition at line 837 of file WorldPhysics.cpp.

◆ initTheWorld()

void mars::sim::WorldPhysics::initTheWorld ( void  )
virtual

This function initializes the ode world.

pre:

  • world_init = false

post:

  • world, space and contactgroup should be created
  • the ODE world parameters should be set
  • at the end world_init have to become true

Implements mars::interfaces::PhysicsInterface.

Definition at line 150 of file WorldPhysics.cpp.

◆ moveCompositeMassCenter()

void mars::sim::WorldPhysics::moveCompositeMassCenter ( dBodyID  theBody,
dReal  x,
dReal  y,
dReal  z 
)

Definition at line 784 of file WorldPhysics.cpp.

◆ nearCallback()

void mars::sim::WorldPhysics::nearCallback ( dGeomID  o1,
dGeomID  o2 
)
private

In this function the collision handling from ode is performed.

pre:

  • world_init = true
  • o1 and o2 are regular geoms

post:

  • if o1 or o2 was a Space, called SpaceCollide and exit
  • otherwise tested if the geoms collide and created a contact joint if so.

A lot of the code is uncommented in this function. This code maybe used later to handle sensors or other special cases in the simulation.

test if a space is colliding with something

exit without doing anything if the two bodies are connected by a joint

Definition at line 434 of file WorldPhysics.cpp.

◆ resetCompositeMass()

void mars::sim::WorldPhysics::resetCompositeMass ( dBodyID  theBody)

resets the mass of a composite body

pre:

  • the body exists in the physical world

post:

Definition at line 765 of file WorldPhysics.cpp.

◆ stepTheWorld()

void mars::sim::WorldPhysics::stepTheWorld ( void  )
virtual

This function handles the calculation of a step in the world.

pre:

  • world_init = true
  • step_size > 0

post:

  • handled the collisions
  • step the world for step_size seconds
  • the contactgroup should be empty

first clear the collision counters of all geoms

then we have to clear the contacts

first check for collisions

then calculate the next state for a time of step_size seconds

Implements mars::interfaces::PhysicsInterface.

Definition at line 226 of file WorldPhysics.cpp.

◆ update()

void mars::sim::WorldPhysics::update ( std::vector< interfaces::draw_item > *  drawItems)
virtual

This is the update function that updates the position of the vertices of all draw_item structs contained in drawItems.

Implements mars::interfaces::DrawInterface.

Definition at line 823 of file WorldPhysics.cpp.

Member Data Documentation

◆ comp_body_list

std::vector<body_nbr_tupel> mars::sim::WorldPhysics::comp_body_list
private

Definition at line 123 of file WorldPhysics.h.

◆ contact_feedback_list

std::vector<dJointFeedback*> mars::sim::WorldPhysics::contact_feedback_list
private

Definition at line 126 of file WorldPhysics.h.

◆ contactgroup

dJointGroupID mars::sim::WorldPhysics::contactgroup
private

Definition at line 117 of file WorldPhysics.h.

◆ control

interfaces::ControlCenter* mars::sim::WorldPhysics::control
private

Definition at line 119 of file WorldPhysics.h.

◆ create_contacts

bool mars::sim::WorldPhysics::create_contacts
private

Definition at line 127 of file WorldPhysics.h.

◆ draw_extern

std::vector<interfaces::draw_item> mars::sim::WorldPhysics::draw_extern
private

Definition at line 125 of file WorldPhysics.h.

◆ draw_intern

std::vector<interfaces::draw_item> mars::sim::WorldPhysics::draw_intern
private

Definition at line 124 of file WorldPhysics.h.

◆ drawLock

utils::Mutex mars::sim::WorldPhysics::drawLock
private

Definition at line 113 of file WorldPhysics.h.

◆ error

PhysicsError mars::sim::WorldPhysics::error = PHYSICS_NO_ERROR
static

Definition at line 110 of file WorldPhysics.h.

◆ iMutex

utils::Mutex mars::sim::WorldPhysics::iMutex
mutable

Definition at line 108 of file WorldPhysics.h.

◆ log_contacts

bool mars::sim::WorldPhysics::log_contacts
private

Definition at line 127 of file WorldPhysics.h.

◆ num_contacts

int mars::sim::WorldPhysics::num_contacts
private

Definition at line 128 of file WorldPhysics.h.

◆ old_cfm

interfaces::sReal mars::sim::WorldPhysics::old_cfm
private

Definition at line 121 of file WorldPhysics.h.

◆ old_erp

interfaces::sReal mars::sim::WorldPhysics::old_erp
private

Definition at line 121 of file WorldPhysics.h.

◆ old_gravity

utils::Vector mars::sim::WorldPhysics::old_gravity
private

Definition at line 120 of file WorldPhysics.h.

◆ plane

dGeomID mars::sim::WorldPhysics::plane
private

Definition at line 116 of file WorldPhysics.h.

◆ ray_collision

int mars::sim::WorldPhysics::ray_collision
private

Definition at line 129 of file WorldPhysics.h.

◆ space

dSpaceID mars::sim::WorldPhysics::space
private

Definition at line 114 of file WorldPhysics.h.

◆ world

dWorldID mars::sim::WorldPhysics::world
private

Definition at line 115 of file WorldPhysics.h.

◆ world_init

bool mars::sim::WorldPhysics::world_init
private

Definition at line 118 of file WorldPhysics.h.


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