Hi, all.
I'm new to Bullet, and this is my first post on this forum.
I'm working on a robot application in which I have to make simulations with its 3D model. The robot consists of several links and joints, every one of them has its corresponding parent-child transformation. Attached you can see a sample screenshot of how it looks like. You can see that there are several hydraulic cylinders whose mission is to force the movement of each joint. For the purpose and question of the message, forget by now the vehicle and the chains, just please focus on the robot arm.
My first aim is to detect collisions (without physical behaviour). I mean, I will move the joints by myself and if any link collide with another, an alarm will be generated. Maybe is not needed too much precision, because I don't want the collision to happen, I just want to shoot the alarm when a certain distance threshold is exceeded.
I have the following question:
- What kind of collision shape would be the best option for each link? For the most of them, maybe is not needed to create an exact concave Compound Shape, but I think a Convex Hull Shape would be enough (taking into account that is not needed to detect contacts accurately).
Also, I made a test with an own-made convex hull, but it doesn't work:
I have create a HelloWorld program from one of the demos. In the first version it consisted of a simple box dropped over a static bigger one. I changed the falling shape for a simple convex object using btConvexHullShape. The graphics representation is performed using OpenGL, but I haven't changed the displaying falling object yet (it is still a simple box, instead of my own-made convex shape). The problem I get is that the falling object doesn't move, it still remains at the origin position. I attached the program code for your review. What am I doing wrong?
Thank you very much,
Francisco
----- C++ code -----
#include <stdlib.h>
#include <iostream>
#include <GL/glut.h>
#include "btBulletDynamicsCommon.h"
using std::cout;
using std::endl;
static float mytime = 0.0;
static btScalar matrix[16];
static btTransform trans;
static btScalar vertexes[36]={-2.5,-2.5,0,-2.5,2.5,0,-.25,-1.5,10,
-.25,1.5,10,.25,1.5,10,.25,-1.5,10,
2.5,2.5,0,2.5,-2.5,0,-2,-.5,-4,
-2,.5,-4,2,-.5,-4,2,.5,-4};
static btDiscreteDynamicsWorld* dynamicsWorld;
static btCollisionShape *groundShape;
static btCollisionShape *fallShape;
static btDefaultMotionState* fallMotionState;
static btDefaultMotionState* groundMotionState;
static btRigidBody *groundRigidBody, *fallRigidBody;
static void draw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//*** draw groundShape
glColor3f(0.0, 0.0, 1.0);
glPushMatrix();
groundRigidBody->getMotionState()->getWorldTransform(trans);
trans.getOpenGLMatrix(matrix);
glMultMatrixf(matrix);
glutSolidCube(40);
glPopMatrix();
//*** draw fallShape
glColor3f(1.0, 1.0, 0.0);
glPushMatrix();
fallRigidBody->getMotionState()->getWorldTransform(trans);
trans.getOpenGLMatrix(matrix);
glMultMatrixf(matrix);
glutSolidCube(10); /* falling shape represented is the old box, not the new convex shape */
glPopMatrix();
glutSwapBuffers();
}
static void timer(void)
{
float dtime = mytime;
mytime = glutGet(GLUT_ELAPSED_TIME) / 500.0;
dtime = mytime - dtime;
if(dynamicsWorld)
dynamicsWorld->stepSimulation(dtime, 10);
std::cout << mytime << "\t" << trans.getOrigin().getY() << std::endl;
glutPostRedisplay();
}
int main(int argc, char** argv)
{
//*** init Bullet Physics
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
int maxProxies = 1024;
btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-20,0));
btQuaternion qtn;
// FIRST SHAPE (STATIC)
groundShape = new btBoxShape(btVector3(20,20,20));
trans.setIdentity();
qtn.setEuler(0.1, 0.3, 0.9);
trans.setRotation(qtn);
trans.setOrigin(btVector3(0, 0, 0));
groundMotionState = new btDefaultMotionState(trans);
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
// SECOND SHAPE (MOVING CONVEXHULL)
//fallShape = new btBoxShape(btVector3(5,5,5)); /* Old falling shape */
fallShape = new btConvexHullShape(vertexes,12); /* New falling shape */
trans.setIdentity();
qtn.setEuler(0.1, 0.9, 0.2);
trans.setRotation(qtn);
trans.setOrigin(btVector3(0, 70, 0));
fallMotionState = new btDefaultMotionState(trans);
btScalar mass = 1;
btVector3 fallInertia(0,0,0);
fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
fallRigidBody = new btRigidBody(fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
//*** init GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Jumpin' little BoX");
glutDisplayFunc(draw);
glutIdleFunc(timer);
//*** init OpenGL
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glMatrixMode(GL_PROJECTION);
gluPerspective( 50.0, 1.0, 20.0, 100.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0.0, 30.0, 90.0, 0.0, 30.0, 0.0, 0.0, 1.0, 0.0);
glutMainLoop();
//*** EXIT
dynamicsWorld->removeRigidBody(fallRigidBody);
delete fallRigidBody->getMotionState();
delete fallRigidBody;
dynamicsWorld->removeRigidBody(groundRigidBody);
delete groundRigidBody->getMotionState();
delete groundRigidBody;
delete fallShape;
delete groundShape;
delete dynamicsWorld;
delete solver;
delete collisionConfiguration;
delete dispatcher;
delete broadphase;
return 0;
}
New to Bullet. Creating a ConvexHullShape
-
- Posts: 15
- Joined: Tue Oct 13, 2009 2:49 pm
New to Bullet. Creating a ConvexHullShape
You do not have the required permissions to view the files attached to this post.
-
- Posts: 15
- Joined: Tue Oct 13, 2009 2:49 pm
Re: New to Bullet. Creating a ConvexHullShape
Hi, again.
Attached you can see a 3D model of the convex shape I made.
I have tried using btConvexHullShape with simpler shapes with less number of vertexes, like a box, and it works, but with this one I attach here it still remains without moving. Is it needed to give the vertexes vector in a certain appropriate order?
Thanks,
Francisco
Attached you can see a 3D model of the convex shape I made.
I have tried using btConvexHullShape with simpler shapes with less number of vertexes, like a box, and it works, but with this one I attach here it still remains without moving. Is it needed to give the vertexes vector in a certain appropriate order?
Thanks,
Francisco
You do not have the required permissions to view the files attached to this post.