#region Using Statements using System; using System.Collections; 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 System.IO; #endregion namespace XNA_Tryout { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; ContentManager content; GraphicsDevice device; VertexBuffer vb; Effect effect; VertexPositionNormalTexture[] vertex = new VertexPositionNormalTexture[4]; ArrayList vertexlist = new ArrayList(); Vector3 CameraPosition; Vector3 CameraTarget; Matrix ViewMatrix; Matrix ProjectionMatrix; Texture2D Texture1; int gamespeed = 1; public Game1() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void Initialize() { SetUpXNADevice(); VertexSetup(); base.Initialize(); } private void SetUpXNADevice() { device = graphics.GraphicsDevice; graphics.PreferredBackBufferWidth = 600; graphics.PreferredBackBufferHeight = 600; graphics.IsFullScreen = false; graphics.SynchronizeWithVerticalRetrace = false; graphics.ApplyChanges(); Window.Title = "XNA TryOut"; } public void VertexSetup() { vertex[0] = new VertexPositionNormalTexture(new Vector3(0,8,0),new Vector3(0,0,1), new Vector2(0,1)); vertex[1] = new VertexPositionNormalTexture(new Vector3(8,0,0), new Vector3(0, 0, 1), new Vector2(1, 0)); vertex[2] = new VertexPositionNormalTexture(new Vector3(-8, 0, 0), new Vector3(0, 0, 1), new Vector2(-1, 0)); vertex[3] = new VertexPositionNormalTexture(new Vector3(5,-8,0), new Vector3(0,0,1), new Vector2(0,-1)); vb = new VertexBuffer(device, VertexPositionNormalTexture.SizeInBytes * 4, ResourceUsage.WriteOnly); vb.SetData(vertex); } private void Effects() { CameraPosition = new Vector3(0, 0, 30); CameraTarget = new Vector3(0, 4, 0); effect = content.Load("Effects"); ViewMatrix = Matrix.CreateLookAt(CameraPosition, CameraTarget, new Vector3(0, 0, 1)); ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, this.Window.ClientBounds.Width / this.Window.ClientBounds.Height, 1.0f, 200.0f); } public void ProcessKeyboard(float speed) { KeyboardState keys = Keyboard.GetState(); if (keys.IsKeyDown(Keys.Escape)) { Exit(); } if (keys.IsKeyDown(Keys.F)) { graphics.ToggleFullScreen(); } } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { Effects(); Texture1 = content.Load("streettexture"); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent == true) { content.Unload(); } } protected override void Update(GameTime gameTime) { ProcessKeyboard(gameTime.ElapsedGameTime.Milliseconds / 500.0f * gamespeed); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0); //CULL MODE STAAT UIT! device.RenderState.CullMode = CullMode.None; effect.CurrentTechnique = effect.Techniques["Textured"]; effect.Parameters["xViewProjection"].SetValue(ViewMatrix * ProjectionMatrix); effect.Parameters["xColoredTexture"].SetValue(Texture1); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements); device.Vertices[0].SetSource(vb, 0, VertexPositionNormalTexture.SizeInBytes); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 4); //device.DrawPrimitives(PrimitiveType.TriangleList,0,3); pass.End(); } effect.End(); base.Draw(gameTime); } } }