Chapter 9. Super Models

In the previous chapter, you created a framework to render OpenGL in 3D. At the very end of that chapter, we added a block of code that rendered a cube. In this chapter, you will learn how to create 3D objects in Open GL, first using code, and then using a 3D modeling program. In this chapter, we will cover the following:

  • Graphics cards: 3D graphics cards are basically small computers that are optimized to render objects in 3D. We will take a quick look at how a graphics card does what it does best.
  • Vertices: 3D objects are drawn by plotting points and telling OpenGL to use these points to create an object that can be rendered on the screen.
  • Triangles: Triangles are used to create all 3D objects. You will learn about the relationship between vertices and triangles and how they are used to create simple objects.
  • Modeling: Once you understand how to create simple 3D objects using code, you will also understand that you are going to need a more effective tool if you ever want to create anything complicated. This is where 3D modeling software comes in and saves the day.
  • Once you create a 3D model, you have to get the model into the game. We will create the code to load a 3D model into our game by reading the data that is created by the modeling software.

New Space

Until now, we have been working only in a two-dimensional space. This means that we were able create game objects with height and width. This works well because our computer screens are also two-dimensional. As we move into three-dimensional space, we need the ability to add another dimension to our objects: depth. As computer screens don't physically have a third dimension in which to display pixels, this is all accomplished by mathematical wizardry!

In Chapter 8, Expanding Your Horizons we discussed several methods that have been used (and are still used) to simulate three-dimensions in a two-dimensional display:

  • Objects that are farther away can be made to appear smaller than objects that are close
  • Objects that are farther away can be made to move more slowly than objects that are close
  • Lines that are parallel can be drawn to converge toward the center as they are farther away

These three techniques have one major shortcoming: they all required the programmer to write code that makes each visual effect work. For example, the programmer has to make sure that objects that are receding from the player are constantly scaled down so that they become increasingly smaller.

In a true 3D game, the only thing that the programmer has to worry about is placing each object at the right coordinates in 3D space. A special graphics card takes care of performing all of the calculations to take care of size, speed, and parallax. This frees the programmer up from doing these calculations, but it actually adds a whole new set of requirements related to positing and rotating objects in three-dimensional space.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.158.173