Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace XNAGame2
- {
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- InputGame pInput = new InputGame();
- private static int screenWidth = 800;
- private static int screenHieght = 600;
- private static float aspectRatio = screenWidth / screenHieght;
- private static float angleInRadians;
- private static float camYaw = 0;
- private static float camPitch = 0;
- private static float camRoll = 0;
- private static float camX = 0f;
- private static float camY = 400f;
- private static float camZ = -500f;
- private static Vector3 modelPosition;
- private static Vector3 camPosition = new Vector3(camX, camY, camZ);
- private static Vector3 camTarget = new Vector3(modelPosition.X, modelPosition.Y, modelPosition.Z);
- private static Vector3 camUpVector = Vector3.Up;
- private static Model model;
- private Model terrain;
- Matrix world;
- Matrix view;
- Matrix projection;
- //Matrix world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
- // Matrix view = Matrix.CreateLookAt(camPosition, camTarget, camUpVector);
- // Matrix projection = Matrix.CreatePerspectiveFieldOfView(
- // MathHelper.ToRadians(45), aspectRatio, 0.1f, 10000f);
- Matrix camYawPitch = Matrix.CreateFromYawPitchRoll(camYaw, camPitch, camRoll);
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- this.graphics.PreferredBackBufferWidth = screenWidth;
- this.graphics.PreferredBackBufferHeight = screenHieght;
- //this.graphics.IsFullScreen = true;
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- model = Content.Load<Model>("Models//shockmodel");
- terrain = Content.Load<Model>("Models//terraintest");
- modelPosition = new Vector3(0, 0, 0);
- angleInRadians = 0;
- aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed
- || Keyboard.GetState().IsKeyDown(Keys.Escape))
- this.Exit();
- modelPosition += new Vector3(0, 0.5f, 0);
- angle();
- world = Matrix.CreateRotationY(angleInRadians) * Matrix.CreateTranslation(modelPosition);
- pInput.gamePadConnection();
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- DrawModel(model);
- DrawTerrain(terrain);
- base.Draw(gameTime);
- }
- private void DrawModel(Model obj)
- {
- Matrix[] transforms = new Matrix[obj.Bones.Count];
- obj.CopyAbsoluteBoneTransformsTo(transforms);
- foreach (ModelMesh mesh in obj.Meshes)
- {
- foreach (BasicEffect effect in mesh.Effects)
- {
- effect.EnableDefaultLighting();
- //effect.LightingEnabled = true;
- //effect.AmbientLightColor = new Vector3(0.1f, 0.05f, 0.2f);
- //effect.EmissiveColor = new Vector3(0, 0, 0.15f);
- effect.FogEnabled = true;
- effect.FogColor = Color.CornflowerBlue.ToVector3();
- effect.FogStart = 550.75f;
- effect.FogEnd = 700.0f;
- effect.World = matrixWorld();
- effect.View = matrixView();
- effect.Projection = matrixProjection();
- }
- prepare3d();
- mesh.Draw();
- }
- }
- private void DrawTerrain(Model terrain)
- {
- Matrix[] transforms = new Matrix[terrain.Bones.Count];
- terrain.CopyAbsoluteBoneTransformsTo(transforms);
- foreach (ModelMesh mesh in terrain.Meshes)
- {
- foreach (BasicEffect effect in mesh.Effects)
- {
- effect.EnableDefaultLighting();
- effect.PreferPerPixelLighting = true;
- effect.World = matrixWorld();
- effect.View = matrixView();
- effect.Projection = matrixProjection();
- }
- prepare3d();
- mesh.Draw();
- }
- }
- public float angle()
- {
- angleInRadians += 0.01f;
- return angleInRadians;
- }
- public Matrix matrixWorld()
- {
- world = Matrix.CreateTranslation(new Vector3(0, 0, 0));
- return world;
- }
- public Matrix matrixView()
- {
- view = Matrix.CreateLookAt(camPosition, camTarget, camUpVector);
- return view;
- }
- public Matrix matrixProjection()
- {
- Matrix projection = Matrix.CreatePerspectiveFieldOfView(
- MathHelper.ToRadians(45), aspectRatio, 0.1f, 10000f);
- return projection;
- }
- public void prepare3d()
- {
- // Reset values to correct rendering
- GraphicsDevice.BlendState = BlendState.Opaque;
- GraphicsDevice.DepthStencilState = DepthStencilState.Default;
- GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
- }
- } // end Class
- } // end Namespace
Advertisement
Add Comment
Please, Sign In to add comment