_So i hope this one clears out all the problems/issues faced during that stage.
[ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡɪɴ ] With PICs シ :
-While in knowledge that you :
_☑ are human...
_☑ have & know how to use a computer...
_☑ have Irrlicht & BulletPhysics & Code::Blocks Downloaded and comes here by order :
____ϟ http://irrlicht.sourceforge.net/downloads/ [ ᴄʜᴏᴏsᴇ 'irrlicht-1.8.zip' ]
____ϟ http://code.google.com/p/bullet/downloads/list [ ᴄʜᴏᴏsᴇ 'bullet-2.81-rev2613.zip' ]
____ϟ http://www.codeblocks.org/downloads/26 [ ᴄʜᴏᴏsᴇ 'codeblocks-12.11mingw-setup.exe' ]
_( confused )
☑ know what a compiler is...
-Steps :
_✧ Compiling Irrlicht...
_✧ Compiling bulletPhysics...
_✧ Linking Libraries...
_✧ Known Errors & Fixes...
_✧ Last Step : Testing !
_✧ Gift...
✎ As a side note, you have Code::Blocks installed, irrlicht extracted & bulletPhysics also...
LET THE GAME BEGIN...
° Compiling Irrlicht °
> Go to irrlicht directory, then /source/irrlicht/
> Now inside that folder, search for Irrlicht-gcc.cbp ( it's a code::block project ) & open it
> In 'build target' choose 'win32 - Release - accurate' (this one is for the Dynamic lib) then press build;
then
sɪᴅᴇ ɴᴏᴛᴇ : the process can take minutes depending on your pc specs, so be relaxed. also; when the process is finished, you should get 'compiled succefully' in C::B 'Build log'.
> Now in your Irrlicht directory go to /bin/win32-gcc/
- you should find your DLL ( Irrlicht.dll ) .
> Return again to your Code::Blocks project ( Irrlicht - gcc.cbp ) then choose again 'win32 - Release - accurate' in your 'Build target' but this time, the one under 'win32 - Debug - Static' ( this one for the static lib. [.a] ) .
- That's all ??? no way !!! ... yes way !
° Compiling BulletPhysics °
- This one is kinda tricky, so keep focused...
> I said focus not over react. Open Code::Blocks then choose New Project.
> Remove the default file 'main.cpp' ( cause we won't be needing it ).
> Now right click your project file then 'add files Recursively'
> Search for your BulletPhysics folder ( the one you extracted ) then choose the 'src' folder.
> Press 'select all' then 'OK'; for the target, all we will be needing is 'Release' so uncheck 'Debug'.
then
> Nice, you should get the whole 'src' folder in your project;
> Now go to 'Project > Build options' in C::B menu, choose 'Release' in the left panel then the TAB 'Search directories > Compiler'; press 'Add'.
choose then
> Browse the directory of your bullet's 'src' folder again and press 'OK'; then press 'OK' again...
then
> In 'Build target' change it to 'Release' then press 'Build' as we don't need the debug mode.
sɪᴅᴇ ɴᴏᴛᴇ : if you get an error ( like 'E:\DATA\Development\...\BulletMultiThreaded\...r_DX11.h|23|fatal error: crtdbg.h: No such file or directory|' please refer to the Errors/Fixes section in the end of this tutorial.
sɪᴅᴇ ɴᴏᴛᴇ : the process can take minutes depending on your pc specs, so be relaxed. also; when the process is finished, you should get 'compiled succefully' in C::B 'Build log'.
- In your Bullet project folder you should find the lib 'libBullet_Physics.a'
Nicely done fisher. Mission Complete...
° Linking Libraries °
> Open a new project, then press 'Build options'
then
> Press 'Add' & Browse to your Irrlicht project folder, you'll find the Irrlicht slib 'libIrrlicht.a' choose it; then press 'OK'
> Press add again & Browse to your bulletPhysics project folder, you'll find the bullet slib 'libBullet_Physics.a' choose it; then press 'OK' you should get something like :
this
> Go to the next TAB 'Search directories > Compiler' then press 'Add' then choose the 'src' folder of your bulletPhysics folder (where you extracted it ); press 'OK'
then
- We are all set up !
° Testing °
- Stay on your project; I'll give you 2 simple ways for testing your linking and libraries...
1st > the famous 'Hello World' project; just copy and past it in you IDE and build/run.
Code: Select all
//***************************************************************
// Bullet/irrlicht demo by Alan Witkowski
// http://www.cs.utah.edu/~witkowsk
// http://code.google.com/p/irrlamb/
//***************************************************************
#include <irrlicht.h>
#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>
#include <cstdlib>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
// Functions
static void CreateStartScene();
static void CreateBox(const btVector3 &TPosition, const vector3df &TScale, btScalar TMass);
static void CreateSphere(const btVector3 &TPosition, btScalar TRadius, btScalar TMass);
static void UpdatePhysics(u32 TDeltaTime);
static void UpdateRender(btRigidBody *TObject);
static void ClearObjects();
static int GetRandInt(int TMax) { return rand() % TMax; }
// Globals
static bool Done = false;
static btDiscreteDynamicsWorld *World;
static IrrlichtDevice *irrDevice;
static IVideoDriver *irrDriver;
static ISceneManager *irrScene;
static IGUIEnvironment *irrGUI;
static IFileSystem *irrFile;
static ITimer *irrTimer;
static ILogger *irrLog;
static list<btRigidBody *> Objects;
// Event receiver
class EventReceiverClass : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent &TEvent) {
if(TEvent.EventType == EET_KEY_INPUT_EVENT && !TEvent.KeyInput.PressedDown) {
switch(TEvent.KeyInput.Key) {
case KEY_ESCAPE:
Done = true;
break;
case KEY_KEY_1:
CreateBox(btVector3(GetRandInt(10) - 5.0f, 7.0f, GetRandInt(10) - 5.0f), vector3df(GetRandInt(3) + 0.5f, GetRandInt(3) + 0.5f, GetRandInt(3) + 0.5f), 1.0f);
break;
case KEY_KEY_2:
CreateSphere(btVector3(GetRandInt(10) - 5.0f, 7.0f, GetRandInt(10) - 5.0f), GetRandInt(5) / 5.0f + 0.2f, 1.0f);
break;
case KEY_KEY_X:
CreateStartScene();
break;
default:
return false;
break;
}
return true;
}
return false;
}
};
int main() {
// Initialize irrlicht
EventReceiverClass Receiver;
irrDevice = createDevice(video::EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, false, false, &Receiver);
irrGUI = irrDevice->getGUIEnvironment();
irrTimer = irrDevice->getTimer();
irrScene = irrDevice->getSceneManager();
irrDriver = irrDevice->getVideoDriver();
irrDevice->getCursorControl()->setVisible(0);
// Initialize bullet
btDefaultCollisionConfiguration *CollisionConfiguration = new btDefaultCollisionConfiguration();
btBroadphaseInterface *BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
btCollisionDispatcher *Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
btSequentialImpulseConstraintSolver *Solver = new btSequentialImpulseConstraintSolver();
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
// Add camera
ICameraSceneNode *Camera = irrScene->addCameraSceneNodeFPS(0, 50, 0.02);
Camera->setPosition(vector3df(0, 5, -5));
Camera->setTarget(vector3df(0, 0, 0));
// Create text
IGUISkin *Skin = irrGUI->getSkin();
Skin->setColor(EGDC_BUTTON_TEXT, SColor(255, 255, 255, 255));
irrGUI->addStaticText(L"Hit 1 to create a box\nHit 2 to create a sphere\nHit x to reset", rect<s32>(0, 0, 200, 100), false);
// Create the initial scene
irrScene->addLightSceneNode(0, core::vector3df(2, 5, -2), SColorf(4, 4, 4, 1));
CreateStartScene();
// Main loop
u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;
while(!Done) {
DeltaTime = irrTimer->getTime() - TimeStamp;
TimeStamp = irrTimer->getTime();
UpdatePhysics(DeltaTime);
irrDriver->beginScene(true, true, SColor(255, 20, 0, 0));
irrScene->drawAll();
irrGUI->drawAll();
irrDriver->endScene();
irrDevice->run();
}
ClearObjects();
delete World;
delete Solver;
delete Dispatcher;
delete BroadPhase;
delete CollisionConfiguration;
irrDevice->drop();
return 0;
}
// Runs the physics simulation.
// - TDeltaTime tells the simulation how much time has passed since the last frame so the simulation can run independently of the frame rate.
void UpdatePhysics(u32 TDeltaTime) {
World->stepSimulation(TDeltaTime * 0.001f, 60);
// Relay the object's orientation to irrlicht
for(list<btRigidBody *>::Iterator Iterator = Objects.begin(); Iterator != Objects.end(); ++Iterator) {
UpdateRender(*Iterator);
}
}
// Creates a base box
void CreateStartScene() {
ClearObjects();
CreateBox(btVector3(0.0f, 0.0f, 0.0f), vector3df(10.0f, 0.5f, 10.0f), 0.0f);
}
// Create a box rigid body
void CreateBox(const btVector3 &TPosition, const vector3df &TScale, btScalar TMass) {
ISceneNode *Node = irrScene->addCubeSceneNode(1.0f);
Node->setScale(TScale);
Node->setMaterialFlag(EMF_LIGHTING, 1);
Node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
// Set the initial position of the object
btTransform Transform;
Transform.setIdentity();
Transform.setOrigin(TPosition);
btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
// Create the shape
btVector3 HalfExtents(TScale.X * 0.5f, TScale.Y * 0.5f, TScale.Z * 0.5f);
btCollisionShape *Shape = new btBoxShape(HalfExtents);
// Add mass
btVector3 LocalInertia;
Shape->calculateLocalInertia(TMass, LocalInertia);
// Create the rigid body object
btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
// Store a pointer to the irrlicht node so we can update it later
RigidBody->setUserPointer((void *)(Node));
// Add it to the world
World->addRigidBody(RigidBody);
Objects.push_back(RigidBody);
}
// Create a sphere rigid body
void CreateSphere(const btVector3 &TPosition, btScalar TRadius, btScalar TMass) {
ISceneNode *Node = irrScene->addSphereSceneNode(TRadius, 32);
Node->setMaterialFlag(EMF_LIGHTING, 1);
Node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
// Set the initial position of the object
btTransform Transform;
Transform.setIdentity();
Transform.setOrigin(TPosition);
btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
// Create the shape
btCollisionShape *Shape = new btSphereShape(TRadius);
// Add mass
btVector3 LocalInertia;
Shape->calculateLocalInertia(TMass, LocalInertia);
// Create the rigid body object
btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
// Store a pointer to the irrlicht node so we can update it later
RigidBody->setUserPointer((void *)(Node));
// Add it to the world
World->addRigidBody(RigidBody);
Objects.push_back(RigidBody);
}
// Passes bullet's orientation to irrlicht
void UpdateRender(btRigidBody *TObject) {
ISceneNode *Node = static_cast<ISceneNode *>(TObject->getUserPointer());
// Set position
btVector3 Point = TObject->getCenterOfMassPosition();
Node->setPosition(vector3df((f32)Point[0], (f32)Point[1], (f32)Point[2]));
// Set rotation
vector3df Euler;
const btQuaternion& TQuat = TObject->getOrientation();
quaternion q(TQuat.getX(), TQuat.getY(), TQuat.getZ(), TQuat.getW());
q.toEuler(Euler);
Euler *= RADTODEG;
Node->setRotation(Euler);
}
// Removes all objects from the world
void ClearObjects() {
for(list<btRigidBody *>::Iterator Iterator = Objects.begin(); Iterator != Objects.end(); ++Iterator) {
btRigidBody *Object = *Iterator;
// Delete irrlicht node
ISceneNode *Node = static_cast<ISceneNode *>(Object->getUserPointer());
Node->remove();
// Remove the object from the world
World->removeRigidBody(Object);
// Free memory
delete Object->getMotionState();
delete Object->getCollisionShape();
delete Object;
}
Objects.clear();
}
2nd > ... i uploaded it to my SkyDrive in both .7z format & .zip so u dont bother (;
____ http://sdrv.ms/18IolM2 .ZIP format
____ http://sdrv.ms/165TN9t] .7z format
° Known Errors/Fixes °
☒ The most important thing; i didn't included the irrlicht dll in the tutorial, you have to put your own ( the compiled one )... if you get 'Irrlicht.dll is missing or not found' it's probably cause the exe can't find the DLL; don't panic just copy/paste the DLL to the application location and it will work.
sɪᴅᴇ ɴᴏᴛᴇ : to avoid the annoying ERROR and copy pasting the DLL everytime you make a new project, just copy/paste it into '/windows/system32/' and you wont be bothered again.
☒ If u get any error that any header file is missing; its probably that you didn't added it to 'search directories' or by mistake you only added it for debug mode. while you are building in release mode.
☒ If you get the ERROR 'E:\DATA\Development\...\src\BulletMultiThreaded\...\btSoftBodySolverVertexBuffer_DX11.h|23|fatal error: crtdbg.h: No such file or directory|' just delete all the BulletMultiThreaded folder from your project files; it's not needed at all ( it's the main problem of all those errors ). crtdbg is probably from Microsoft VC++ SDK that helps detecting memory leaks and that is not included in Mingw; correct me if am wrong.
☒ If you get an ERROR such 'E:\DATA\Development\Game Development\...\main.cpp|3|fatal error: btBulletDynamicsCommon.h: No such file or directory|'
- it's obviously sir or lady that you didn't show the compiler where the header files are located... go to 'Project > Build option' then 'Search directories > Compiler' then add your BulletPhysics 'src' folder.
then
☪ ᴛʜᴇ ɢɪғᴛ : finally what you all were scrolling for lol, the gift is just the libs and dll packed into one zip file for the ones who couldn't manage to make it run ツ don't get disappointed.
< http://sdrv.ms/1dO0GRy LIBs >
Uploaded with http://imageshack.us
Thanks to ᴛʜᴇ ɢʀᴇᴀᴛᴍɪɴᴅs who made up Irrlicht & bulletPhysic such great engines; also the Code::Blocks Team
i worked hard for this tutorial; and it took me hours so don't be disrespectful... i hope this one clarify the problems faced during the compiling of my favourite engines, anything else please post it here kindly. nighty night (;
ɴᴏᴛᴇ : the tutorial is posted in both irrlicht & bullet's forum & it will also be posted in C::B forum.
following this link
bulletPhysics Forum :
http://www.bulletphysics.org/Bullet/php ... f=9&t=9397
Irrlicht Forum :
http://irrlicht.sourceforge.net/forum// ... 73#p282873
Code::Blocks Forum :
http://forums.codeblocks.org/index.php/ ... 318.0.html
...cannot use [url] bbcode.
_____________________________________________________________________________
ᴀᴋ'