Les bases de la programmation 3D
CHAPITRE 12
269
Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 0.001f,
➥1000f, out projection);
Matrix.CreateLookAt(ref cameraPosition, ref cameraTarget, ref
➥cameraUpVector, out view);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
vertices = CreateShape();
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration
➥(graphics.GraphicsDevice, VertexPositionColor.VertexElements);
BasicEffect effect = new BasicEffect(graphics.GraphicsDevice, null);
effect.Projection = projection;
effect.View = view;
effect.LightingEnabled = false;
effect.Begin();
foreach (EffectPass CurrentPass in effect.CurrentTechnique.Passes)
{
CurrentPass.Begin();
graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList,
➥vertices, 0, vertices.Length / 3);
CurrentPass.End();
}
effect.End();
base.Draw(gameTime);
}
private VertexPositionColor[] CreateShape()
{
VertexPositionColor[] vertices = new VertexPositionColor[3];
// Top left corner
vertices[0] = new VertexPositionColor(new Vector3(-1, 1, 0), Color.White);
=Labat FM.book Page 269 Vendredi, 19. juin 2009 4:01 16
Précédent

- 290/366

Suivant