Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4.  
  5. namespace Game1
  6. {
  7.     /// <summary>
  8.     /// This is the main type for your game.
  9.     /// </summary>
  10.     public class Game1 : Game
  11.     {
  12.         GraphicsDeviceManager graphics;
  13.         SpriteBatch spriteBatch;
  14.  
  15.         public Game1()
  16.         {
  17.             graphics = new GraphicsDeviceManager(this);
  18.             Content.RootDirectory = "Content";
  19.         }
  20.  
  21.         /// <summary>
  22.         /// Allows the game to perform any initialization it needs to before starting to run.
  23.         /// This is where it can query for any required services and load any non-graphic
  24.         /// related content.  Calling base.Initialize will enumerate through any components
  25.         /// and initialize them as well.
  26.         /// </summary>
  27.         Quad quad;
  28.         Quad quad2;
  29.         VertexDeclaration vertexDeclaration;
  30.         Matrix View, Projection;
  31.         protected override void Initialize()
  32.         {
  33.             quad = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 1, 1);
  34.             quad2 = new Quad(new Vector3(0.5f,0,1), Vector3.Backward, Vector3.Up, 1, 1);
  35.             View = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Zero,
  36.                 Vector3.Up);
  37.             Projection = Matrix.CreatePerspectiveFieldOfView(
  38.                 MathHelper.PiOver4, 4.0f / 3.0f, 1, 500);
  39.  
  40.             base.Initialize();
  41.         }
  42.  
  43.         /// <summary>
  44.         /// LoadContent will be called once per game and is the place to load
  45.         /// all of your content.
  46.         /// </summary>
  47.         Texture2D texture;
  48.         BasicEffect quadEffect;
  49.         BasicEffect quadEffect2;
  50.         protected override void LoadContent()
  51.         {
  52.             // Create a new SpriteBatch, which can be used to draw textures.
  53.             spriteBatch = new SpriteBatch(GraphicsDevice);
  54.             texture = Content.Load<Texture2D>("Placeholder");
  55.             quadEffect = new BasicEffect(graphics.GraphicsDevice);
  56.             quadEffect2 = new BasicEffect(graphics.GraphicsDevice);
  57.             //quadEffect.EnableDefaultLighting();
  58.  
  59.             quadEffect.World = Matrix.Identity;
  60.             quadEffect.View = View;
  61.             quadEffect.Projection = Projection;
  62.             quadEffect.TextureEnabled = true;
  63.             quadEffect.Texture = texture;
  64.  
  65.             quadEffect2.World = Matrix.Identity;
  66.             quadEffect2.View = View;
  67.             quadEffect2.Projection = Projection;
  68.             quadEffect2.TextureEnabled = true;
  69.             quadEffect2.Texture = texture;
  70.  
  71.             vertexDeclaration = new VertexDeclaration(new VertexElement[]
  72.                 {
  73.                     new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
  74.                     new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
  75.                     new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
  76.                 });
  77.  
  78.         }
  79.  
  80.         /// <summary>
  81.         /// UnloadContent will be called once per game and is the place to unload
  82.         /// game-specific content.
  83.         /// </summary>
  84.         protected override void UnloadContent()
  85.         {
  86.             // TODO: Unload any non ContentManager content here
  87.         }
  88.  
  89.         /// <summary>
  90.         /// Allows the game to run logic such as updating the world,
  91.         /// checking for collisions, gathering input, and playing audio.
  92.         /// </summary>
  93.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  94.         protected override void Update(GameTime gameTime)
  95.         {
  96.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  97.                 Exit();
  98.  
  99.             // TODO: Add your update logic here
  100.  
  101.             base.Update(gameTime);
  102.         }
  103.  
  104.         /// <summary>
  105.         /// This is called when the game should draw itself.
  106.         /// </summary>
  107.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  108.         protected override void Draw(GameTime gameTime)
  109.         {
  110.             GraphicsDevice.Clear(Color.CornflowerBlue);
  111.             foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes)
  112.             {
  113.                 pass.Apply();
  114.                
  115.                 GraphicsDevice.DrawUserIndexedPrimitives
  116.                     <VertexPositionNormalTexture>(
  117.                     PrimitiveType.TriangleList,
  118.                     quad2.Vertices, 0, 4,
  119.                     quad2.Indexes, 0, 2);
  120.  
  121.                 GraphicsDevice.DrawUserIndexedPrimitives
  122.                     <VertexPositionNormalTexture>(
  123.                     PrimitiveType.TriangleList,
  124.                     quad.Vertices, 0, 4,
  125.                     quad.Indexes, 0, 2);
  126.             }
  127.  
  128.             base.Draw(gameTime);
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement