[ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡɪɴ ]

A forum to store posts deemed exceptionally wise and useful
Post Reply

CHOOSE ONLY 3 :

I like the tutorial !
4
67%
The tutorial was helpful !
1
17%
Hy Five !
1
17%
I disagree with you !
0
No votes
I don't like it at all !
0
No votes
 
Total votes: 6

CHAOS-THEORY
Posts: 3
Joined: Mon Sep 02, 2013 4:35 pm

[ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡɪɴ ]

Post by CHAOS-THEORY »

After searching many times on google plus irrlicht and bullet's forum; i've saw that many users interfers with many issues during using/compiling Irrlicht/bullet_physics using Code::Blocks...
_So i hope this one clears out all the problems/issues faced during that stage.

Image

[ ᴛᴜᴛᴏʀɪᴀʟ ] 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/
Image

> Now inside that folder, search for Irrlicht-gcc.cbp ( it's a code::block project ) & open it
Image

> In 'build target' choose 'win32 - Release - accurate' (this one is for the Dynamic lib) then press build;
Image then Image

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/
Image

- you should find your DLL ( Irrlicht.dll ) .
Image

> 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] ) .
Image

- 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.
Image

> Remove the default file 'main.cpp' ( cause we won't be needing it ).
Image

> Now right click your project file then 'add files Recursively'
Image

> Search for your BulletPhysics folder ( the one you extracted ) then choose the 'src' folder.
Image

> Press 'select all' then 'OK'; for the target, all we will be needing is 'Release' so uncheck 'Debug'.
Image then Image

> Nice, you should get the whole 'src' folder in your project;
Image

> Now go to 'Project > Build options' in C::B menu, choose 'Release' in the left panel then the TAB 'Search directories > Compiler'; press 'Add'.
Image choose Image then Image

> Browse the directory of your bullet's 'src' folder again and press 'OK'; then press 'OK' again...
Image then Image

> In 'Build target' change it to 'Release' then press 'Build' as we don't need the debug mode.
Image

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'
Image

Nicely done fisher. Mission Complete...

° Linking Libraries °

> Open a new project, then press 'Build options'
Image then Image

> Press 'Add' & Browse to your Irrlicht project folder, you'll find the Irrlicht slib 'libIrrlicht.a' choose it; then press 'OK'
Image

> 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 :
Image this Image

> 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'
Image then Image

- 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();
}
 
sɪᴅᴇ ɴᴏᴛᴇ : if you get an error such as 'Irrlicht.dll is missing...' or 'Irrlicht.dll not found' please refer to the Errors/Fixes section in the end of the tutorial...

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.
Image

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.
Image

☒ 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.
Image

☒ If you get an ERROR such 'E:\DATA\Development\Game Development\...\main.cpp|3|fatal error: btBulletDynamicsCommon.h: No such file or directory|'
Image

- 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.
Image then Image

☪ ᴛʜᴇ ɢɪғᴛ : 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

Image

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.
_____________________________________________________________________________
ᴀᴋ'
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: [ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡ

Post by Cube_ »

This is remarkably similar to how I solved it :P
Way to go putting it in writing though, it'll help a lot of people (I think I shared two code snippets that pretty much allow dropping cubes and balls on a plane in one of the help threads around here)
"this is not the bottleneck you are looking for"
CHAOS-THEORY
Posts: 3
Joined: Mon Sep 02, 2013 4:35 pm

Re: [ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡ

Post by CHAOS-THEORY »

thanks brother; yeah it is, but since i lost all my developpment folder i couldn't find a simplier one to offer (;
Cube_
Posts: 1010
Joined: Mon Oct 24, 2011 10:03 pm
Location: 0x45 61 72 74 68 2c 20 69 6e 20 74 68 65 20 73 6f 6c 20 73 79 73 74 65 6d

Re: [ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡ

Post by Cube_ »

heh, it's cool, I shared that source snippet for others to use (Albeit I should've specified a license as unlicensed is legally considered "you can't do anything with it" either way it was meant to be public domain :P), the most important thing is that someone bothered writing a tutorial about it, this way people *might* just maybe stop spamming the forums on how to integrate bullet :P
"this is not the bottleneck you are looking for"
CHAOS-THEORY
Posts: 3
Joined: Mon Sep 02, 2013 4:35 pm

Re: [ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡ

Post by CHAOS-THEORY »

Yeah; thanks i hope they wont lol
Lorddeamon
Posts: 1
Joined: Thu Aug 28, 2014 1:19 pm

Re: [ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡ

Post by Lorddeamon »

I have a problem with "fatal error: crtdbg.h: No such file or directory". When i delete all BulletMultiThreaded from project from Sources, Headers and Others I get 3 another errors
obj\Release\bullet-2.82-r2704\src\MiniCL\MiniCL.o:MiniCL.cpp|| undefined reference to `Win32ThreadSupport::Win32ThreadSupport(Win32ThreadSupport::Win32ThreadConstructionInfo const&)'|

obj\Release\bullet-2.82-r2704\src\MiniCL\MiniCL.o:MiniCL.cpp|| undefined reference to `SequentialThreadSupport::SequentialThreadSupport(SequentialThreadSupport::SequentialThreadConstructionInfo&)'|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)||undefined reference to `WinMain@16'|

and I don't know what to do with this
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: [ ᴛᴜᴛᴏʀɪᴀʟ ] Irrlicht + BulletPhysics + Code::Blocks [ ᴡ

Post by REDDemon »

run Cmake. open the project file of your ide, and build. Also add the tutorial for that? I don't like Cmake (for my projects) but is perfect for build stuff of other people.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply