Physics Simulation Forum


All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue May 29, 2012 1:29 pm 

Joined: Tue May 29, 2012 1:02 pm
Posts: 1
First of all, great work on the library.
Now, I am not a native c++ programmer (tried everything for a while before c/c++) so my code might have errors that it probably shouldn't.
I tried the [url=Hello World][/url] example in regards to setting up a plane and a sphere dropping on it, to test out some settings, but instead of using a fixed loop, I inserted it into a simple opengl program, which renders only a line for the plane and the dropping sphere.

My code to initialize bullet is:
  btBroadphaseInterface* broadphase = new btDbvtBroadphase();
  btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
  btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
  btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
  btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
  btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
  btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
  btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
  btCollisionShape* fallShape = new btSphereShape(0.10f);

  btDefaultMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
  btScalar mass = 0.10f;
  btVector3 fallInertia(0,0,0);
  btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
  btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
  dynamicsWorld->getDispatchInfo().m_allowedCcdPenetration = 0.0001f;

(I saw the last line on the forum somewhere that should have fixed my problem, but didn't)

And the code inside my loop is:
float dt = (btScalar)m_clock.getTimeMicroseconds()  * 0.000001f;
btTransform trans;

glBegin(GL_LINES); //Draw our plane
drawSphere(0.10f, 30, 30, trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ());

where drawSphere is (simply draw a sphere of a specific radius center on a chosen location, copied the code from one of the bullet samples):
void drawSphere(btScalar radius, int lats, int longs, btScalar _x, btScalar _y, btScalar _z)

Now my problem, during the simulation the sphere when it first hits the plane it will go all the way through (up to a height between -1 and -2) before it bounces and then on the second hit it goes up to -0.1 before resting at 0.1 (radius of the sphere). How can I fix it and make it react more realistically ?
I compiled bullet and the sample in both mingw32 and visual studio 2010 with the same effect.

project2.cpp [5.2 KiB]
Downloaded 120 times
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Google [Bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group