98 btVector3 aabbMin,aabbMax;
103 const btTransform *mainTransform;
104 btRigidBody* rbody = 0;
105 btSoftBody* sbody = 0;
112 if( colObj->getInternalType() == btCollisionObject::CO_RIGID_BODY ) {
114 rbody = btRigidBody::upcast(colObj);
119 mainTransform = &(colObj->getWorldTransform());
121 mainTransform->getOpenGLMatrix( m );
122 qRot = mainTransform->getRotation();
123 rot = mainTransform->getBasis();
124 orig = mainTransform->getOrigin();
133 else if ( colObj->getInternalType() == btCollisionObject::CO_SOFT_BODY )
136 sbody = btSoftBody::upcast(colObj);
143 mainTransform->getOpenGLMatrix( m );
144 qRot = mainTransform->getRotation();
145 rot = mainTransform->getBasis();
146 orig = mainTransform->getOrigin();
148 for(
int n=0; n<sbody->m_faces.size(); n++)
151 btSoftBody::Node* node_0=sbody->m_faces[n].m_n[0];
152 btSoftBody::Node* node_1=sbody->m_faces[n].m_n[1];
153 btSoftBody::Node* node_2=sbody->m_faces[n].m_n[2];
179 Matrix3f
id = Matrix3f::Identity();
225 btTransform &t1=joint->getRigidBodyA().getWorldTransform();
226 btTransform &t2=joint->getRigidBodyB().getWorldTransform();
228 if( joint->getConstraintType() == HINGE_CONSTRAINT_TYPE )
235 else if( joint->getConstraintType() == CONETWIST_CONSTRAINT_TYPE )
237 pivot1 = t1 * ((btConeTwistConstraint *)joint)->getAFrame();
239 pivot2 = t2 * ((btConeTwistConstraint *)joint)->getBFrame();
242 else if( joint->getConstraintType() == SLIDER_CONSTRAINT_TYPE )
244 pivot1 = t1 * ((btSliderConstraint *)joint)->getFrameOffsetA();
246 pivot2 = t2 * ((btSliderConstraint *)joint)->getFrameOffsetB();
249 else if( joint->getConstraintType() == D6_CONSTRAINT_TYPE )
251 pivot1 = t1 * ((btGeneric6DofConstraint *)joint)->getFrameOffsetA();
253 pivot2 = t2 * ((btGeneric6DofConstraint *)joint)->getFrameOffsetB();
270 const btTransform& startTransform,
271 btCollisionShape* shape,
272 const btVector3 &color_,
281 bool is_empty_pixmap = pixmap.
getData()==0;
284 switch( shape->getShapeType() )
287 case STATIC_PLANE_PROXYTYPE:
289 const btStaticPlaneShape* staticPlaneShape =
290 static_cast<const btStaticPlaneShape*
>(shape);
291 btScalar planeConst =
292 staticPlaneShape->getPlaneConstant();
293 const btVector3& planeNormal =
294 staticPlaneShape->getPlaneNormal();
295 btVector3 planeOrigin =
296 planeNormal * planeConst;
298 btPlaneSpace1(planeNormal,vec0,vec1);
314 case BOX_SHAPE_PROXYTYPE:
316 const btBoxShape* boxShape =
317 static_cast<const btBoxShape*
>(shape);
318 btVector3 halfExtent =
319 boxShape->getHalfExtentsWithMargin();
320 Vector3f glHalfExtent =
332 case SPHERE_SHAPE_PROXYTYPE:
334 const btSphereShape* sphereShape =
335 static_cast<const btSphereShape*
>(shape);
336 float radius = sphereShape->getMargin();
348 if( shape->isConvex())
350 const btConvexShape* convexShape =
351 static_cast<const btConvexShape*
>(shape);
353 btShapeHull hull(convexShape);
355 if(hull.buildHull(convexShape->getMargin()))
358 const btVector3* btvtx = hull.getVertexPointer();
359 const unsigned int* idx = hull.getIndexPointer();
360 std::vector<Vector3f> vtx(hull.numVertices());
362 for(
int x=0; x< hull.numVertices(); x++)
393 const btVector3 &color_,
398 float mass = (body->getInvMass() >0 ) ? 1.0/(body->getInvMass()): 0;
400 const btTransform& startTransform = body->getCenterOfMassTransform();
402 btCollisionShape* shape = body->getCollisionShape();
406 bool is_empty_pixmap = pixmap.
getData()==0;
409 switch( shape->getShapeType() )
412 case STATIC_PLANE_PROXYTYPE:
414 const btStaticPlaneShape* staticPlaneShape =
415 static_cast<const btStaticPlaneShape*
>(shape);
416 btScalar planeConst =
417 staticPlaneShape->getPlaneConstant();
418 const btVector3& planeNormal =
419 staticPlaneShape->getPlaneNormal();
420 btVector3 planeOrigin =
421 planeNormal * planeConst;
423 btPlaneSpace1(planeNormal,vec0,vec1);
439 case BOX_SHAPE_PROXYTYPE:
441 const btBoxShape* boxShape =
442 static_cast<const btBoxShape*
>(shape);
443 btVector3 halfExtent =
444 boxShape->getHalfExtentsWithMargin();
445 Vector3f glHalfExtent =
457 case SPHERE_SHAPE_PROXYTYPE:
459 const btSphereShape* sphereShape =
460 static_cast<const btSphereShape*
>(shape);
461 float radius = sphereShape->getMargin();
473 if( shape->isConvex())
475 const btConvexShape* convexShape =
476 static_cast<const btConvexShape*
>(shape);
478 btShapeHull hull(convexShape);
480 if(hull.buildHull(convexShape->getMargin()))
483 const btVector3* btvtx = hull.getVertexPointer();
484 const unsigned int* idx = hull.getIndexPointer();
485 std::vector<Vector3f> vtx(hull.numVertices());
487 for(
int x=0; x< hull.numVertices(); x++)
521 btCollisionShape* shape,
522 const btVector3 &color_,
531 bool is_empty_pixmap = pixmap.
getData()==0;
548 const btVector3 &color_,
555 bool is_empty_pixmap = pixmap.
getData()==0;
576 btTransform local_transform,
577 std::string screenTitle,
613 data.
m_bcOrigin = local_transform.getOrigin();
615 local_transform.getOrigin() +
616 local_transform.getBasis() * btVector3(target,0,0);
617 data.
m_bcUp = local_transform.getBasis() * up;
649 mainTransform.getBasis() * data.
m_bcUp );
662 return Eigen::Vector3f(v.x(), v.y(), v.z());
667 return btVector3(v.x(), v.y(), v.z());
A custom HingeConstraint Class.
btMatrix3x3 eigen2btMat(const Eigen::Matrix3f &v)
Computational Embodied Neuroscience Simulator library.
btSoftBody * localCreateSoftBody(float mass, btCollisionShape *shape, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
void drawLine(const Vector3f &v1, const Vector3f &v2, const Vector3f color)
btSoftRigidDynamicsWorld * m_phDynamicsWorld
void drawAxis(const Vector3f &origin, const Matrix3f &rotation, float length)
std::vector< CENSCamera * > m_grCameras
bool m_grCameraAxisEnabled
btRigidBody * localImportRigidBody(btRigidBody *body, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
CENSGraphics * cens_graphics
CENSPixelMap CENS_NULL_PIXMAP
Graphic processing of an object.
void buildAsConvex(const Vertices &vertices, const unsigned int *idx, int nvtxs, int nidxs, int ntrns, const TexCoords &texCoords=CENS_NULL_TEXCOORDS, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
void buildAsSphere(float radius, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
virtual void stepToStepLoop()
CENSCamera m_grViewCamera
std::vector< Vector2f > TexCoords
virtual void syncAttachedCamera(int index)
std::vector< CENSGraphicsShape * > m_grShapes
btSoftBody * localLinkSoftBody(btSoftBody *body, const btVector3 &color=eigen2btVec(CENS_NULL_COLOR), const TexCoords &texCoords=CENS_NULL_TEXCOORDS, CENSPixelMap &pixmap=CENS_NULL_PIXMAP)
void focusCamera(int camera_index)
Eigen::Matrix3f btMat2eigen(const btMatrix3x3 &v)
virtual void initCENSGraphics(int argc, char **argv)
virtual void cens_physics_step()
virtual btSoftBody * localCreateSoftBody(float mass, btCollisionShape *shape)
Vector3f m_grCapsuleColor
btVector3 eigen2btVec(const Eigen::Vector3f &v)
void initCamera(CENSCamera &camera, CENSLight light)
virtual void step(int value)
void buildAsPlane(const Vector3f &orig, const Vector3f &v1, const Vector3f &v2, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
virtual void init(int argc, char **argv)
std::string m_cScreenTitle
Use a byte vector as a matrix.
btTransform m_bcLocal_transform
virtual btRigidBody * localCreateRigidBody(float mass, const btTransform &startTransform, btCollisionShape *shape)
bool m_grObjectAxesEnabled
virtual void initObjects()
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)
std::vector< CENSCamera * > m_grEyeCameras
const GLubyte * getData() const
bool m_grJointAxesEnabled
Parameters for the body-camera link.
Eigen::Vector3f btVec2eigen(const btVector3 &v)
void buildAsSoft(int numTriangles, const TexCoords &texCoords=CENS_NULL_TEXCOORDS, const Vector3f &color=CENS_NULL_COLOR, CENSPixelMap pixmap=CENS_NULL_PIXMAP)
std::vector< CENSBodyCameraData > m_eAttachedCameras
btTransform & getTransformFromBody(btRigidBody *body)
virtual void step(int ts)
void buildAsBox(const Vector3f &halfExtents, const Vector3f &color=CENS_NULL_COLOR, 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)