using
System;
using
System.Collections.Generic;
using
Microsoft.Xna.Framework;
using
Microsoft.Xna.Framework.Content;
using
Microsoft.Xna.Framework.GamerServices;
using
Microsoft.Xna.Framework.Graphics;
using
Microsoft.Xna.Framework.Input;
using
Microsoft.Xna.Framework.Storage;
public
class GameClass
: Microsoft.Xna.Framework.Game
{
float dist = -20.0f;
Vector2 rot =
new Vector2();
GraphicsDeviceManager graphics;
Model myModel;
public GameClass()
{
graphics =
new
GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override
void LoadContent()
{
myModel =
Content.Load<Model>("basiccar");
}
protected override
void Draw(GameTime
gameTime)
{
// Just a few lines that let the controller move
the camera
// all the way around our 3d model...mode is at
(0,0,0)
rot.Y +=
GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X
* 0.05f;
rot.X -=
GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y
* 0.05f;
dist +=
GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y
* 0.1f;
Vector3 dir =
Vector3.Transform(new
Vector3(0, 0, 1),
Matrix.CreateRotationX(rot.X)
* Matrix.CreateRotationY(rot.Y));
Vector3 camPos = dir * dist;
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix worldMatrix =
Matrix.CreateScale(0.01f, 0.01f, 0.01f) ;
Matrix[] modelTransforms =
new Matrix[myModel.Bones.Count];
myModel.CopyBoneTransformsTo(modelTransforms);
foreach (ModelMesh
mesh in myModel.Meshes)
{
foreach (BasicEffect
effect in mesh.Effects)
{
GraphicsDevice device =
graphics.GraphicsDevice;
effect.EnableDefaultLighting();
effect.World = modelTransforms[mesh.ParentBone.Index] * worldMatrix;
float aspectRatio = (float)device.Viewport.Width
/ device.Viewport.Height;
effect.View = Matrix.CreateLookAt(camPos,
Vector3.Zero,
Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f),
aspectRatio,
1.0f,
1000.0f);
}
mesh.Draw();
}
base.Draw(gameTime);
}
}
static
class Program
{
static void
Main(string[] args)
{
using (GameClass
game = new
GameClass())
{
game.Run();
}
}
}
|