![]() |
Computational Embodied Neuroscience Simulator
1.1
3D simulation library
|
Initializing and manipulating physics objects. More...
#include <cens_engine.h>
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) |
![]() | |
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 CENSTouchSensor * | addTouchSensor (btRigidBody *body) |
btScalar | getStep () |
btScalar | getSubstep () |
Vector3f | getGravity () |
![]() | |
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 CENSPixelMap & | getCameraPixelMap (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) |
![]() | |
btTransform & | getTransformFromBody (btRigidBody *body) |
btTransform & | getTransformFromBody (btSoftBody *body) |
![]() | |
void | beginRendering () |
void | endRendering () |
void | initTextures () |
void | initTexture (const GLubyte *source=0, int width=0, int height=0) |
Additional Inherited Members | |
![]() | |
static CENSNonCollidingTable | m_phNonCollidingTable |
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.
cens::CENSEngine::CENSEngine | ( | ) |
Definition at line 35 of file cens_engine.cpp.
References cens::cens_graphics.
|
virtual |
Definition at line 57 of file cens_engine.cpp.
|
virtual |
Attach a camera to a body
body | The attached body |
local_transform | transform of the camera |
screenTitle | target view point |
screenWidth | width of screen view |
screenHeight | height of screen view |
screenXGap | horizontal screen position of view |
screenYGap | vertical screen position of view |
up | Up vector of the camera |
target | target view point |
foV | field of view |
near | near plane |
far | far plane |
Definition at line 574 of file cens_engine.cpp.
References cens::CENSGraphics::initCamera(), cens::CENSEngine::CENSBodyCameraData::m_bcBody, cens::CENSEngine::CENSBodyCameraData::m_bcIdx, cens::CENSEngine::CENSBodyCameraData::m_bcLocal_transform, cens::CENSEngine::CENSBodyCameraData::m_bcOrigin, cens::CENSEngine::CENSBodyCameraData::m_bcTarget, cens::CENSEngine::CENSBodyCameraData::m_bcUp, cens::CENSGraphics::CENSCamera::m_cDistance, cens::CENSGraphics::CENSCamera::m_cFar, cens::CENSGraphics::CENSCamera::m_cFoV, cens::CENSGraphics::CENSCamera::m_cHeight, cens::CENSGraphics::CENSCamera::m_cNear, cens::CENSGraphics::CENSCamera::m_cScreenHeight, cens::CENSGraphics::CENSCamera::m_cScreenTitle, cens::CENSGraphics::CENSCamera::m_cScreenWidth, cens::CENSGraphics::CENSCamera::m_cScreenXGap, cens::CENSGraphics::CENSCamera::m_cScreenYGap, m_eAttachedCameras, cens::CENSGraphics::m_grEyeCameras, cens::CENSGraphics::m_grLight, cens::CENSGraphics::m_grViewCamera, and syncAttachedCamera().
Referenced by cens::CENSSerializedEngine::addCamera().
|
virtual |
Rendering of all objects
Reimplemented from cens::CENSGraphics.
Definition at line 91 of file cens_engine.cpp.
References cens::btMat2eigen(), cens::btVec2eigen(), cens::CENSGraphics::drawAxis(), cens::CENSGraphics::drawLine(), cens::CENSPhysics::getTransformFromBody(), cens::CENSEngine::CENSBodyCameraData::m_bcBody, cens::CENSEngine::CENSBodyCameraData::m_bcIdx, cens::CENSEngine::CENSBodyCameraData::m_bcLocal_transform, cens::CENSEngine::CENSBodyCameraData::m_bcUp, cens::CENSGraphics::CENSCamera::m_cDistance, cens::CENSGraphics::CENSCamera::m_cOrigin, cens::CENSGraphics::CENSCamera::m_cTarget, m_eAttachedCameras, m_eShapes, cens::CENSGraphics::m_grAxisEnabled, cens::CENSGraphics::m_grCameraAxisEnabled, cens::CENSGraphics::m_grEyeCameras, cens::CENSGraphics::m_grJointAxesEnabled, cens::CENSGraphics::m_grObjectAxesEnabled, cens::CENSGraphics::m_grShapes, cens::CENSPhysics::m_phDynamicsWorld, and syncAttachedCamera().
|
virtual |
Initialize cens_graphics and cens_physics.
argc | arguments' number (for glutMainLoop). |
argv | arguments' 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.
|
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.
mass | weight of the body. Zero mass equals to a body having a fixed position in space. |
startTransform | initial rotation and translation. |
shape | shape of the body. |
color | color of the body. |
texCoords | UV cordinates for texture. |
pixmap | image 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.
mass | weight of the body. Zero mass equals to a body having a fixed position in space. |
shape | shape of the body. |
color | color of the body. |
texCoords | UV cordinates for texture. |
pixmap | image 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 |
||
) |
Link a rigid body it to the m_phDynamicsWorld.
body | pointer to a btRigidBody |
color | color of the body. |
texCoords | UV cordinates for texture. |
pixmap | image to use for texturing the surface of the body. |
Definition at line 391 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(), m_eShapes, cens::CENSGraphics::m_grBoxColor, cens::CENSGraphics::m_grCapsuleColor, cens::CENSGraphics::m_grShapes, and cens::CENSGraphics::m_grSphereColor.
Referenced by cens::CENSSerializedEngine::loadBulletFile().
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.
body | pointer to a btRigidBody |
color | color of the body. |
texCoords | UV cordinates for texture. |
pixmap | image 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.
|
virtual |
Start the simulation.
Definition at line 76 of file cens_engine.cpp.
References cens::CENSGraphics::loop().
|
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().
|
virtual |
run a single step of simulation.
Definition at line 83 of file cens_engine.cpp.
References cens::CENSGraphics::stepToStepLoop().
|
protectedvirtual |
synchronize the camera position with the body position
index | Index of the camera |
Definition at line 631 of file cens_engine.cpp.
References cens::btVec2eigen(), cens::CENSPhysics::getTransformFromBody(), cens::CENSEngine::CENSBodyCameraData::m_bcBody, cens::CENSEngine::CENSBodyCameraData::m_bcIdx, cens::CENSEngine::CENSBodyCameraData::m_bcOrigin, cens::CENSEngine::CENSBodyCameraData::m_bcTarget, cens::CENSEngine::CENSBodyCameraData::m_bcUp, cens::CENSGraphics::CENSCamera::m_cOrigin, cens::CENSGraphics::CENSCamera::m_cTarget, cens::CENSGraphics::CENSCamera::m_cUp, m_eAttachedCameras, and cens::CENSGraphics::m_grEyeCameras.
Referenced by attachCamera(), and display().
|
protected |
Store of the attached cameras
Definition at line 251 of file cens_engine.h.
Referenced by attachCamera(), display(), and syncAttachedCamera().
|
protected |
shapes mapped to bodies
Definition at line 248 of file cens_engine.h.
Referenced by display(), localCreateRigidBody(), localCreateSoftBody(), localImportRigidBody(), and localLinkSoftBody().