[Help'] Bullet Physics - Irrlicht gEngine

CHAOS-THEORY
Posts: 9
Joined: Fri Jan 25, 2013 1:46 pm

[Help'] Bullet Physics - Irrlicht gEngine

Post by CHAOS-THEORY »

Eeoo, ssup dudes
am stuck with bullet, really hard to learn but dang awsome<< ... okey i integrated it with irrlicht ( kind of -.- )
am loading an irr scene with irrlicht (a mesh which is the level or ground if u can say, and the box)
all i wanted to do is create the world, add gravity, add collision to the box + mass n all )
what i got is the box is dalling like a toilet paper xD srry, and the ground... no comments i mean no collisions, so heres a piece o' shi.. code :

Code: Select all

#include <irrlicht.h>
#include <btBulletDynamicsCommon.h>

	using namespace irr;
	using namespace core;
	using namespace video;
	using namespace scene;
	using namespace io;
	using namespace gui;
//aha aha ..

static btDiscreteDynamicsWorld* dynamicsWorld;

//Am i right here??? i mean for only one object which is the box, but laters if i wanna duplicate the box i guess it will make it easy for me to update hein lol ur the physict nt me

static std::vector<btRigidBody*> Box;

//main function
int main(int argc, char** argv){
	//creatingg the device
	IrrlichtDevice *mdevice = createDevice(video::EDT_OPENGL,dimension2d<u32>(640,480),32,false,true,false,0);
	//check if the device failed
	if (!mdevice)
		return 1;
//Irrlicht blah blah...

//here we are ... Bullet Physics.. this is the right forum aight?
	// Initialize bullet
	btBroadphaseInterface *BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000),    btVector3(1000, 1000, 1000));
    btDefaultCollisionConfiguration *CollisionConfiguration = new btDefaultCollisionConfiguration();
	btCollisionDispatcher *Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
	btSequentialImpulseConstraintSolver *Solver = new btSequentialImpulseConstraintSolver();
	dynamicsWorld = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);

    //sets the gravity i guess ? xD
    dynamicsWorld->setGravity(btVector3(0,-9.8,0));

    //my level collsion
    btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
    btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));

//oke i dunno what to use as a collision shape for my mesh -.- and what does this construction info do????
	btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
    btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);

    dynamicsWorld->addRigidBody(groundRigidBody);

//now the box, "box" is the box node in irrlicht ...
    //my box physics
    btRigidBody::btRigidBodyConstructionInfo boxInfo(0,groundMotionState,groundShape,btVector3(0,0,0));

    // Set the initial position of the object
    btTransform Transform;
    Transform.setIdentity();
    Transform.setOrigin(btVector3(box->getPosition().X, box->getPosition().Y, box->getPosition().Z));
    // Give it a default MotionState
    btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);

    // Create the shape
    btVector3 HalfExtents(box->getScale().X * 0.5f, box->getScale().Y * 0.5f, box->getScale().Z * 0.5f);
    btCollisionShape *boxShape = new btBoxShape(HalfExtents);

    // Add mass
    btVector3 LocalInertia;
    boxShape->calculateLocalInertia(1, LocalInertia);

    // Create the rigid body object
    btRigidBody *RigidBody = new btRigidBody(1, MotionState, boxShape, LocalInertia);

    // Store a pointer to the irrlicht node so we can update it later
    RigidBody->setUserPointer((void *)(box));

    // Add it to the world
    dynamicsWorld->addRigidBody(RigidBody);
//push back ,???? is this when i duplicate the boxes or ?? or or?? i dnt get it, i guess it adds the new created box to the list, damn that helloworld tut ****, just make it simplier dude
    Box.push_back(RigidBody);

n	while(mdevice->run())

	if (mdevice->isWindowActive())
	{
        DeltaTime = mdevice->getTimer()->getTime() - TimeStamp;
		TimeStamp = mdevice->getTimer()->getTime();

		dynamicsWorld->stepSimulation(DeltaTime * 0.001f, 60);

// now here tell me how to update the position of da box??? i know how in irrlicht but in bullet??? 

//_______________________________

//drop the graphical device
	mdevice->drop();
//return 0 as final output, render finished
	return 0;

}
Nah dont hellow world me peepz, i searched for everythin... too bad i couldnt find anythin xDDDD all i want is a simple box fallin, the collision shape for my mesh wait i ll post some pics for u gentlemens... n gentlewomens... srry bout the sharabya, just bored
You do not have the required permissions to view the files attached to this post.
tometherton
Posts: 4
Joined: Tue Jan 29, 2013 4:45 pm

Re: [Help'] Bullet Physics - Irrlicht gEngine

Post by tometherton »

From what I can tell from your code you've implemented Bullet fine - you just need to call the update somewhere in your main loop. Without that nothing will happen to any of the objects in your world. It would also be worth implementing a BulletDebugDraw function so you can draw the debug lines and see where all your shapes are and what is colliding with what.

To update the Bullet system you need to get a function in your code calling dynamicsWorld->stepSimulation

You will need to store your dynamicsWorld in a non-local variable so that it stays in scope and you can make the call to it for it to update without having to create it every time. If you need more help with any of that, just shout.

T
CHAOS-THEORY
Posts: 9
Joined: Fri Jan 25, 2013 1:46 pm

Re: [Help'] Bullet Physics - Irrlicht gEngine

Post by CHAOS-THEORY »

tometherton wrote:From what I can tell from your code you've implemented Bullet fine - you just need to call the update somewhere in your main loop. Without that nothing will happen to any of the objects in your world. It would also be worth implementing a BulletDebugDraw function so you can draw the debug lines and see where all your shapes are and what is colliding with what.

To update the Bullet system you need to get a function in your code calling dynamicsWorld->stepSimulation

You will need to store your dynamicsWorld in a non-local variable so that it stays in scope and you can make the call to it for it to update without having to create it every time. If you need more help with any of that, just shout.

T
cool dude but i already have the stepsimulation, the problem is in updating the objetc or objects, can u tell me how in bullet n how to use the debug draw. thanks ;)
rtrius
Posts: 43
Joined: Sat May 26, 2012 1:09 am

Re: [Help'] Bullet Physics - Irrlicht gEngine

Post by rtrius »

Just a guess, but the simulation could appear to be slow because
its running too quickly(DeltaTime might be 0).

The standard way to update the graphical representation of an object
would be to derive a class from btMotionState or btDefaultMotionState, e.g.

Code: Select all

struct IrrlichtMotionState : public btDefaultMotionState
{
    void* node;    //This should store a node/object in Irrlicht

    //This is called by Bullet when an object moves
    virtual void setWorldTransform(const btTransform &worldTrans)
    {
        //Update the position of node here
    }
};
Alternatively, you can use btRigidBody::getCenterOfMassTransform()
after calling stepSimulation() to get the most recent rigid body positions/orientations.


As for debug drawing, create a derived class from btIDebugDraw:
http://www.continuousphysics.com/Bullet ... gDraw.html
attach it to the dynamics world with btCollisionWorld::setDebugDrawer(),
and call btDiscreteDynamicsWorld::debugDrawWorld() when rendering.
(Details in the Bullet_User_Manual.pdf)