XNA L03–Models, Basic Effect and Animation
-
Upload
mohammad-shaker -
Category
Technology
-
view
312 -
download
0
Transcript of XNA L03–Models, Basic Effect and Animation
![Page 1: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshaker.com
@ZGTRShaker2011, 2012, 2013, 2014
XNA Game DevelopmentL03 – Models, BasicEffect and Animation
![Page 2: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/2.jpg)
Using 3D Models
![Page 3: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/3.jpg)
Using 3D Models Why using models?!
![Page 4: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/4.jpg)
Some 3D Modeling Programs
• 3D Max
• Maya
• Blender
• Wings3D
• Google SketchUp
• … etc
![Page 5: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/5.jpg)
Using 3D Models - Loading the Model
• Global Scope
private Model model; Initialize
LoadContent
UnloadContent
Update
Draw
Game1
![Page 6: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/6.jpg)
Using 3D Models - Loading the Model
• Global Scope
• LoadContent()
private Model model;
model = Content.Load<Model>("Ship");
Initialize
LoadContent
UnloadContent
Update
Draw
Game1
![Page 7: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/7.jpg)
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);
![Page 8: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/8.jpg)
Using 3D Models
• DrawModel() and Draw()
private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
Initialize
LoadContent
UnloadContent
Update
Draw
Game1
![Page 9: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/9.jpg)
Using 3D Models
• DrawModel() and Draw()
private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
Initialize
LoadContent
UnloadContent
Update
Draw
Game1
![Page 10: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/10.jpg)
Using 3D Models
• “App-Using3DModels”
![Page 11: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/11.jpg)
BasicEffect
![Page 12: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/12.jpg)
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
![Page 13: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/13.jpg)
BasicEffect
protected override void Draw(GameTime gameTime){
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;basicEffect.View = view;basicEffect.Projection = projection;basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes){
pass.Apply(); GraphicsDevice.DrawUserPrimitives<> …
}base.Draw(gameTime);
}
![Page 14: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/14.jpg)
BasicEffect
protected override void Draw(GameTime gameTime){
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;basicEffect.View = view;basicEffect.Projection = projection;basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes){
pass.Apply(); GraphicsDevice.DrawUserPrimitives<> …
}base.Draw(gameTime);
}
![Page 15: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/15.jpg)
BasicEffect
protected override void Draw(GameTime gameTime){
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;basicEffect.View = view;basicEffect.Projection = projection;basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes){
pass.Apply(); GraphicsDevice.DrawUserPrimitives<> …
}base.Draw(gameTime);
}
![Page 16: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/16.jpg)
BasicEffect
private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection) {
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
![Page 17: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/17.jpg)
BasicEffect
• Changing BasicEffect Texture
effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
![Page 18: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/18.jpg)
BasicEffect
• Changing BasicEffect Texture
effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
![Page 19: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/19.jpg)
BasicEffect
• Not using Texture!
effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
![Page 20: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/20.jpg)
Lighting
![Page 21: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/21.jpg)
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.
![Page 22: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/22.jpg)
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.
![Page 23: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/23.jpg)
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.
![Page 24: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/24.jpg)
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.
![Page 25: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/25.jpg)
Lighting with the BasicEffect Class
• Default Lighting
effect.EnableDefaultLighting();
![Page 26: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/26.jpg)
Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
![Page 27: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/27.jpg)
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
![Page 28: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/28.jpg)
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
![Page 29: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/29.jpg)
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 BX Y Z
![Page 30: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/30.jpg)
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 BX Y Z
R G B
![Page 31: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/31.jpg)
![Page 32: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/32.jpg)
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);
![Page 33: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/33.jpg)
Lighting with the BasicEffect Class
• “App2-BasicEffectLighting”
![Page 34: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/34.jpg)
BasicEffect FogWhy using fog?
![Page 35: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/35.jpg)
BasicEffect FogWhy using fog?
For instance; Can be used to hide a close far-clipping plane
![Page 36: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/36.jpg)
BasicEffect Fog
• Rendering Fog with the BasicEffect Class
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 9.75f;
effect.FogEnd = 10.25f;
![Page 37: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/37.jpg)
BasicEffect Fog
• Rendering Fog with the BasicEffect Class
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 9.75f;
effect.FogEnd = 10.25f;
![Page 38: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/38.jpg)
3D Animation
![Page 39: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/39.jpg)
Basic Matrices
![Page 40: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/40.jpg)
Basic Matrices
![Page 41: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/41.jpg)
Basic Matrices
![Page 42: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/42.jpg)
Basic Matrices
![Page 43: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/43.jpg)
Basic Matrices
![Page 44: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/44.jpg)
Basic Matrices
![Page 45: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/45.jpg)
3D Animation
• Create a Place to Store the Position
private Vector3 position;
![Page 46: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/46.jpg)
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);
![Page 47: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/47.jpg)
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);
![Page 48: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/48.jpg)
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);
![Page 49: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/49.jpg)
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);
![Page 50: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/50.jpg)
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()
![Page 51: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/51.jpg)
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()
![Page 52: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/52.jpg)
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
![Page 53: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/53.jpg)
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
![Page 54: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/54.jpg)
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
![Page 55: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/55.jpg)
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
![Page 56: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/56.jpg)
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);
![Page 57: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/57.jpg)
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);
![Page 58: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/58.jpg)
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);
![Page 59: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/59.jpg)
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);
![Page 60: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/60.jpg)
3D Animation
![Page 61: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/61.jpg)
3D Animation
![Page 62: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/62.jpg)
3D Animation
![Page 63: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/63.jpg)
3D Animation
![Page 64: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/64.jpg)
3D Animation
![Page 65: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/65.jpg)
3D Animation
![Page 66: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/66.jpg)
3D Animation
![Page 67: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/67.jpg)
• 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
![Page 68: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/68.jpg)
3D Animation
![Page 69: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/69.jpg)
3D Animation
![Page 70: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/70.jpg)
3D Animation
![Page 71: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/71.jpg)
3D Animation
![Page 72: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/72.jpg)
• 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
![Page 73: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/73.jpg)
• 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
![Page 74: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/74.jpg)
• 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
![Page 75: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/75.jpg)
• 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
![Page 76: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/76.jpg)
• 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
![Page 77: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/77.jpg)
• 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
![Page 78: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/78.jpg)
• 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
![Page 79: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/79.jpg)
• 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
![Page 80: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/80.jpg)
• 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
![Page 81: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/81.jpg)
• 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
![Page 82: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/82.jpg)
• 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
![Page 83: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/83.jpg)
3D Animation
• “App1-Animation”
![Page 84: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/84.jpg)
Mesh-by-Mesh Animation
![Page 85: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/85.jpg)
Mesh-by-Mesh Animation What’s that?
![Page 86: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/86.jpg)
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
![Page 87: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/87.jpg)
Mesh-by-Mesh Animation
• Adding global variables
private Model helicopterModel;
private float mainRotorAngle = 0;
private float tailRotorAngle = 0;
private Vector3 location = new Vector3(0, 0, 0);
private float angle = 0f;
private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
private Matrix view = Matrix.CreateLookAt(new Vector3(10, 10, 10),
new Vector3(0, 0, 0),
Vector3.UnitY);
private Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f, 0.1f, 100f);
![Page 88: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/88.jpg)
Mesh-by-Mesh Animation
• Adding global variables
private Model helicopterModel;
private float mainRotorAngle = 0;
private float tailRotorAngle = 0;
private Vector3 location = new Vector3(0, 0, 0);
private float angle = 0f;
private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
private Matrix view = Matrix.CreateLookAt(new Vector3(10, 10, 10),
new Vector3(0, 0, 0),
Vector3.UnitY);
private Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f, 0.1f, 100f);
![Page 89: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/89.jpg)
Mesh-by-Mesh Animation
• Adding global variables
private Model helicopterModel;
private float mainRotorAngle = 0;
private float tailRotorAngle = 0;
private Vector3 location = new Vector3(0, 0, 0);
private float angle = 0f;
private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
private Matrix view = Matrix.CreateLookAt(new Vector3(10, 10, 10),
new Vector3(0, 0, 0),
Vector3.UnitY);
private Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f, 0.1f, 100f);
![Page 90: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/90.jpg)
Mesh-by-Mesh Animation
• Adding global variables
private Model helicopterModel;
private float mainRotorAngle = 0;
private float tailRotorAngle = 0;
private Vector3 location = new Vector3(0, 0, 0);
private float angle = 0f;
private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
private Matrix view = Matrix.CreateLookAt(new Vector3(10, 10, 10),
new Vector3(0, 0, 0),
Vector3.UnitY);
private Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f, 0.1f, 100f);
![Page 91: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/91.jpg)
Mesh-by-Mesh Animation
• Adding global variables
private Model helicopterModel;
private float mainRotorAngle = 0;
private float tailRotorAngle = 0;
private Vector3 location = new Vector3(0, 0, 0);
private float angle = 0f;
private Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
private Matrix view = Matrix.CreateLookAt(new Vector3(10, 10, 10),
new Vector3(0, 0, 0),
Vector3.UnitY);
private Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f, 0.1f, 100f);
![Page 92: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/92.jpg)
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));
![Page 93: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/93.jpg)
Mesh-by-Mesh Animation
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 94: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/94.jpg)
Mesh-by-Mesh Animation
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 95: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/95.jpg)
Mesh-by-Mesh Animation
• New Draw() method
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 96: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/96.jpg)
Mesh-by-Mesh Animation
• New Draw() methodprotected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 97: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/97.jpg)
Mesh-by-Mesh Animation
• New Draw() methodprotected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 98: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/98.jpg)
Mesh-by-Mesh Animation
• New Draw() methodprotected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 99: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/99.jpg)
Mesh-by-Mesh Animation
• New Draw() methodprotected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 100: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/100.jpg)
Mesh-by-Mesh Animation
• New Draw() methodprotected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 101: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/101.jpg)
Mesh-by-Mesh Animation
• New Draw() methodprotected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] meshWorlds = new Matrix[3];
meshWorlds[0] = Matrix.CreateTranslation(new Vector3(0, 0, 0));
meshWorlds[1] = Matrix.CreateRotationY(mainRotorAngle);
meshWorlds[2] = Matrix.CreateTranslation(new Vector3(0, -0.25f, -3.4f)) *
Matrix.CreateRotationX(tailRotorAngle) *
Matrix.CreateTranslation(new Vector3(0, 0.25f, 3.4f));
world = Matrix.CreateRotationY(angle) * Matrix.CreateTranslation(location);
DrawModel(helicopterModel, world, meshWorlds, view, projection);
base.Draw(gameTime);
}
![Page 102: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/102.jpg)
Mesh-by-Mesh Animation
• Creating a new DrawModel() method as we did before
private void DrawModel(Model model, Matrix world, Matrix[] meshWorlds, Matrix view, Matrix
projection)
{
for (int index = 0; index < model.Meshes.Count; index++)
{
ModelMesh mesh = model.Meshes[index];
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = mesh.ParentBone.Transform * meshWorlds[index] * world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
![Page 103: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/103.jpg)
Mesh-by-Mesh Animation
• Creating a new DrawModel() method as we did before
private void DrawModel(Model model, Matrix world, Matrix[] meshWorlds, Matrix view, Matrix
projection)
{
for (int index = 0; index < model.Meshes.Count; index++)
{
ModelMesh mesh = model.Meshes[index];
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = mesh.ParentBone.Transform * meshWorlds[index] * world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
![Page 104: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/104.jpg)
Mesh-by-Mesh Animation
• Creating a new DrawModel() method as we did before
private void DrawModel(Model model, Matrix world, Matrix[] meshWorlds, Matrix view, Matrix
projection)
{
for (int index = 0; index < model.Meshes.Count; index++)
{
ModelMesh mesh = model.Meshes[index];
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = mesh.ParentBone.Transform * meshWorlds[index] * world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
![Page 105: XNA L03–Models, Basic Effect and Animation](https://reader033.fdocuments.net/reader033/viewer/2022052823/5553b470b4c905d9448b4c70/html5/thumbnails/105.jpg)
Mesh-by-Mesh Animation
• Test it live
• “App1-Mesh-by-MeshAnimation”