I have tried to run the code with bullet physics library without using cmake and have been following this
http://dementedvice.wordpress.com/2013/ ... udio-2012/
everything went well with no errors but when I run it it shows no any output. how to see the output of the program???
#include "stdafx.h"
#include "btBulletDynamicsCommon.h"
int _tmain(int argc, _TCHAR* argv[]){
btBoxShape * box = new btBoxShape(btVector3(1,1,1));
delete box;
return 0;
}
output not shown with bullet physics library
-
- Posts: 225
- Joined: Wed Jan 07, 2009 11:43 am
- Location: London
Re: output not shown with bullet physics library
I'm not sure what you're expecting to see from that example? - you're creating and deleting a collision shape, thats all. Theres no code to setup a physics world, add objects or step the simulation. Looking at that example web page I think they're just testing for general compilation errors rather than anything more meaningful.
You'd be better off looking at one of the demo programs and looking at how it runs it's processing loop.
You'd be better off looking at one of the demo programs and looking at how it runs it's processing loop.
-
- Posts: 48
- Joined: Thu Dec 12, 2013 4:04 pm
Re: output not shown with bullet physics library
Follow this tutorial. It'll get you up and running adding shapes and seeing things move about.
https://www.youtube.com/watch?v=wbu5MdsFYko
https://www.youtube.com/watch?v=wbu5MdsFYko
-
- Posts: 7
- Joined: Mon Feb 24, 2014 8:39 am
Re: output not shown with bullet physics library
even I tried with the code of Helloworld from this sitexexuxjy wrote:I'm not sure what you're expecting to see from that example? - you're creating and deleting a collision shape, thats all. Theres no code to setup a physics world, add objects or step the simulation. Looking at that example web page I think they're just testing for general compilation errors rather than anything more meaningful.
You'd be better off looking at one of the demo programs and looking at how it runs it's processing loop.
http://bulletphysics.org/mediawiki-1.5. ... ello_World
but the output window blinks and disappears.
-
- Posts: 225
- Joined: Wed Jan 07, 2009 11:43 am
- Location: London
Re: output not shown with bullet physics library
how many simulation loops did you go through?
what you should be doing is:
Create physics world (DiscreteDynamicsWorld, Dispatcher, Broadphase)
create your collision shapes and rigid bodies.
add them to the world.
loop , stepping the simulation until you've reached the number of steps you want, or a key press stops the simulation, or whatever.
cleanup the world
they key point though is that by default you will not _see_ anything on the screen. if you want to see if somethings happening you could get the positions of your rigid bodies and print them out to the screen, or you could hook up a DebugDraw system so you can visualise things, but by default 'all' bullet will be doing is updating the states of the objects.
what you should be doing is:
Create physics world (DiscreteDynamicsWorld, Dispatcher, Broadphase)
create your collision shapes and rigid bodies.
add them to the world.
loop , stepping the simulation until you've reached the number of steps you want, or a key press stops the simulation, or whatever.
cleanup the world
they key point though is that by default you will not _see_ anything on the screen. if you want to see if somethings happening you could get the positions of your rigid bodies and print them out to the screen, or you could hook up a DebugDraw system so you can visualise things, but by default 'all' bullet will be doing is updating the states of the objects.
-
- Posts: 48
- Joined: Thu Dec 12, 2013 4:04 pm
Re: output not shown with bullet physics library
Try puttingLaxmi wrote: even I tried with the code of Helloworld from this site
http://bulletphysics.org/mediawiki-1.5. ... ello_World
but the output window blinks and disappears.
Code: Select all
int x;
std::cin >> x;
-
- Posts: 7
- Joined: Mon Feb 24, 2014 8:39 am
Re: output not shown with bullet physics library
xexuxjy wrote:how many simulation loops did you go through?
what you should be doing is:
Create physics world (DiscreteDynamicsWorld, Dispatcher, Broadphase)
create your collision shapes and rigid bodies.
add them to the world.
loop , stepping the simulation until you've reached the number of steps you want, or a key press stops the simulation, or whatever.
cleanup the world
they key point though is that by default you will not _see_ anything on the screen. if you want to see if somethings happening you could get the positions of your rigid bodies and print them out to the screen, or you could hook up a DebugDraw system so you can visualise things, but by default 'all' bullet will be doing is updating the states of the objects.
Thanks for your answer. I am using visual studio 2010 for running the program. here is the actual code
Code: Select all
///-----includes_start-----
#include "stdafx.h"
#include "btBulletDynamicsCommon.h"
#include <stdio.h>
/// This is a Hello World program for running a basic Bullet physics simulation
int main(int argc, char** argv)
{
///-----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.
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
///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,-56,0));
{
btScalar mass(0.);
//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
dynamicsWorld->addRigidBody(body);
}
{
//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();
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);
dynamicsWorld->addRigidBody(body);
}
/// 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()));
}
}
}
///-----stepsimulation_end-----
//cleanup in the reverse order of creation/initialization
///-----cleanup_start-----
//remove the rigidbodies from the dynamics world and delete them
for (i=dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
delete body->getMotionState();
}
dynamicsWorld->removeCollisionObject( obj );
delete obj;
}
//delete collision shapes
for (int j=0;j<collisionShapes.size();j++)
{
btCollisionShape* shape = collisionShapes[j];
collisionShapes[j] = 0;
delete shape;
}
//delete dynamics world
delete dynamicsWorld;
//delete solver
delete solver;
//delete broadphase
delete overlappingPairCache;
//delete dispatcher
delete dispatcher;
delete collisionConfiguration;
//next line is optional: it will be cleared by the destructor when the array goes out of scope
collisionShapes.clear();
///-----cleanup_end-----
}
-
- Posts: 463
- Joined: Fri Nov 30, 2012 4:50 am
Re: output not shown with bullet physics library
Display what objects, bullet is a physics library, not a graphics oneLaxmi wrote: In the output console I see the coordinates. however how can I display the object in the new windows in visual studio. Do I need to create windows form application in visual studio????
What you need is to just build the demos first and see how they work, there's also a simple OGL based rendering system set up for demos you can use too.
-
- Posts: 7
- Joined: Mon Feb 24, 2014 8:39 am
Re: output not shown with bullet physics library
I have almost build all the demos in the folder and it displays some figurative display object like box ,sphere ,floor. How can I acheive such ?? Do I need to integrate opengl with bullet to render the phsical objects??Basroil wrote:Display what objects, bullet is a physics library, not a graphics oneLaxmi wrote: In the output console I see the coordinates. however how can I display the object in the new windows in visual studio. Do I need to create windows form application in visual studio????
What you need is to just build the demos first and see how they work, there's also a simple OGL based rendering system set up for demos you can use too.
-
- Posts: 149
- Joined: Fri May 24, 2013 6:08 am
Re: output not shown with bullet physics library
You will indeed need some kind of graphics API in order to render graphics. I use Ogre, but there are many choices out there including creating your own renderer using OpenGL or DirectX
-
- Posts: 463
- Joined: Fri Nov 30, 2012 4:50 am
Re: output not shown with bullet physics library
Laxmi wrote: I have almost build all the demos in the folder and it displays some figurative display object like box ,sphere ,floor. How can I acheive such ?? Do I need to integrate opengl with bullet to render the phsical objects??
If you have problems adapting the demos I think the issue is deeper than just using bullet. I would suggest putting your project on hold until you learn the basics of game engine design, even an overview would help vastly more than people handing you code to use. The demos have everything you need to use bullet in code form, now you just need to learn how to read code and analyze it.
Just remember, bullet itself is a computation library, it calculates things to give you numbers, it's up to your other code to do something with those numbers.