SlideShare uma empresa Scribd logo
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2011, 2012, 2013, 2014
XNA Game Development
L03 – Models, BasicEffect and Animation
Using 3D Models
Using 3D Models
Why using models?!
Some 3D Modeling Programs
• 3D Max
• Maya
• Blender
• Wings3D
• Google SketchUp
• … etc
Using 3D Models - Loading the Model
• Global Scope
private Model model; Initialize
LoadContent
UnloadContent
Update
Draw
Game1
Using 3D Models - Loading the Model
• Global Scope
• LoadContent()
private Model model;
model = Content.Load<Model>("Ship");
Initialize
LoadContent
UnloadContent
Update
Draw
Game1
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);
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
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
Using 3D Models
• “App-Using3DModels”
BasicEffect
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
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);
}
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);
}
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);
}
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();
}
}
BasicEffect
• Changing BasicEffect Texture
effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
BasicEffect
• Changing BasicEffect Texture
effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
BasicEffect
• Not using Texture!
effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
Lighting
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.
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.
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.
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.
Lighting with the BasicEffect Class
• Default Lighting
effect.EnableDefaultLighting();
Lighting with the BasicEffect Class
• Default Lighting
• Custom Lighting
effect.EnableDefaultLighting();
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
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
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
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
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);
Lighting with the BasicEffect Class
• “App2-BasicEffectLighting”
BasicEffect Fog
Why using fog?
BasicEffect Fog
Why using fog?
For instance; Can be used to hide a close far-clipping plane
BasicEffect Fog
• Rendering Fog with the BasicEffect Class
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 9.75f;
effect.FogEnd = 10.25f;
BasicEffect Fog
• Rendering Fog with the BasicEffect Class
effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 9.75f;
effect.FogEnd = 10.25f;
3D Animation
Basic Matrices
Basic Matrices
Basic Matrices
Basic Matrices
Basic Matrices
Basic Matrices
3D Animation
• Create a Place to Store the Position
private Vector3 position;
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);
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);
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);
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);
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()
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()
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
3D Animation
• Now we want to move the Model
– “Attaching position vector with our model”
world = Matrix.CreateTranslation(position);
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);
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);
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);
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);
3D Animation
3D Animation
3D Animation
3D Animation
3D Animation
3D Animation
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);
3D Animation
3D Animation
3D Animation
3D Animation
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);
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);
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);
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);
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);
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);
3D Animation
• 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
• 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
• 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
• 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
• 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
3D Animation
• “App1-Animation”
Mesh-by-Mesh Animation
Mesh-by-Mesh Animation
What’s that?
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
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);
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);
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);
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);
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);
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));
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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();
}
}
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();
}
}
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();
}
}
Mesh-by-Mesh Animation
• Test it live
• “App1-Mesh-by-MeshAnimation”

Mais conteúdo relacionado

Mais procurados

Computer Vision harris
Computer Vision harrisComputer Vision harris
Computer Vision harris
Wael Badawy
 
Lec2
Lec2Lec2
A practical intro to BabylonJS
A practical intro to BabylonJSA practical intro to BabylonJS
A practical intro to BabylonJS
HansRontheWeb
 
Ch32 ssm
Ch32 ssmCh32 ssm
Ch32 ssm
Marta Díaz
 
Anschp34
Anschp34Anschp34
Anschp34
FnC Music
 
Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...
Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...
Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...
Daniel Barrero
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
livedoor
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
05 Views
05 Views05 Views
05 Views
Mahmoud
 
WaterFlowUDK
WaterFlowUDKWaterFlowUDK
WaterFlowUDK
min9202
 
Shadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareShadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL Hardware
Mark Kilgard
 
CS193P Lecture 5 View Animation
CS193P Lecture 5 View AnimationCS193P Lecture 5 View Animation
CS193P Lecture 5 View Animation
onoaonoa
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
Richard Jones
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
Richard Jones
 
Applets
AppletsApplets
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
Marakana Inc.
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
Maximizing performance of 3 d user generated assets in unity
Maximizing performance of 3 d user generated assets in unityMaximizing performance of 3 d user generated assets in unity
Maximizing performance of 3 d user generated assets in unity
WithTheBest
 
2. reflection (solved example + exercise)
2. reflection (solved example + exercise)2. reflection (solved example + exercise)
2. reflection (solved example + exercise)
SameepSehgal1
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
Mark Kilgard
 

Mais procurados (20)

Computer Vision harris
Computer Vision harrisComputer Vision harris
Computer Vision harris
 
Lec2
Lec2Lec2
Lec2
 
A practical intro to BabylonJS
A practical intro to BabylonJSA practical intro to BabylonJS
A practical intro to BabylonJS
 
Ch32 ssm
Ch32 ssmCh32 ssm
Ch32 ssm
 
Anschp34
Anschp34Anschp34
Anschp34
 
Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...
Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...
Company of Heroes 2 (COH2) Rendering Technology: The cold facts of recreating...
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
05 Views
05 Views05 Views
05 Views
 
WaterFlowUDK
WaterFlowUDKWaterFlowUDK
WaterFlowUDK
 
Shadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareShadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL Hardware
 
CS193P Lecture 5 View Animation
CS193P Lecture 5 View AnimationCS193P Lecture 5 View Animation
CS193P Lecture 5 View Animation
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Applets
AppletsApplets
Applets
 
Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)Graphicsand animations devoxx2010 (1)
Graphicsand animations devoxx2010 (1)
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
 
Maximizing performance of 3 d user generated assets in unity
Maximizing performance of 3 d user generated assets in unityMaximizing performance of 3 d user generated assets in unity
Maximizing performance of 3 d user generated assets in unity
 
2. reflection (solved example + exercise)
2. reflection (solved example + exercise)2. reflection (solved example + exercise)
2. reflection (solved example + exercise)
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 

Destaque

How to create an effective presentation
How to create an effective presentationHow to create an effective presentation
How to create an effective presentation
MCroce25
 
Basic PowerPoint Guidelines
Basic PowerPoint GuidelinesBasic PowerPoint Guidelines
Basic PowerPoint Guidelines
Caitlyn Garlock
 
Basic Guidelines For PowerPoint Presentation
Basic Guidelines For PowerPoint PresentationBasic Guidelines For PowerPoint Presentation
Basic Guidelines For PowerPoint Presentation
Nikki Dapanas
 
Powerpoint Design Simple Rules
Powerpoint Design Simple RulesPowerpoint Design Simple Rules
Powerpoint Design Simple Rules
mahoneyoregon
 
Powerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign Samples
Powerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign SamplesPowerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign Samples
Powerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign Samples
The Presentation Team - Professional PowerPoint Design and Training
 
How to create an effective presentation
How to create an effective presentationHow to create an effective presentation
How to create an effective presentation
Kay Franklin
 
Effective Design in PowerPoint
Effective Design in PowerPoint Effective Design in PowerPoint
Effective Design in PowerPoint
Soni Amit K
 
Guidelines on Developing Effective PowerPoint Presentation
Guidelines on Developing Effective PowerPoint PresentationGuidelines on Developing Effective PowerPoint Presentation
Guidelines on Developing Effective PowerPoint Presentation
Asif Mehmood, CLDP
 
Presentation Skills - Presenting to a Group
Presentation Skills - Presenting to a Group Presentation Skills - Presenting to a Group
Presentation Skills - Presenting to a Group
Ossama Motawae
 
How to make effective presentation
How to make effective presentationHow to make effective presentation
How to make effective presentation
Satyajeet Singh
 

Destaque (10)

How to create an effective presentation
How to create an effective presentationHow to create an effective presentation
How to create an effective presentation
 
Basic PowerPoint Guidelines
Basic PowerPoint GuidelinesBasic PowerPoint Guidelines
Basic PowerPoint Guidelines
 
Basic Guidelines For PowerPoint Presentation
Basic Guidelines For PowerPoint PresentationBasic Guidelines For PowerPoint Presentation
Basic Guidelines For PowerPoint Presentation
 
Powerpoint Design Simple Rules
Powerpoint Design Simple RulesPowerpoint Design Simple Rules
Powerpoint Design Simple Rules
 
Powerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign Samples
Powerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign SamplesPowerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign Samples
Powerful PowerPoint Makeovers: PowerPoint Design & Presentation Redesign Samples
 
How to create an effective presentation
How to create an effective presentationHow to create an effective presentation
How to create an effective presentation
 
Effective Design in PowerPoint
Effective Design in PowerPoint Effective Design in PowerPoint
Effective Design in PowerPoint
 
Guidelines on Developing Effective PowerPoint Presentation
Guidelines on Developing Effective PowerPoint PresentationGuidelines on Developing Effective PowerPoint Presentation
Guidelines on Developing Effective PowerPoint Presentation
 
Presentation Skills - Presenting to a Group
Presentation Skills - Presenting to a Group Presentation Skills - Presenting to a Group
Presentation Skills - Presenting to a Group
 
How to make effective presentation
How to make effective presentationHow to make effective presentation
How to make effective presentation
 

Semelhante a XNA L03–Models, Basic Effect and Animation

Real life XNA
Real life XNAReal life XNA
Real life XNA
Johan Lindfors
 
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientTh 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Bin Shao
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
Robyn Overstreet
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
Model View Intent on Android
Model View Intent on AndroidModel View Intent on Android
Model View Intent on Android
Cody Engel
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platform
goodfriday
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
gerbille
 
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxasmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
fredharris32
 
HTML5 game dev with three.js - HexGL
HTML5 game dev with three.js - HexGLHTML5 game dev with three.js - HexGL
HTML5 game dev with three.js - HexGL
Thibaut Despoulain
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
Fabio506452
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
Mohammad Shaker
 
COMP340 TOPIC 4 THREE.JS.pptx
COMP340 TOPIC 4 THREE.JS.pptxCOMP340 TOPIC 4 THREE.JS.pptx
COMP340 TOPIC 4 THREE.JS.pptx
Egerton University
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
XNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle EnginesXNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle Engines
Mohammad Shaker
 
Top Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsTop Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on Tablets
Motorola Mobility - MOTODEV
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
Stephen Lorello
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
Naman Dwivedi
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
Tomi Aarnio
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
Stacy Goh
 

Semelhante a XNA L03–Models, Basic Effect and Animation (20)

Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficientTh 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Model View Intent on Android
Model View Intent on AndroidModel View Intent on Android
Model View Intent on Android
 
Silverlight as a Gaming Platform
Silverlight as a Gaming PlatformSilverlight as a Gaming Platform
Silverlight as a Gaming Platform
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docxasmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
asmt7~$sc_210_-_assignment_7_fall_15.docasmt7cosc_210_-_as.docx
 
HTML5 game dev with three.js - HexGL
HTML5 game dev with three.js - HexGLHTML5 game dev with three.js - HexGL
HTML5 game dev with three.js - HexGL
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and TerrainXNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
 
COMP340 TOPIC 4 THREE.JS.pptx
COMP340 TOPIC 4 THREE.JS.pptxCOMP340 TOPIC 4 THREE.JS.pptx
COMP340 TOPIC 4 THREE.JS.pptx
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconfbuilding_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
 
XNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle EnginesXNA L09–2D Graphics and Particle Engines
XNA L09–2D Graphics and Particle Engines
 
Top Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsTop Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on Tablets
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 

Mais de Mohammad Shaker

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
Mohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
Mohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
Mohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
Mohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
Mohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
Mohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
Mohammad Shaker
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
Mohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
Mohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
Mohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
Mohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
Mohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
Mohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
Mohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
Mohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
Mohammad Shaker
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
Mohammad Shaker
 

Mais de Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 

Último

"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 

Último (20)

"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 

XNA L03–Models, Basic Effect and Animation

  • 1. Mohammad Shaker mohammadshaker.com @ZGTRShaker 2011, 2012, 2013, 2014 XNA Game Development L03 – Models, BasicEffect and Animation
  • 3. Using 3D Models Why using models?!
  • 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);
  • 8. 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
  • 9. 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
  • 10. Using 3D Models • “App-Using3DModels”
  • 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
  • 13. 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); }
  • 14. 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); }
  • 15. 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); }
  • 16. 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(); } }
  • 17. BasicEffect • Changing BasicEffect Texture effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
  • 18. BasicEffect • Changing BasicEffect Texture effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
  • 19. BasicEffect • Not using Texture! effect.Texture = otherTexture; // otherTexture is of the type "Texture2D"
  • 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);
  • 33. Lighting with the BasicEffect Class • “App2-BasicEffectLighting”
  • 35. BasicEffect Fog Why using fog? For instance; Can be used to hide a close far-clipping plane
  • 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;
  • 45. 3D Animation • Create a Place to Store the Position private Vector3 position;
  • 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
  • 87. 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);
  • 88. 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);
  • 89. 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);
  • 90. 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);
  • 91. 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);
  • 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));
  • 93. 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); }
  • 94. 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); }
  • 95. 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); }
  • 96. 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); }
  • 97. 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); }
  • 98. 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); }
  • 99. 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); }
  • 100. 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); }
  • 101. 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); }
  • 102. 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(); } }
  • 103. 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(); } }
  • 104. 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(); } }
  • 105. Mesh-by-Mesh Animation • Test it live • “App1-Mesh-by-MeshAnimation”