XNA 3.0 Game Programming Recipes
Chapter 2: Setting Up Different Camera Modes in Your 3D World (144 pages)
In a 3D application, the camera is one of the most elementary components. The camera represents the viewpoint of the user in your 3D world. XNA renders your 3D world to the screen as it is seen by the camera. So before you can ask XNA to render the content of your 3D scene to the screen, you first need to specify the position and viewing direction of your camera.
This chapter starts off with some fundamental topics you need to master before you can create any 3D application.
The second part of this chapter covers some more advanced examples, such as camera flybys, quadtrees, octrees, and post-processing.
2-1. Set Up the Camera: Position, Target, and View Frustum
This beginner recipe introduces to the steps required to set up your own 3D World. The purpose of the camera is discussed, together with the View and Projection matrices. As an extra, the use and necessity of the Z-buffer is explained.
2-2. Specify the Target of Your Camera
To rotate a camera, you should only change its Target point. Although this can be done by diving into trigon maths, itís far easier and more scalable to use simple transformations.
2-3. Create a First-Person Shooter Camera: A Quake-Style Camera
This recipes creates the QuakeCamera class, which is being used in almost all 3D recipes in this book. This camera mode allows you to fly through your 3D world using as seen in most first-person shooting games.
2-4. Create a Freelancer-Style Camera: Full 3D Rotation Using Quaternions
The Quaternion camera is quite different from the Quake Camera, as it allows the camera to rotate in all directions.
2-5. Check Whether an Object Is in Sight of the Camera
This recipe shows how to use the Contains method of the BoundingFrustum class. As an example, you learn how to check whether a single point, single Model or multiple Models are in sight of the camera.
2-6. Detect Camera Collision Against Models, Walls, or Terrains
This recipe uses a BoundingSphere to keep the camera at a certain distance from a Model or terrain grid.
2-7. Create a Camera Fly-by Action
Most 3D games allow for smooth Fly-By camera modes. This allows the game engine to bring some locations of the 3D world to the attention of the player. This recipe shows how to implement such Fly-By using a Bezier curve.
2-8. Remove the Solid Background Color: Skybox
An easy way to remove the solid background color of the screen is to render a cube around the camera and cover the cube with textures. The HLSL part of this recipe explains the texCUBE intrinsic.
2-9. Draw Only the Parts of the Scene That Are in Sight
of the Camera: Octree
Having tens or hundres of Models in your 3D World will severely slow down your application. This recipe shows how you can separate your 3D world in smaller parts, and render only those parts that are in sight of the camera.
2-10. Use a Quadtree to Hide Parts of a Grid That Are Not in Sight
This recipe introduces you to large terrain rendering. A large terrain is split up into multiple smaller grids, of which only those in sight of the camera are actually being rendered to the screen.
2-11. Create a Real-Time Camera-Dependant Optimally Adapting Mesh (ROAM) Terrain
In case the terrain you want to render for your game is so huge it cannot be handled by the previous recipe canít handle, this recipe introduces you to a totally different way of rendering terrain. This is done by selecting for each triangle individually the optimal Level-Of-Detail that is should be rendered in.
2-12. Set Up a Post-Processing Framework
Almost all games come with a complete set of Post-Processing effects. These HLSL effects capture the final image before it is rendered to screen and modify the color content. This recipe shows how you can set up a Post-Processing framework, allowing you to easily add or drop Post-Processing effects.
2-13. Create a Blur/Glow Post-Processing Effect
Two examples of Post-Processing effects. The Glow effect is used to show how to use multiple pass alpha rendering, one of the more complex techniques to master in Post-Processing.
2-14. Write a Custom Content Importer
As a more advanced recipe on the Content Pipeline, this recipe shows you how you can load custom defined objects into the Content Pipeline, and how you can extract and present their contents to a Content Processor.
Recipe 2-11: Real time ROAM terrain engine for rendering huge outdoor environments.
- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans