# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Hello World why does it go down?Posted: Thu Nov 08, 2012 2:06 pm

Joined: Thu Nov 08, 2012 2:03 pm
Posts: 12
In the hello world demo,there is an dynamic rigidbody.When i run the demo,I can see the y value of it getting lower and lower.

I thought it had something to do with gravity.But if I set the default y value to -56,IT STILL Goes down!

Why is it going down?!

Top

 Post subject: Re: Hello World why does it go down?Posted: Thu Nov 08, 2012 9:03 pm

Joined: Thu Nov 08, 2012 8:51 pm
Posts: 6
It isn't clear what you mean when you say you set the default y value to -56. The gravity is set on line 43.

dynamicsWorld->setGravity(btVector3(0,-10,0));

If you set the gravity to a positive y value then it will 'fall' upwards.

Top

 Post subject: Re: Hello World why does it go down?Posted: Thu Nov 08, 2012 10:24 pm

Joined: Thu Nov 08, 2012 2:03 pm
Posts: 12
Look at the output:

x 0 y -56 z 0
x 0 y -57 z 0
x 0 y -58 z 0
x 0 y -59 z 0
x 0 y -60 z 0
x 0 y -61 z 0
x 0 y -62 z 0
x 0 y -63 z 0
x 0 y -64 z 0
x 0 y -65 z 0
x 0 y -66 z 0
x 0 y -67 z 0
x 0 y -68 z 0
x 0 y -69 z 0
x 0 y -70 z 0

Gravity is set to:
dynamicsWorld->setGravity(btVector3(0,-10,0));

How is it possible to go down?! Should it get higher and higher untill it reaches -10?

Here's full code:
Code:
///-----includes_end-----

int i;
///-----initialization_start-----

///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
btCollisionDispatcher* dispatcher = new   btCollisionDispatcher(collisionConfiguration);

///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.

///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0,-10,0));

///-----initialization_end-----

///create a few basic rigid bodies
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));

//keep track of the shapes, we release memory at exit.
//make sure to re-use collision shapes among rigid bodies whenever possible!
btAlignedObjectArray<btCollisionShape*> collisionShapes;

collisionShapes.push_back(groundShape);

btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-5,0));

{
btScalar mass(0.0f);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

//add the body to the dynamics world
}

{
//create a dynamic rigidbody

//btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
btCollisionShape* colShape = new btSphereShape(btScalar(1.));
collisionShapes.push_back(colShape);

/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,-56,0));

btScalar   mass(1.f);

//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);

btVector3 localInertia(0,0,0);
if (isDynamic)
colShape->calculateLocalInertia(mass,localInertia);

//startTransform.setOrigin(btVector3(2,10,0));

//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

}

/// Do some simulation

///-----stepsimulation_start-----
for (i=0;i<100;i++)
{
dynamicsWorld->stepSimulation(1.f/60.f,10);

//print positions of all objects
for (int j=dynamicsWorld->getNumCollisionObjects()-1; j>=0 ;j--)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
btTransform trans;
body->getMotionState()->getWorldTransform(trans);

printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
}
}
}

Top

 Post subject: Re: Hello World why does it go down?Posted: Thu Nov 08, 2012 11:22 pm

Joined: Thu Nov 08, 2012 8:51 pm
Posts: 6
The gravity is a force with direction and magnitude. The object is being pushed with a force of 10 in the -y direction. It will go down no matter where you put it, unless you change the direction of the force.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 25 guests

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

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities