XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
Forum
   
My XNA Book
      
       Go to section on this site

Additional info


Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 20/05/2013 at 02:30:13

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22


Ads




XNA 2.0 Game Programming Recipes

Riemer Grootjans







Chapter 4: Working with Models (108 pages)

What good is a game without any objects? It would be quite impossible, however, to manually specify the shapes of all objects you use in your game. Luckily, XNA can load Models that have been created in specific modeling applications and have been saved to disk. Once you致e loaded them into your XNA project, you can move and rotate your Models around in your scene and even animate them!

The first recipes of this chapter explain how to load a Model from a file and how to position it correctly in your 3D world. Next, you値l find a detailed discussion on the structure of a Model object, allowing you to make your Models come to life by animating them.

Furthermore, this chapter presents some different collision detection mechanisms, because most games rely heavily on this. These checks range from some very fast, volume-based checks to the most detailed per-triangle check.

Because some of the advanced recipes require a custom content processor for the Models, this chapter demonstrates how to extend the default Model processor and how to pass objects of custom classes using a custom-built TypeWriter and a custom-built TypeReader.

You値l definitely need some models to make your 3D world come alive. However, if you use an orthogonal Projection matrix (see recipe 2-13), a 2D game can also use Models.

4-1. Load and Render a Model Using the BasicEffect Class
This recipe will show you how to load 3D Models from disk into your 3D World. As an extra, the whole structure of a 3D Model is explained using some examples.

4-2. Set Different World Matrices for Different Objects, Combining World Matrices
The World Matrix is needed when you want to reposition, rotate and/or scale a 3D Model before rendering it to the screen. This recipe shows you how to do this, and goes one step further by show you the correct way to combine multiple operations together into one matrix.

4-3. Find the Rotation Angle Corresponding to a Direction
When you are moving a Model based only on its previous and current 3D location, you should make sure the Model is correctly rotated.

4-4. Use Acceleration to Control Velocity
This recipe shows you how you can make your Model move smoothly. Using acceleration, your Model will slowly speed up until it reaches its maximum speed.

4-5. Construct the Global BoundingSphere Around a Model
The Global BoundingSphere of a Model is the smallest sphere surrounding the Model. The global BoundingSphere is required in many cases, and especially for fast collision detection. This recipe shows you how to create this Global BoundingSphere.

4-6. Scale the Model to a Predefined Size
When loaded from a file, most Models will have to be scaled up/down before you can use them in your application. This Recipe shows you how you can scale a Model to a size of your choice immediately when it is loaded into your XNA project.

4-7. Render a Model Using Custom Effects and Custom Textures (Easy Approach)
This recipe explains how you can use your own HLSL effects to render a Model.

4-8. Visualize the Bone Structure of a Model
Before you can move over to animation, you need to know how to visualize the Bone structure of a 3D Model. In this recipe, you値l learn how you can automatically write down this Bone structure to a .txt file.

4-9. Make the Bones Move Individually: Model Animation
This recipe shows how you can move/rotate the different parts of Model, for example rotate the turret and canon of a tank.

4-10. Use BoundingSpheres for Basic Model Collision Detection
This recipe uses the global BoundingSphere of a 3D Model to quickly perform a coarse check for possible collisions between other Models.

4-11. Use Ray-Traced Collision Detection for Small/Fast Objects
You might run into trouble detecting collisions between small, very fast objects (such as bullets). This recipe shows you how you can use the Ray class to detect collisions at any speed.

4-12. Extend the Model Content Processor to Load Custom Effects (Clean Approach)
This recipe shows you how you can extend the default Model Processor. In this example, the Model will come into your XNA project with your HLSL effects loaded.

4-13. Gain Direct Access to Vertex Position Data by Extending the Model Processor
The Custom Model Processor created in this recipe give you XNA code full access to all vertices of your Model.

4-14. Gain Direct Access to Vertex Position Data of Each ModelMesh by Extending the Model Processor
This recipe explores the structure of the Model, as it stores the vertices by ModelMesh, instead of putting them all together as in the previous recipe.

4-15. Gain Direct Access to Vertex Position Data by Defining a Custom TypeWriter and TypeReader
This recipe shows how you can pass objects of a custom class from your Content Processor to your XNA code by coding your own TypeReader and TypeWriter.

