Computational Embodied Neuroscience Simulator  1.1
3D simulation library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cens::CENSEngine Class Reference

Initializing and manipulating physics objects. More...

#include <cens_engine.h>

Inheritance diagram for cens::CENSEngine:
Inheritance graph
[legend]
Collaboration diagram for cens::CENSEngine:
Collaboration graph
[legend]

Classes

struct  CENSBodyCameraData
 Parameters for the body-camera link. More...
 

Public Member Functions

 CENSEngine ()
 
virtual ~CENSEngine ()
 
virtual void init (int argc, char **argv)
 
virtual void initObjects ()
 
virtual void display ()
 
virtual void step (int value)
 
virtual void run ()
 
virtual void stepRun ()
 
btRigidBody * localCreateRigidBody (float mass, const btTransform &startTransform, btCollisionShape *shape, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
 
btRigidBody * localImportRigidBody (btRigidBody *body, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
 
btSoftBody * localCreateSoftBody (float mass, btCollisionShape *shape, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
 
btSoftBody * localLinkSoftBody (btSoftBody *body, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
 
virtual int attachCamera (btRigidBody *body, btTransform local_transform, std::string screenTitle, int screenWidth, int screenHeight, int screenXGap, int screenYGap, btVector3 up, float target, float foV=70.0, float near=1.0, float far=10000)
 
- Public Member Functions inherited from cens::CENSPhysics
 CENSPhysics ()
 
virtual ~CENSPhysics ()
 
virtual void initCENSPhysics ()
 
virtual void cens_physics_step ()
 
virtual btDynamicsWorld * getDynamicsWorld ()
 
virtual btCollisionDispatcher * getDispatcher ()
 
virtual btRigidBody * localCreateRigidBody (float mass, const btTransform &startTransform, btCollisionShape *shape)
 
virtual btSoftBody * localCreateSoftBody (float mass, btCollisionShape *shape)
 
virtual void setCollisionFilter (CENSNonCollidingTable _non_colliding_table)
 
virtual CENSTouchSensoraddTouchSensor (btRigidBody *body)
 
btScalar getStep ()
 
btScalar getSubstep ()
 
Vector3f getGravity ()
 
- Public Member Functions inherited from cens::CENSGraphics
 CENSGraphics ()
 
 ~CENSGraphics ()
 
virtual void initCENSGraphics (int argc, char **argv)
 
virtual void loop ()
 
virtual void stepToStepLoop ()
 
virtual bool isIdle ()
 
virtual void quit ()
 
virtual void keyboard (unsigned char key, int x, int y)
 
void initCamera (CENSCamera &camera, CENSLight light)
 
void focusCamera (int camera_index)
 
void updateCamera (int camera_index)
 
const CENSPixelMapgetCameraPixelMap (int camera_index)
 
void saveCameraPixelMap (int camera_index, int t, const char *type="jpg")
 
void drawLine (const Vector3f &v1, const Vector3f &v2, const Vector3f color)
 
void drawPlane (const Vector3f &orig, const Vector3f &vec0, const Vector3f &vec1)
 
void drawBox (const Vector3f &orig, const Matrix3f &rotMat, const Vector3f &halfExtent)
 
void drawSphere (const Vector3f &orig, const Matrix3f &rot, float radius)
 
void drawConvex (const Vector3f &orig, const Matrix3f &rot, const std::vector< Vector3f > &vtx, const unsigned int *idx, int nvtxs, int nidxs, int ntrns)
 
void drawAxis (const Vector3f &origin, const Matrix3f &rotation, float length)
 
void drawVector (const Vector3f &v)
 
void drawTriangle (const Vector3f &v1, const Vector3f &v2, const Vector3f &v3, const Vector3f n)
 
void stepLeft ()
 
void stepRight ()
 
void stepFront ()
 
void stepBack ()
 
void zoomIn ()
 
void zoomOut ()
 
void toggleStop ()
 
void toggleTexture ()
 
void toggleAxis ()
 
void toggleObjectAxes ()
 
void toggleJointAxes ()
 
void toggleCameraAxis ()
 

Protected Member Functions

virtual void syncAttachedCamera (int index)
 
- Protected Member Functions inherited from cens::CENSPhysics
btTransform & getTransformFromBody (btRigidBody *body)
 
btTransform & getTransformFromBody (btSoftBody *body)
 
- Protected Member Functions inherited from cens::CENSGraphics
void beginRendering ()
 
void endRendering ()
 
void initTextures ()
 
void initTexture (const GLubyte *source=0, int width=0, int height=0)
 

Protected Attributes

CENSShapes m_eShapes
 
std::vector< CENSBodyCameraDatam_eAttachedCameras
 
- Protected Attributes inherited from cens::CENSPhysics
btSoftRigidDynamicsWorld * m_phDynamicsWorld
 
btAlignedObjectArray
< btCollisionShape * > 
m_phCollisionShapes
 
btAlignedObjectArray
< CENSTouchSensor * > 
m_phTouchSensors
 
btAlignedObjectArray
< btSoftSoftCollisionAlgorithm * > 
m_phSoftSoftCollisionAlgorithms
 
btAlignedObjectArray
< btSoftRididCollisionAlgorithm * > 
m_phSoftRigidCollisionAlgorithms
 
btSoftBodyWorldInfo m_phSoftBodyWorldInfo
 
btBroadphaseInterface * m_phBroadphase
 
btCollisionDispatcher * m_phDispatcher
 
btConstraintSolver * m_phSolver
 
btDefaultCollisionConfiguration * m_phCollisionConfiguration
 
btScalar m_phDefaultContactProcessingThreshold
 
Vector3f m_phGravity
 
double m_phStep
 
double m_phSubstep
 
CENSParameterManager m_phParameterManager
 
- Protected Attributes inherited from cens::CENSGraphics
int m_grTimestep
 
int m_grArgc
 
char ** m_grArgv
 
Vector3f m_grEnvColor
 
Vector3f m_grGroundColor
 
Vector3f m_grObjectColor
 
Vector3f m_grBoxColor
 
Vector3f m_grCapsuleColor
 
Vector3f m_grSphereColor
 
Vector3f m_grSoftColor
 
Vector3f m_grCompoundColor
 
bool m_grTextureEnabled
 
bool m_grTextureInitialized
 
bool m_grHide
 
CENSLight m_grLight
 
bool m_grAxisEnabled
 
bool m_grSimEnabled
 
bool m_grCameraAxisEnabled
 
bool m_grObjectAxesEnabled
 
bool m_grJointAxesEnabled
 
CENSCamera m_grViewCamera
 
int m_grEyeCameraNumber
 
std::vector< CENSCamera * > m_grEyeCameras
 
std::vector< CENSCamera * > m_grCameras
 
std::vector< CENSGraphicsShape * > m_grShapes
 
CENSParameterManager m_grParameterManager
 

Additional Inherited Members

- Static Protected Attributes inherited from cens::CENSPhysics
static CENSNonCollidingTable m_phNonCollidingTable
 

Detailed Description

Initializing and manipulating physics objects.

Graphic rendering is automatic, based on information stored in physics.

Inherits CENSGraphics and CENSPhysics.

The initObjects() and the step() methods can be overloaded in a derived class.

In the initObjects() method a model of the world can be built by initializing all bodies and joints. Pointers bodies and joints to be manipulated at run time should be declared in the header as members of the class.

In the step() method run-time you can put instructions about moving and resetting bodies and joints as well as applying forces and torques, etc. Remember to call the CENSEngine::step() method at the end of the overloaded step() method

void DerivedFromCENSEngine::step( int value) { 
...  
...
CENSEngine::step(value); 
} 

Definition at line 104 of file cens_engine.h.

Constructor & Destructor Documentation

cens::CENSEngine::CENSEngine ( )

Definition at line 35 of file cens_engine.cpp.

References cens::cens_graphics.

cens::CENSEngine::~CENSEngine ( )
virtual

Definition at line 57 of file cens_engine.cpp.

Member Function Documentation

int cens::CENSEngine::attachCamera ( btRigidBody *  body,
btTransform  local_transform,
std::string  screenTitle,
int  screenWidth,
int  screenHeight,
int  screenXGap,
int  screenYGap,
btVector3  up,
float  target,
float  foV = 70.0,
float  near = 1.0,
float  far = 10000 
)
virtual
void cens::CENSEngine::display ( )
virtual
void cens::CENSEngine::init ( int  argc,
char **  argv 
)
virtual

Initialize cens_graphics and cens_physics.

Parameters
argcarguments' number (for glutMainLoop).
argvarguments' list (for glutMainLoop).

Definition at line 43 of file cens_engine.cpp.

References cens::CENSGraphics::focusCamera(), cens::CENSGraphics::initCENSGraphics(), initObjects(), cens::CENSGraphics::initTextures(), and cens::CENSGraphics::m_grCameras.

virtual void cens::CENSEngine::initObjects ( )
inlinevirtual

All bodies and joints are created here. Connections of bodies to joints are stated also here

Reimplemented from cens::CENSPhysics.

Definition at line 117 of file cens_engine.h.

Referenced by init().

btRigidBody * cens::CENSEngine::localCreateRigidBody ( float  mass,
const btTransform &  startTransform,
btCollisionShape *  shape,
const btVector3 &  color = eigen2btVec(CENS_NULL_COLOR),
const TexCoords texCoords = CENS_NULL_TEXCOORDS,
CENSPixelMap pixmap = CENS_NULL_PIXMAP 
)

Create a rigid body and link it to the m_phDynamicsWorld.

Parameters
massweight of the body. Zero mass equals to a body having a fixed position in space.
startTransforminitial rotation and translation.
shapeshape of the body.
colorcolor of the body.
texCoordsUV cordinates for texture.
pixmapimage to use for texturing the surface of the body.

Definition at line 268 of file cens_engine.cpp.

References cens::btVec2eigen(), cens::CENSGraphicsShape::buildAsBox(), cens::CENSGraphicsShape::buildAsConvex(), cens::CENSGraphicsShape::buildAsPlane(), cens::CENSGraphicsShape::buildAsSphere(), cens::CENS_NULL_COLOR, cens::CENS_NULL_PIXMAP, cens::CENSPixelMap::getData(), cens::CENSPhysics::localCreateRigidBody(), m_eShapes, cens::CENSGraphics::m_grBoxColor, cens::CENSGraphics::m_grCapsuleColor, cens::CENSGraphics::m_grShapes, and cens::CENSGraphics::m_grSphereColor.

btSoftBody * cens::CENSEngine::localCreateSoftBody ( float  mass,
btCollisionShape *  shape,
const btVector3 &  color = eigen2btVec(CENS_NULL_COLOR),
const TexCoords texCoords = CENS_NULL_TEXCOORDS,
CENSPixelMap pixmap = CENS_NULL_PIXMAP 
)

Create a soft body and link it to the m_phDynamicsWorld.

Parameters
massweight of the body. Zero mass equals to a body having a fixed position in space.
shapeshape of the body.
colorcolor of the body.
texCoordsUV cordinates for texture.
pixmapimage to use for texturing the surface of the body.

Definition at line 519 of file cens_engine.cpp.

References cens::btVec2eigen(), cens::CENSGraphicsShape::buildAsSoft(), cens::CENS_NULL_COLOR, cens::CENS_NULL_PIXMAP, cens::CENSPixelMap::getData(), cens::CENSPhysics::localCreateSoftBody(), m_eShapes, cens::CENSGraphics::m_grShapes, and cens::CENSGraphics::m_grSoftColor.

btRigidBody * cens::CENSEngine::localImportRigidBody ( btRigidBody *  body,
const btVector3 &  color = eigen2btVec(CENS_NULL_COLOR),
const TexCoords texCoords = CENS_NULL_TEXCOORDS,
CENSPixelMap pixmap = CENS_NULL_PIXMAP 
)
btSoftBody * cens::CENSEngine::localLinkSoftBody ( btSoftBody *  body,
const btVector3 &  color = eigen2btVec(CENS_NULL_COLOR),
const TexCoords texCoords = CENS_NULL_TEXCOORDS,
CENSPixelMap pixmap = CENS_NULL_PIXMAP 
)

Link a rigid body it to the m_phDynamicsWorld.

Parameters
bodypointer to a btRigidBody
colorcolor of the body.
texCoordsUV cordinates for texture.
pixmapimage to use for texturing the surface of the body.

Definition at line 546 of file cens_engine.cpp.

References cens::btVec2eigen(), cens::CENSGraphicsShape::buildAsSoft(), cens::CENS_NULL_COLOR, cens::CENS_NULL_PIXMAP, cens::CENSPixelMap::getData(), m_eShapes, cens::CENSGraphics::m_grShapes, and cens::CENSGraphics::m_grSoftColor.

void cens::CENSEngine::run ( )
virtual

Start the simulation.

Definition at line 76 of file cens_engine.cpp.

References cens::CENSGraphics::loop().

void cens::CENSEngine::step ( int  ts)
virtual

One step of cens_graphics rendering.

Reimplemented from cens::CENSGraphics.

Reimplemented in cens::CENSSerializedEngine.

Definition at line 63 of file cens_engine.cpp.

References cens::CENSPhysics::cens_physics_step(), cens::CENSGraphics::m_grSimEnabled, and cens::CENSGraphics::step().

Referenced by cens::CENSSerializedEngine::step().

void cens::CENSEngine::stepRun ( )
virtual

run a single step of simulation.

Definition at line 83 of file cens_engine.cpp.

References cens::CENSGraphics::stepToStepLoop().

void cens::CENSEngine::syncAttachedCamera ( int  index)
protectedvirtual

Member Data Documentation

std::vector<CENSBodyCameraData> cens::CENSEngine::m_eAttachedCameras
protected

Store of the attached cameras

Definition at line 251 of file cens_engine.h.

Referenced by attachCamera(), display(), and syncAttachedCamera().

CENSShapes cens::CENSEngine::m_eShapes
protected

shapes mapped to bodies

Definition at line 248 of file cens_engine.h.

Referenced by display(), localCreateRigidBody(), localCreateSoftBody(), localImportRigidBody(), and localLinkSoftBody().


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