vi-wer

Integration

I have a blog now, visit me >>here<< for latest updates!
Eine deutsche Version meines Blogs gibt es >>hier<< !


01. integration

"Fallin' boxes"
This is the first tutorial of this series. It will show you how to use the bullet physics library with the Irrlicht engine and explain the use of bullet in general.
I'm not going to explain how to built any of the libraries, take a look into their FAQ, WIKI or whatever. I expect that you have a working library already.

We start with something simple and necessary: the initialisation of the dynamcs world. At first we create a game class that will hold all references to objects and provide necessary functions. That's the way the class should look like:
CGameWorld.h - Class:
 1  #ifndef CGAMEWORLD_H
2 #define CGAMEWORLD_H
3
4 // includes
5 #include <irrlicht.h>
6 #include <btBulletDynamicsCommon.h>
7
8
9 const wchar_t appName[] = L"IrrBullet - 01. Bullet Integration Demo";
10
11
12 // GameWorld class
13 class CGameWorld
14 {
15 public:
16 /** Default constructor */
17 CGameWorld();
18 /** Default destructor */
19 virtual ~CGameWorld();
20
21 bool initGraphics( irr::video::E_DRIVER_TYPE driver = irr::video::EDT_OPENGL );
22 bool initPhysics();
23 bool createSceneObjects();
24 bool run();
25 bool cleanupGraphics();
26 bool cleanupPhysics();
27
28 protected:
29
30 // Irrlicht Engine
31 irr::IrrlichtDevice *m_device;
32 irr::video::IVideoDriver* m_driver;
33 irr::scene::ISceneManager* m_smgr;
34 irr::gui::IGUIEnvironment* m_guienv;;
35
36
37 // Bullet Physics Engine
38 btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
39 btBroadphaseInterface *m_broadphase;
40 btCollisionDispatcher *m_dispatcher;
41 btConstraintSolver *m_solver;
42 btCollisionConfiguration *m_collisionConfiguration;
43 btDynamicsWorld *m_dynamicsWorld;
44
45 private:
46 irr::u32 m_time;
47 };
48
49 #endif // CGAMEWORLD_H


Might look like it's pretty much but it isn't at all. Therefore the main file is pretty simple:
main.cpp - main function:
 1  #include "CGameWorld.h"
2
3 int main(int argc, char** argv)
4 {
5 CGameWorld *world = new CGameWorld();
6 world->run();
7 delete world;
8
9 return 0;
10 }


We just create a CGameClass object and let it run, when it's finished we destroy it. Simple, huh? The initialisation will be done within the CGameClass constructor and if the 'world' is destroyed the destructor will cleanup everything.

Let's begin with the constructor. It has to call both init functions and the createSceneObjects function. This function will create all the world objects. And we also set all the pointers to NULL, just to prevent invalid memory access.
CGameWorld.cpp - Constructor:
 1  #include "CGameWorld.h"
2 #include "../btIrrlichtMotionState.h"
3 #include <btBulletCollisionCommon.h>
4
5 using namespace irr;
6
7 CGameWorld::CGameWorld()
8 : m_device(0), m_driver(0), m_smgr(0), m_guienv(0),
9 m_broadphase(0), m_dispatcher(0), m_solver(0), m_collisionConfiguration(0),
10 m_dynamicsWorld(0)
11 {
12 initGraphics();
13 initPhysics();
14
15 createSceneObjects();
16 }

And the destructor (this one should be self-expanatory):
CGameWorld.cpp - Destructor:
18  CGameWorld::~CGameWorld()
19 {
20 cleanupPhysics();
21 cleanupGraphics();
22 }
CGameWorld.h - Class:
here some text
Custom Search
IP
 
Best View on Firefox and IE7 - (C) by Viktor W.

Diese Webseite wurde kostenlos mit Homepage-Baukasten.de erstellt. Willst du auch eine eigene Webseite?
Gratis anmelden