1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using XNAExtras;
#endregion
namespace WindowsGame4
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
ContentManager content;
Model modele;
Vector3 camPos = new Vector3(200.0f, 100.0f, 200.0f);
float FOV = 45.0f;
float vitesse = 1.0f;
BitmapFont font;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
protected override void Initialize()
{
font = new BitmapFont("courier.xml");
base.Initialize();
}
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
modele = content.Load<Model>("sol");
}
font.Reset(graphics.GraphicsDevice);
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent == true)
{
content.Unload();
}
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (Keyboard.GetState().IsKeyDown(Keys.S))
{
camPos.X += vitesse;
}
if (Keyboard.GetState().IsKeyDown(Keys.Z))
{
camPos.X -= vitesse;
}
if (Keyboard.GetState().IsKeyDown(Keys.Up))
{
camPos.Y += vitesse;
}
if (Keyboard.GetState().IsKeyDown(Keys.Down))
{
camPos.Y -= vitesse;
}
if (Keyboard.GetState().IsKeyDown(Keys.NumPad8))
{
camPos.Z -= vitesse;
}
if (Keyboard.GetState().IsKeyDown(Keys.NumPad2))
{
camPos.Z += vitesse;
}
if (Keyboard.GetState().IsKeyDown(Keys.Subtract))
{
if (FOV < 90)
{
FOV++;
}
}
if (Keyboard.GetState().IsKeyDown(Keys.Add))
{
if (FOV > 30)
{
FOV--;
}
}
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
FOV = 45.0f;
}
if (Keyboard.GetState().IsKeyDown(Keys.F1))
{
vitesse = 0.5f;
}
if (Keyboard.GetState().IsKeyDown(Keys.F2))
{
vitesse = 1.0f;
}
if (Keyboard.GetState().IsKeyDown(Keys.F3))
{
vitesse = 2.0f;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.Red);
float ratio = 640.0f/480.0f;
Matrix[] transformation = new Matrix[modele.Bones.Count];
Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(FOV), ratio, 1.0f, 10000.0f);
Matrix view = Matrix.CreateLookAt(camPos, Vector3.Zero, Vector3.Up);
modele.CopyAbsoluteBoneTransformsTo(transformation);
foreach (ModelMesh mesh in modele.Meshes)
{
foreach (BasicEffect basic in mesh.Effects)
{
basic.View = view;
basic.World = mesh.ParentBone.Transform;
basic.Projection = projection;
}
mesh.Draw();
}
font.DrawString(20, 20, Color.Blue, "X : " + camPos.X.ToString());
font.DrawString(20, 40, Color.Blue, "Y : " + camPos.Y.ToString());
font.DrawString(20, 60, Color.Blue, "Z : " + camPos.Z.ToString());
font.DrawString(20, 80, Color.Blue, "FOV : " + FOV.ToString());
base.Draw(gameTime);
}
}
} |
Partager