This project was done as part of the Computer Graphics and Visualization subject.
The process of designing, 2D, 3D, and animating an object is known as Computer Graphics. Modelling, simulation, and visualisation of an object or a problem are all possible with computer graphics. Since the advent of photography and television, interactive computer graphics has been the most popular means of creating images. It also has the benefit of being able to create images not only of concrete real-world objects but also of abstract, synthetic objects such as mathematical surfaces and data with no apparent geometry, such as survey results, using a computer.
The aim of this project is to demonstrate how OpenGL can be used to simulate the Tower of Hanoi problem. The keyboard is the primary means of input in this project.
OpenGL is a graphics rendering API that is independent of operating systems and produces high-quality colour images consisting of geometric and image primitives. This interface is made up of approximately 150 distinct commands that you can use to define the objects and operations used to create immersive three-dimensional applications. Silicon Graphics Inc. (SGI) created OpenGL in 1992, and it is commonly used in CAD, augmented reality, science visualisation, knowledge visualisation, and flight simulation. It's also used in computer games, where it competes with Direct3D on Microsoft's Windows platform.
Three rods and n discs make up the Tower of Hanoi, a mathematical puzzle. The aim of the puzzle is to shift the whole stack to a different rod by following these basic rules:
- At a given time, only one disc can be transferred.
- Each move consists of taking the upper disk from one of the pegs and placing it on top of another peg i.e., a disk can only be moved if it is the uppermost disk on a stack.
- A smaller disc cannot be mounted on top of a larger disc.
Step 1 - Start.
Step 2 - Let the three towers be the Source, Destination, and Aux.
Step 3 - Read the number of disks, n from the user.
Step 4 - Move n-1 disks from Source to Aux.
Step 5 - Move n-th disk from Source to Destination.
Step 6 - Move n-1 disks from Aux to Destination.
Step 7 - Repeat Steps 3 to 5, by decrementing n by 1.
Step 8 - Stop.
- Open the terminal and navigate to the directory (folder) containing the .cpp file (using the cd command).
- Compile the code using the command
g++ tower.cpp
- Now execute the program using the command
./a.out tower.cpp