Click here to Skip to main content
15,868,053 members
Articles / Game Development
Tip/Trick

Augmented reality using irrlicht and newton

Rate me:
Please Sign up or sign in to vote.
3.00/5 (3 votes)
2 May 2013CPOL4 min read 18K   5   6
Demo illustrates how to make augmented reality program using irrlicht and newton

Image 1 Image 2

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.

C++
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.

C++
// 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

C++
//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:

C++
// 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 

C++
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

C++
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 

C++
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Main Telecom
Egypt Egypt
Senior C++ and Java developer graduated from faculty of computers and infomation cairo university.
I gift this article to do3aa

Just want to make a usful egyptian contripution on this great site

Comments and Discussions

 
GeneralMy vote of 1 Pin
Gun Gun Febrianza5-May-14 17:18
Gun Gun Febrianza5-May-14 17:18 
QuestionNo source code Pin
Damir Vidakovic7-May-13 22:54
Damir Vidakovic7-May-13 22:54 
AnswerRe: No source code Pin
Ihab ramadan7-May-13 23:00
Ihab ramadan7-May-13 23:00 
GeneralRe: No source code Pin
xqhust17-Feb-14 0:52
xqhust17-Feb-14 0:52 
QuestionCamera rotation Pin
xuanhaobk4-May-13 18:50
xuanhaobk4-May-13 18:50 
AnswerRe: Camera rotation Pin
Ihab ramadan7-May-13 23:07
Ihab ramadan7-May-13 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.