Showing posts with label Tokamak. Show all posts
Showing posts with label Tokamak. Show all posts

Tuesday, September 11, 2012

3d graphics programming - adding some physics

Now that we got the basics of 3d game programming using Irrlicht out of the way, how about adding some physics? I'll demonstrate how physics could be added to a 3d application using the open source Tokamak Physics library. In order to better illustrate the source code, I've uploaded it to GitHub. It is accessible via the 3dGraphicsExamples repository.
Update the Qt project file to include Tokamak library:
In order to use Tokamak in C++ code, you'll need to include its header file:
Before Tokamak can take over as the physics engine behind your application, you need to provide it with some details about the simulation as well as information about your 3d models. In Tokamak, 3d objects that are supposed to be mobile are called rigid bodies, while bodies that are supposed to stay in their position are called animated bodies. In order for Tokamak to run, it needs to know how many objects are needed to be tracked in the simulation as well as information about gravity.
In our simulation, we'll start with poker cards initially suspended in air at varying distances from the a point and all cards facing this point. These cards will fall on a inanimate floor. Create the floor in Irrlicht and record it's attributes in Tokamak:
Create cards using the routine from the previous example however this time also set their physical attributes in Tokamak:
In order to run the simulation, Tokamak requires you to provide an advance interval. In order to get a consistent feel, you'll need to use a timer object and keep track of elapsed time interval. Luckily, Irrlicht provides you with a timer object as well:
You'll also need to ensure that your simulation runs consistently regardless of the amount of processing that goes on in your render loop. The below code is adaptation of code used by Adam Dawes on his site:
In your render loop, you'll have to traverse through your catalog of 3d objects in Tokamak and apply the position and rotation to the corresponding Irrlicht scene nodes.
There you go! You should now see your 3d objects, all initially facing in different directions, falling from on the floor, colliding with each other and bouncing. The complete source file can be found on github: example2.h

Wednesday, August 22, 2012

3d world creation and simulation using Open Source tools and libraries

Over past few weeks I've been looking into 3D world simulation. I checked out Ogre3d however I found it to be way too complex with a steep learning curve. I then came across irrLicht and was greately impressed with its simplicity of use and how quickly it let me jump from following their tutorials to creating my own code. The tutorials on their site are well documented and very easy to follow. Among other things, the tutorials also address basic collision detection. Simple simulations were very easy to make, however, I ran into a road block when attempting to implement slightly more complex physics. I soon realized that while it was possible, I'd have to hand code almost all physics, for instance, gravity, friction, momentum, etc.
After doing some research I came across Tokamak physics engine. I found Tokamak to be surprisingly easy to learn however I only found very few example. Right around the same time I also found Bullet Physics which I found to be very well documented with plenty of tutorials and examples available online. Bullet is also a more comprehensive physics engine than Tokamak and comes with a slight learning curve over Tokamak. On the other hand, Tokamak can get you started and running in no time.
I am currently exploring IrrLicht and both Bullet and Tokamak in couple hobby projects. If the projects gain critical mass, I'll share the experience and perhaps example code in future posts.