In this article, we will take a look at project that is one of the most complete projects I have seen to start 3D programming from scratch. We will see the project overview, interesting objects and list the openGL topics covered by this project.
Eight years ago, I was trying to enter the 3D programming world. I was studying NEHE tutorials but due to its complexity, I quit like 3 times. The tutorials were written in C++ and were sometimes very hard to understand. Then I came across this project. I have to say this is one of the most complete projects I have seen to start 3D programming from scratch.
In the project, you will see a house with everything inside. But the amazing part of it is that everything is done by code. That means that the project doesn't load any 3D object. It just creates them at runtime. There is no 3D engine used so you get to see how most of the code looks that is used to make cameras, object interaction, collisions, among others. The programmers made all the objects just by combining simple OpenGL primitives.
The project language is coded in C# using TAO namespace. TAO is a library that maps all OpenGL functions to .NET. In this way, you will be using OpenGL from the .NET sandbox. The project is very modular. That means that every object is almost standalone. Each object actually contains all its own working logic so you won't get lost with too many dependencies across the project. The main class is main.cs so you can start discovering the project from there.
This is a code example of the main.cs. You can see how objects are added to the scene during runtime.
public MainClass(string args)
GlControl ViewPort = new GlControl(Width,Height);
GlObjectList world = new GlObjectList();
world.Add(new TranslatedObject(new Point3D(0,-10,0),new SkyBox()));
GlObjectList casa = new GlObjectList();
casa.Add(new Librero(new Point3D(210,0,-318),0));
casa.Add(new Librero(new Point3D(210,Librero.Height+.3,-316),-3));
casa.Add(new Lamp(new Point3D(60,270,190),70));
casa.Add(new Refrigerador(new Point3D(-145,0,120),180));
Plantilla obj = new Mesita(new Point3D(80,0,40),90);
casa.Add(new TV(new Point3D(80,obj.Height+.2,60),0));
casa.Add(new Cama(new Point3D(370,0,-250),0,100,70));
casa.Add(new Cama(new Point3D(370,0,-480),0,100,60));
casa.Add(new Cama(new Point3D(-210,0,-420),0,90,40));
casa.Add(new Estante(new Point3D(-210,170,-108)));
obj = new Mesa(new Point3D(380,0,200));
casa.Add(new Silla(new Point3D(440,0,160)));
casa.Add(new Silla(new Point3D(440,0,240)));
casa.Add(new Silla(new Point3D(330,0,160),180));
casa.Add(new Silla(new Point3D(330,0,240),180));
casa.Add(new Silla(new Point3D(385,0,110),90));
casa.Add(new Silla(new Point3D(385,0,290),-90));
casa.Add(new Plato(new Point3D(380,obj.Height+.2,200)));
casa.Add(new Vaso(new Point3D(380,obj.Height+.2,230)));
casa.Add(new MesitaDeNoche(new Point3D(455,0,-140),-90));
casa.Add(new MesitaDeNoche(new Point3D(455,0,-380),-90));
casa.Add(new MesitaDeNoche(new Point3D(455,0,-580),-90));
casa.Add(new MesitaDeNoche(new Point3D(-280,0,-340),90));
obj = new EstanteHorizontal(new Point3D(330,0,-70),180);
casa.Add(new Butaca(new Point3D(-30,0,200),90,2));
casa.Add(new Butaca(new Point3D(200,0,270),250,1));
casa.Add(new Butaca(new Point3D(200,0,110),-70,1));
casa.Add(new MesetaConFregadero(new Point3D(-307,0,-64),0));
casa.Add(new Clock(new Point3D(485,200,325),270));
GlObject c = new TranslatedObject(new Point3D(0,0,-70),casa);
observer=new Avatar(ViewPort, world);
The project uses a FPS camera. You will change the camera direction with the mouse and move forward and backwards with left click/right click. To interact with objects like the house door, press space.
Also, you can press G key and activate ghost mode. In this mode, collisions won't work and you will be able to go through the house walls.
You will find a clock hanging in the wall when you enter the house. If you notice, the clock will show your computer time.
Entering the kitchen, you will find the classic OpenGL Teapot. This object was hardcoded into the GLUT library and is like the symbol of OpenGL.
You will have to interact with doors. The will open and close. The good part is that there is no 3D engine behind it so you get to see how it is actually done.
Tables, chairs, beds, among other house objects can also be seen. If you look into the code, you will realize how they are built combining simple OpenGL primitives.
If you walk around the house, you will see the sky and the ground. Form this project , I learned the basics for rendering the environment in 3D programming. Which is a textured cube (skybox) and a plane for the ground.
This ceiling lamp has a chain and the chain is made by code using OpenGL primitives. It is very interesting to have a look at how it is done.
OpenGL Topics Covered by this Project
This is a list of all the basics that this project involves. The explanation of each one goes beyond the logic of this article. I recommend you to start looking over the internet.
- FPS Camera
- CSG (Constructive Solid Geometry)
- Skybox Technique
- Vector Handling
- Texture Loading and mapping.
- OpenGL primitives
- Object interaction
Points of Interest
You can learn a lot from this project. You can start by commenting the objects added to the scene and see the outcome. If you get a little confident, you can start adding your own objects. The project is coded in a very modular way enabling you to add complexity without compromising the entire structure design.
I hope this will be your inspiration to start in this amazing world.
- 16th June, 2015: First version