4-16. Store Multiple Objects in the Tag Property by Defining a Custom TypeWriter and TypeReader
The Tag property of the Model is extremely useful for passing data from the Content Processor to your XNA code. However, you can only store a single object in this property. This recipe shows you how you can solve this, by writing another custom TypeWriter and TypeReader.

4-17. Correctly Tilt a Model Corresponding to the Terrain Underneath
What good is a terrain if you cannot move your objects over it? In this recipe, you値l learn how to correctly position a four-wheel vehicle on your terrain, so its four wheels touch the ground.

4-18. Detect Ray-Model Collisions Using Per-Triangle Checks
For the finest of collision detections, you need to be able to check whether a Ray collides with a triangle. In this mathematically advanced recipe, you値l learn how to detect collisions between a Ray and any triangle of a Model. This recipe is written so it remains valid even for animated Models.

4-19. Detect Whether the Pointer Is Over a Model
Although it seems trivial to detect whether the mouse pointer is over a 3D Model, this is quite difficult as it comes down to checking whether a 3D ray collides with the Model. The result of the previous recipe is used to solve this, while you値l get more insight on how the 3D -> Screen transformation works.





Recipe 4-17: A tank is being tilted around its X and Z axes so its four wheels touch the ground.


Google
 
Webwww.riemers.net


If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !



- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans
Translations

This site in English
This site in Korean
This site in Czech

Microsoft MVP Award



2007 - 2011 MVP Award
DirectX - XNA

Contents

News
Home
Forum
XNA 2.0 Recipes Book (8)
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
XNA 3.0 Recipes Book (8)
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Team Project (1)
News
Tutorials (160)
XNA 4.0 using C# (89)
2D Series: Shooters (22)
Starting a project
Drawing fullscreen images
Positioning images
SpriteBatch.Draw()
Rotation
Keyboard input
Writing text
Angle to Direction
Direction to Angle
Smoke trail
Manual texture creation
Random terrain
Texture to Colors
Coll Detection Overview
Coll Detection Matrices
Putting CD into practice
Particles
Additive alpha blending
Particle engine
Adding craters
Sound in XNA
Resolution independency
3D Series 1: Terrain (13)
Starting a project
The effect file
The first triangle
World space
Rotation - translation
Indices
Terrain basics
Terrain from file
Keyboard
Adding colors
Lighting basics
Terrain lighting
VertexBuffer & IndexBuffer
3D Series 2: Flightsim (14)
Starting point
Textures
Loading the floorplan
Creating the 3D city
Loading a Model
Ambient and diffuse
Quaternion camera
Flight kinematics
Collision detection
Adding targets
Point sprites
Alpha blending
Skybox
Camera delay
3D Series 3: HLSL (18)
Starting point
HLSL introduction
Vertex format
Vertex shader
Pixel shader
Per-pixel colors
Textured triangle
Triangle strip
World transform
World normals
Per-pixel lighting
Shadow map
Render to texture
Projective texturing
Real shadow
Shaping the light
Preshaders
3D Series 4: Adv. terrain (19)
Starting code
Mouse camera
Textured terrain
Multitexturing
Adding detail
Skydome
The water technique
Refraction map
Reflection map
Perfect mirror
Ripples
The Fresnel term
Moving water
Specular highlights
Billboarding
Region growing
Billboarding renderstates
Perlin noise
Gradient skybox
Short Tuts (3)
Run XNA on older pcs
MessageBox in XNA
Normal generation
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Starting code
Textures
The floorplan
Creating the 3D City
Meshloading from file
Ambient light
Action
Flight kinematics
Collision detection
Skybox
Texture filtering
Adding targets
Point sprites
Alpha blending
DirectSound
Sounds in 3D
Playing MP3 files
Displaying text
Going fullscreen
Series 3: HLSL (19)
Starting point
HLSL Introduction
Vertex Shader
Shaded triangle
Pixel Shader
Textured Triangle
Triangle Strip
World transform
Adding normals
The first light
Shadow mapping
Render To Texture
Projective texturing
The first shadow
Shaping the light
Preshaders
Multiple lights
Adjusting Z values
Finishing touch
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
Series 1: Terrain (15)
Opening a window
Ending the game loop
Linking to the Device
Clearing your window
Drawing a triangle
Culling
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing .bmp files
Adding colors
DirectX Light basics
DirectX using VB (2)
Series 1: Intro (2)
The first triangle
Rotation - translation
-- Tree view --


Thank you!

Support this site --
any amount is welcome !

Stay up-to-date

I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!