Game Development Reference
In-Depth Information
technology just for the fun or the challenge and in so doing, you discover a new
idea for a game. The vast majority of big budget modern games are 3D and this
alone makes learning 3D game development appealing.
3D graphics programming is a vast, intimidating heap of mathematics, techni-
ques, and terminology, and it's important to approach it in a measured, achiev-
able manner. To aim to compete with the latest FPS shooter with your first
project is only setting yourself up for disappointment. A better goal is something
that can be achieved quite quickly and is a stepping stone to more ambitious
projects. For 3D graphics, getting a box to display on the screen is an achievable
first step-even better if the box rotates. A later intermediate step might be to re-
create the side-scrolling shooter game covered in the last chapter, but use
3D models instead of sprites.
The code examples in this topic have often made use of a function called
Setup2DGraphics in the Form.cs file. It's quite trivial to write an equivalent
Setup3DGraphics .
private void Setup3DGraphics(double width, double height)
{
double halfWidth = width / 2;
double halfHeight = height / 2;
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(90, 4 / 3, 1, 1000);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
}
This code is nearly identical to the Setup2DGraphics call, but it uses the
function gluPerspective instead of glOrtho . The gluPerspective
function takes in a field of view as the first argument, the aspect ratio as the
second, and the near and far planes as the last two arguments. This describes
something similar to the lens of a camera for viewing the 3D scene.
If Setup3DGraphics is called instead of Setup2DGraphics then that's
nearly all that's needed to start 3D game programming. Here's a game state that
renders a pyramid in 3D using OpenGLs immediate mode producing an image
similar to Figure 11.1. Make sure that you have replaced all Setup2DGraphics
calls with Setup3DGraphics calls before running this state.
 
Search WWH ::




Custom Search