Wednesday, May 26, 2021

TRANSFORMERS - The OpenGL Computer Graphics Projects

OpenGL Projects Committed to provide student new and best Computer Graphics Projects. In view of that we have posted so many innovative projects using OpenGL C++ on this blog.  Students can download the source codes from OpenGL Projects, use them in their own innovative projects. We know coding is fun! so what's in here? In this post we bring you one simple still classic projects that will demonstrate the "TRANSFORMERS", inspired from the movie Transformers. We will give insight about projects as well as source code for same. This projects is developed by Mahesh Bhandari of New Horizon College of Engineering, Bengaluru.

Transformers are actually objects that transform. But with reference to our film we can define the transformers are alien robots that can transform themselves into various other mechanical objects. The idea was inspired from the toy lines from japan. These transformers have been created on earth but lives on alien plane called cybertron. They can talk like human and have emotion like human, hence both negative as well as positive behavior.

What are we building

In this OpenGL Computer Graphics Projects, we are building a Transformer not exactly but a smaller robot that will transform. We are going to code a simple robot which will have two arms and legs, a head with small antenna. To show different body we will differentiate the body color and joint color and of course the head color.

First we are going to design a small place with trees across it to make the scenery in this opengl projects. As we said we will design a simple robot, this will place in the midway of scenery. Now we will code to animate the robot. The idea is to collapse all the parts of robot and transform in to a car or vehicles as seen in the movie. When you will do this and run the program you will feel watching the movie, isn't that cool.

The Transformer OpenGL Projects

Lets code this Computer Graphics Projects.
We will write code for different objects say tree, clouds etc and then club all them into the main functions. For example you can see the code for tree below -

void tree()
{
//Trunk
glColor3f(0.325,0.208,0.039);
glScalef(1.5,0.3,0.3);
glTranslatef(0,-10,0);
glutSolidSphere(10,18,20);
glTranslatef(0,10,0);
glScalef(1/1.5,1/0.3,1/0.3);
glutSolidCube(12);

//Tree
glColor3f(0,1,0);
for(int c=-5;c<=10;c+=5)
{
glTranslatef(c,25,0);
glScalef(1,0.8,1);
glutSolidSphere(20,20,20);
glScalef(1,1/0.8,1);
glTranslatef(-c,-25,0);
}
}

Now as we have code for all the objects we have to code the animation and bring it to display function.

void trans()
{
if (yll<130)
{
yll+=1;
ylu+=1;
yln+=1;
}
else if(yrh>240)
{
yrh-=1;
yre-=1;
yrf-=1;
ye-=1;
yrnc-=1;
}
else if(yll<220)
{
yll+=1;
}
else if(rlh<=560)
{
rlh+=1;
rrh-=1;
rla+=0.9;
rra-=0.9;
}
else if(rxa<=90)
{
rxa+=1;
tz-=2;
ty+=1.2;
}
else
{
flag=1;
rxa=0;
sx=1.3;
sy=0.5;
sz=1;
}
}

All the code are easy to understand and make. Just download the code and see yourself.

What Can be improve?

As we know perfection is myth, hence we can improve this OpenGL projects as well. In future we can improve it with code reusability. With recursion and other techniques we can improve the coding as well reduce the compilation time. The projects can be implement in 3D which will make it more impressive. Addition of sound and lights will also mark improvement. We can add user interaction in the program.

Conclusion

After movie came many people think transformers(basically robot with Artificial Intelligence) may replace everything within the future. It's vital to understand about the transformers. The aim of this project is to point out the demonstration of working of transformers. This project demonstrates one among the simplest cartoon series of transformers, the project completely uses graphics and has been done using OpenGL. The code utilized in the program is extremely simple. we will easily understand the working of transformers by seeing the output of this project.

Minimum code is written to point out the animation in order that the programmers can easily understand and can be distributed with modification in the code as open source. With this OpenGL Computer Graphics Projects, you will learn the techniques that will helps in future endeavors.