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;
}