Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Augmented reality using irrlicht and newton

0.00/5 (No votes)
2 May 2013 1  
Demo illustrates how to make augmented reality program using irrlicht and newton

 

Introduction

What about going to a journey to a weird planet and fighting some monsters or flying with F16 helicopter and destroy some city or being a master coach of real Madrid Spanish club, i can do all this stuff with the help of games.

Games can take you to a virtual world where you can do all the above stuff which could be impossible to be done in our real world, what if we merged this amazing virtual world with our real world that's what AR (Augmented reality) does.

Let us see some of awesomeness of AR in this article using the irrlicht game engine and Newton physics engine with the aid of my previous article on CodeProject Irrlicht car simulation.

We will not only augment some entities from the real world but also will make it in a physics environment

Background

Augmented reality is the technology of augmenting a real world entities to computer generated sensory input such as sound, video, graphics or GPS data, this is my light definition of Wikipedia definition.

if virtual reality is replacing the real world with a simulated one, augmented reality is replacing some entities on it with a computer generated entities (usually are 3D graphics modules)

As mentioned the demo uses Irrlicht game engine for rendering the model of the house and the care, Newton is responsible for the physics environment which makes the car and the falling balls are so real.

You can refer to my article Irrlicht Car Simulation to know how newton integrated with Irrlicht.

Irrlich version is 1.4.2, it is not the latest version but i used the same version of the previous article with the same code so i will not talk more on irrlicht and newton on this article we will focus on Augmented reality part.

ARToolKit is a software library for building Augmented Reality (AR) applications I used it in this demo it is open source and you can download it from here

IrrAR is a combination of Irrlicht and Augmented Reality to create the most rapid development platform for augmented reality at the moment. IrrAR creates 3D "nodes" out of real lifer markers to let you insert your 3d world into the real world

Using the code

All you need to start is to download the source code and load the project in visual studio 2005 then print the hiro pattern exists in ..\IRRAR\ardata\patthiro.pdf, run the project then you will find a window

It is the property sheet which controls some properties of the application window like the color space, the output size of the window the compression quality of the video ,etc....

leave everything as it and press OK then wait seconds for the window to load.

You should have a camera installed in your computer and running properly it is required for our application as it the main device which will capture the video, the application will detect the default camera installed and use it.

If every thing is ok you will see a window holds your camera view, now put the printed hiro pattern front of the camera and enjoy the event

Illustrating the code

Firstly we must configure the project to use irrlicht, newton, and ARToolkit, so i added the header files and libraries needed for them in the project directory. As i mentioned i will not talk about irrlicht and newton in this article you can refer to my article here.

The IrrAr SDK is a very useful tool in our application as it wrrapped most of the work of integrating irrlicht with ARToolkit

Lets have a look at the irrAR.cpp file and illustrate the most important parts of the code.

IAnimatedMeshSceneNode* LoadCar(scene::ISceneManager* smgr ) 
{  
    char* carModel = "../media/Vehicle/impreza.3ds";
    IAnimatedMesh* carMesh = smgr->getMesh(carModel);
    IAnimatedMeshSceneNode* carSceneNode = smgr->addAnimatedMeshSceneNode(carMesh); 
    carSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
    carSceneNode->setPosition(vector3df(0,100,0));
    carSceneNode->setScale(vector3df(18,18,18));
    return carSceneNode;
}

This part is an irrlicht code which loads the car and make the scene node for it.

// the house<pre>char* pk3Map = "../media/dum/dum.pk3";         
char* mapName = "dum.bsp";

this is the house which is a pk3 map holds all the details in a compressed file with the extension pk3

//AR stuff
armgr = new IARManager(device);

This generates an instance of the IARManager class which holds the most AR functions

This part is for initiating the camera:

// init the physics world 
physics.init(device->getTimer());   
// this cube considered the horisental plane for the world
SPhysicsCube cube;
cube.bodyType =  EBT_STATIC;
cube.node = cubeNode;

After Initiating the physics world  i created a cube to be the an horizontal plane for the car to move on 

hiro_node = armgr->addARSceneNode("../ardata/patt.hiro", gameMap); 

 Here I connect the map or the house to the hiro pattern. After creating the house and adding it to the physics world I will add the car and the wheels as a child to it to be connected all to the pattern and move as a one scene

hiro_node->addChild(carData.carBodyNode);
hiro_node->addChild(carData.tireNode_FL);
hiro_node->addChild(carData.tireNode_FR);
hiro_node->addChild(carData.tireNode_RL);
hiro_node->addChild(carData.tireNode_RR);
hiro_node->addChild(cubeNode);

We must run this line of code to make the AR work 

armgr->run();
armgr->drawBackground();  

I hope this article may help you in Augmented Reality world or be a good start in this great technology 

Points of Interest 

Game programming and iOS programming.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here