4. Some 3D Modeling Programs
• 3D Max
• Maya
• Blender
• Wings3D
• Google SketchUp
• … etc
5. Using 3D Models - Loading the Model
• Global Scope
private Model model; Initialize
LoadContent
UnloadContent
Update
Draw
Game1
6. Using 3D Models - Loading the Model
• Global Scope
• LoadContent()
private Model model;
model = Content.Load<Model>("Ship");
Initialize
LoadContent
UnloadContent
Update
Draw
Game1
7. Using 3D Models - Drawing the Model
• Must set appropriate matrices
private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
private Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10),
new Vector3(0, 0, 0),
Vector3.UnitY);
private Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 480f,
0.1f,
100f);
12. BasicEffect
• Effects in XNA
– An effect is simply a method of designating how an object should be rendered on the screen.
– In the past (graphics API)
• tell the graphics card everything it needed to know
– HLSL
– It can be quite a bit of work to create a complete effect from scratch
• XNA guys delivered to us the “BasicEffect” class
21. Lighting
• Diffuse Light
– Diffuse light is the basic kind of light. This is the kind of light that lights an object we are
viewing, for the most part. The intensity of the light mostly comes from the angle the surface
makes with the light itself, so surfaces that face away from the light don't aren't bright at all,
while surfaces that face the light are lit up pretty well.
22. Lighting
• Specular Light
– Specular light (or specular highlights) are the shiny spots that appear when an object is
somewhat reflective. This light is based on how reflective the surface is, as well as the angle
that is being made between the light source, the surface, and the viewer.
23. Lighting
• Ambient Light
– Ambient light is light that doesn't come from any particular light source, but instead is kind of
"background light" that comes from all over. In the real world, there is always a small amount
of ambient light, and in our game, we will want to add a little bit to make our objects look
more realistic.
24. Lighting
• Emissive Light
– Emissive light is light that is coming from the surface itself. In games, however, emissive light
doesn't automatically light up nearby objects, so it often doesn't have the same effect that we
would like, but it still has its uses.
25. Lighting with the BasicEffect Class
• Default Lighting
effect.EnableDefaultLighting();
26. Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
27. Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
effect.LightingEnabled = true; // turn on the lighting subsystem.
effect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0, 0); // a red light
effect.DirectionalLight0.Direction = new Vector3(1, 0, 0); // coming along the x-axis
effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0); // with green highlights
28. Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
effect.LightingEnabled = true; // turn on the lighting subsystem.
effect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0, 0); // a red light
effect.DirectionalLight0.Direction = new Vector3(1, 0, 0); // coming along the x-axis
effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0); // with green highlights
R G B
29. Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
effect.LightingEnabled = true; // turn on the lighting subsystem.
effect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0, 0); // a red light
effect.DirectionalLight0.Direction = new Vector3(1, 0, 0); // coming along the x-axis
effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0); // with green highlights
R G B
X Y Z
30. Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
effect.LightingEnabled = true; // turn on the lighting subsystem.
effect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0, 0); // a red light
effect.DirectionalLight0.Direction = new Vector3(1, 0, 0); // coming along the x-axis
effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0); // with green highlights
R G B
X Y Z
R G B
31.
32. Lighting with the BasicEffect Class
• You can turn individual lights on and off with
• you can set the effect's ambient light color
effect.DirectionalLight0.Enabled = false;
effect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f);
effect.EmissiveColor = new Vector3(1, 0, 0);
36. BasicEffect Fog
• Rendering Fog with the BasicEffect Class
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 9.75f;
effect.FogEnd = 10.25f;
37. BasicEffect Fog
• Rendering Fog with the BasicEffect Class
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 9.75f;
effect.FogEnd = 10.25f;
46. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
47. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
48. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
49. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
50. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
LoadContent() Update() Draw()
51. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
LoadContent() Update() Draw()
52. 3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
53. 3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
54. 3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
55. 3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
56. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
57. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
58. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
59. 3D Animation
• Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
67. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
72. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
73. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
74. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
75. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
76. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
77. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
position= new Vector3(0, 0, 0);
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
78. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
private float angle;
position= new Vector3(0, 0, 0);
angle = 0;
position += new Vector3(0, 0.01f, 0);
world = Matrix.CreateTranslation(position);
3D Animation
79. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
private float angle;
position= new Vector3(0, 0, 0);
angle = 0;
position += new Vector3(0, 0.01f, 0);
angle += 0.03f;
world = Matrix.CreateTranslation(position);
3D Animation
80. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
private float angle;
position= new Vector3(0, 0, 0);
angle = 0;
position += new Vector3(0, 0.01f, 0);
angle += 0.03f;
world = Matrix.CreateTranslation(position);
3D Animation
81. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
private float angle;
position= new Vector3(0, 0, 0);
angle = 0;
position += new Vector3(0, 0.01f, 0);
angle += 0.03f;
world = Matrix.CreateRotationY(angle) *
Matrix.CreateTranslation(position);
3D Animation
82. • Create a Place to Store the Position
• Initialize the Position
• Creating animation/ Updating Position!
private Vector3 position;
private float angle;
position= new Vector3(0, 0, 0);
angle = 0;
position += new Vector3(0, 0.01f, 0);
angle += 0.03f;
world = Matrix.CreateRotationY(angle) *
Matrix.CreateTranslation(position);
3D Animation
86. Mesh-by-Mesh Animation
• Firing Up!
– Setup
• We will first need to acquire a model that has different parts that will allow us to do the movements
that we want
• Our "Helicopter" model included in appendix
92. Mesh-by-Mesh Animation
• Loading the model in LoadContent() method
• Updating the angles and location of the Helicopter model in Update()method
helicopterModel = Content.Load<Model>("Helicopter");
tailRotorAngle -= 0.15f;
mainRotorAngle -= 0.15f;
angle += 0.02f;
location += Vector3.Transform(new Vector3(0.1f, 0, 0),
Matrix.CreateRotationY(MathHelper.ToRadians(90) + angle));