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 
Offline

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]http://bulletphysics.org/mediawiki-1.5.8/index.php/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:
Code:
  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);
 
  dynamicsWorld->setGravity(btVector3(0,-10,0));
 
  btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
 
  btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
  btRigidBody::btRigidBodyConstructionInfo
          groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
  btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
  dynamicsWorld->addRigidBody(groundRigidBody);
 
  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);
  fallShape->calculateLocalInertia(mass,fallInertia);
  btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
  btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
  dynamicsWorld->addRigidBody(fallRigidBody);
 
  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:
Code:
float dt = (btScalar)m_clock.getTimeMicroseconds()  * 0.000001f;
m_clock.reset();
dynamicsWorld->stepSimulation(dt);
btTransform trans;
fallRigidBody->getMotionState()->getWorldTransform(trans);

glBegin(GL_LINES); //Draw our plane
glVertex3f(-1,0,0);
glVertex3f(1,0,0);
glEnd();
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):
Code:
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.


Attachments:
project2.cpp [5.2 KiB]
Downloaded 96 times
Top
 Profile  
 
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], Yahoo [Bot] and 7 guests


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