Advertisement
GeeckoDev

Rob0

Oct 17th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.84 KB | None | 0 0
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Game1.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Audio;
  15. using Microsoft.Xna.Framework.Content;
  16. using Microsoft.Xna.Framework.GamerServices;
  17. using Microsoft.Xna.Framework.Graphics;
  18. using Microsoft.Xna.Framework.Input;
  19. using Microsoft.Xna.Framework.Input.Touch;
  20. using Microsoft.Xna.Framework.Media;
  21. using System.IO;
  22.  
  23. namespace Rob
  24. {
  25.     /// <summary>
  26.     /// This is the main type for your game
  27.     /// </summary>
  28.     public class Game1 : Microsoft.Xna.Framework.Game
  29.     {
  30.         Matrix worldMatrix;
  31.         Matrix viewMatrix;
  32.         Matrix projectionMatrix;
  33.  
  34.         Vector3 up = Vector3.Up;
  35.         Vector3 forward = Vector3.Forward;
  36.         Vector3 right = Vector3.Right;
  37.  
  38.         Texture2D tex;
  39.  
  40.         BasicEffect basicEffect;
  41.  
  42.         List<VertexPositionNormalTexture> vertexList;
  43.         List<int> indexList;
  44.  
  45.         VertexBuffer vertexBuffer;
  46.  
  47.         RasterizerState rasterizerState;
  48.  
  49.         GraphicsDeviceManager graphics;
  50.  
  51.         public Game1()
  52.         {
  53.             graphics = new GraphicsDeviceManager(this);
  54.             graphics.PreferredBackBufferHeight = 800;
  55.             graphics.PreferredBackBufferWidth = 600;
  56.             Content.RootDirectory = "Content";
  57.         }
  58.  
  59.         /// <summary>
  60.         /// Allows the game to perform any initialization it needs to before starting to run.
  61.         /// This is where it can query for any required services and load any non-graphic
  62.         /// related content.  Calling base.Initialize will enumerate through any components
  63.         /// and initialize them as well.
  64.         /// </summary>
  65.         protected override void Initialize()
  66.         {
  67.             InitializeTransform();
  68.             InitializeEffect();
  69.             InitializePoints();
  70.  
  71.             InitializeTriangleList();
  72.  
  73.  
  74.             rasterizerState = new RasterizerState();
  75.             rasterizerState.FillMode = FillMode.Solid;
  76.             rasterizerState.CullMode = CullMode.CullClockwiseFace;
  77.  
  78.             base.Initialize();
  79.         }
  80.  
  81.         /// <summary>
  82.         /// LoadContent will be called once per game and is the place to load
  83.         /// all of your content.
  84.         /// </summary>
  85.         protected override void LoadContent()
  86.         {
  87.             // TODO
  88.         }
  89.  
  90.         /// <summary>
  91.         /// UnloadContent will be called once per game and is the place to unload
  92.         /// all content.
  93.         /// </summary>
  94.         protected override void UnloadContent()
  95.         {
  96.             // TODO: Unload any non ContentManager content here
  97.         }
  98.  
  99.         /// <summary>
  100.         /// Initializes the transforms used by the game.
  101.         /// </summary>
  102.         private void InitializeTransform()
  103.         {
  104.  
  105.             viewMatrix = Matrix.CreateLookAt(
  106.                 new Vector3(0.0f, 0.0f, 4.0f),
  107.                 Vector3.Zero,
  108.                 Vector3.Up
  109.                 );
  110.  
  111.             projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90), 4.0f/3.0f, 1, 1000);
  112.         }
  113.  
  114.         /// <summary>
  115.         /// Initializes the effect (loading, parameter setting, and technique selection)
  116.         /// used by the game.
  117.         /// </summary>
  118.         private void InitializeEffect()
  119.         {
  120.             tex = Content.Load<Texture2D>("DieTexture");
  121.  
  122.             worldMatrix = Matrix.Identity;
  123.  
  124.             basicEffect = new BasicEffect(GraphicsDevice);
  125.             basicEffect.EnableDefaultLighting();
  126.  
  127.             basicEffect.VertexColorEnabled = false;
  128.             basicEffect.TextureEnabled = true;
  129.             basicEffect.Texture = tex;
  130.             basicEffect.World = worldMatrix;
  131.             basicEffect.View = viewMatrix;
  132.             basicEffect.Projection = projectionMatrix;
  133.         }
  134.  
  135.         /// <summary>
  136.         /// Initializes the point list.
  137.         /// </summary>
  138.         private void InitializePoints()
  139.         {
  140.             vertexList = new List<VertexPositionNormalTexture>();
  141.  
  142.             //// C
  143.             // front
  144.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
  145.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
  146.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
  147.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
  148.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
  149.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
  150.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
  151.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
  152.             // back
  153.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
  154.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
  155.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
  156.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
  157.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
  158.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
  159.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
  160.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
  161.             // contour
  162.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 1), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  163.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 0), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  164.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 1), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  165.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 0), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  166.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f))); //
  167.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
  168.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
  169.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
  170.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 1), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f))); //
  171.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 0), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
  172.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 1), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
  173.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 0), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
  174.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f))); //
  175.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  176.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  177.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  178.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 1), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f))); //
  179.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 0), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
  180.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 1), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
  181.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 0), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
  182.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f))); //
  183.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
  184.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
  185.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
  186.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 1), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f))); //
  187.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 0), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
  188.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 1), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
  189.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 0), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
  190.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f))); //
  191.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  192.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  193.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  194.  
  195.  
  196.             //// G
  197.             // front
  198.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
  199.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
  200.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
  201.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
  202.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
  203.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
  204.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
  205.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
  206.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
  207.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
  208.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
  209.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
  210.             // back
  211.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
  212.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
  213.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
  214.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
  215.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
  216.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
  217.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
  218.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
  219.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
  220.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
  221.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
  222.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
  223.             // contour
  224.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 1), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  225.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 0), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  226.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 1), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  227.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 0), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
  228.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f))); //
  229.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
  230.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
  231.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
  232.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 1), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f))); //
  233.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 0), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
  234.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 1), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
  235.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 0), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
  236.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 1), new Vector3(0.5f, -0.3f, 0), new Vector2(0.0f, 0.0f))); //
  237.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 0), new Vector3(0.5f, -0.3f, 0), new Vector2(0.0f, 0.0f)));
  238.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 1), new Vector3(0.5f, -0.3f, 0), new Vector2(1.0f, 0.0f)));
  239.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 0), new Vector3(0.5f, -0.3f, 0), new Vector2(1.0f, 0.0f)));
  240.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 1), new Vector3(0.3f, 0.4f, 0), new Vector2(1.0f, 0.0f))); //
  241.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 0), new Vector3(0.3f, 0.4f, 0), new Vector2(1.0f, 0.0f)));
  242.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 1), new Vector3(0.3f, 0.4f, 0), new Vector2(0.0f, 1.0f)));
  243.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 0), new Vector3(0.3f, 0.4f, 0), new Vector2(0.0f, 1.0f)));
  244.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 1), new Vector3(-0.9f, -0.2f, 0), new Vector2(0.0f, 1.0f))); //
  245.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 0), new Vector3(-0.9f, -0.2f, 0), new Vector2(0.0f, 1.0f)));
  246.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 1), new Vector3(-0.9f, -0.2f, 0), new Vector2(1.0f, 1.0f)));
  247.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 0), new Vector3(-0.9f, -0.2f, 0), new Vector2(1.0f, 1.0f)));
  248.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 1), new Vector3(-1.2f, -0.4f, 0), new Vector2(1.0f, 1.0f))); //
  249.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 0), new Vector3(-1.2f, -0.4f, 0), new Vector2(1.0f, 1.0f)));
  250.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 1), new Vector3(-1.2f, -0.4f, 0), new Vector2(0.0f, 0.0f)));
  251.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 0), new Vector3(-1.2f, -0.4f, 0), new Vector2(0.0f, 0.0f)));
  252.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 1), new Vector3(-0.3f, 0.3f, 0), new Vector2(0.0f, 0.0f))); //
  253.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 0), new Vector3(-0.3f, 0.3f, 0), new Vector2(0.0f, 0.0f)));
  254.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 1), new Vector3(-0.3f, 0.3f, 0), new Vector2(0.0f, 0.0f)));
  255.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 0), new Vector3(-0.3f, 0.3f, 0), new Vector2(0.0f, 0.0f)));
  256.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 1), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f))); //
  257.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 0), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
  258.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 1), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
  259.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 0), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
  260.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f))); //
  261.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
  262.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
  263.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
  264.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 1), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f))); //
  265.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 0), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
  266.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 1), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
  267.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 0), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
  268.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f))); //
  269.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  270.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  271.             vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
  272.  
  273.             // Initialize the vertex buffer, allocating memory for each vertex.
  274.             vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration,
  275.                                             vertexList.Count, BufferUsage.None);
  276.  
  277.             // Set the vertex buffer data to the array of vertices.
  278.             vertexBuffer.SetData<VertexPositionNormalTexture>(vertexList.ToArray());
  279.         }
  280.  
  281.  
  282.  
  283.         /// <summary>
  284.         /// Initializes the triangle list.
  285.         /// </summary>
  286.         private void InitializeTriangleList()
  287.         {
  288.             int shift = 0;
  289.             indexList = new List<int>();
  290.  
  291.             //// C
  292.             // front
  293.             for (int i=0; i<3; i++) {
  294.                 indexList.Add (shift+2*i+0);    indexList.Add (shift+2*i+2);    indexList.Add (shift+2*i+1);
  295.                 indexList.Add (shift+2*i+1);    indexList.Add (shift+2*i+2);    indexList.Add (shift+2*i+3);
  296.             }
  297.             shift += 8;
  298.             // back
  299.             for (int i=0; i<3; i++) {
  300.                 indexList.Add (shift+2*i+0);    indexList.Add (shift+2*i+1);    indexList.Add (shift+2*i+2);
  301.                 indexList.Add (shift+2*i+2);    indexList.Add (shift+2*i+1);    indexList.Add (shift+2*i+3);
  302.             }
  303.             shift += 8;
  304.             // contour
  305.             for (int i=0; i<8; i++) {
  306.                 indexList.Add (shift+4*i+0);    indexList.Add (shift+4*i+1);    indexList.Add (shift+4*i+2);
  307.                 indexList.Add (shift+4*i+2);    indexList.Add (shift+4*i+1);    indexList.Add (shift+4*i+3);
  308.             }
  309.             shift += 8 * 4;
  310.  
  311.             //// G
  312.             // front
  313.             for (int i=0; i<5; i++) {
  314.                 indexList.Add (shift+2*i+0);    indexList.Add (shift+2*i+2);    indexList.Add (shift+2*i+1);
  315.                 indexList.Add (shift+2*i+1);    indexList.Add (shift+2*i+2);    indexList.Add (shift+2*i+3);
  316.             }
  317.             shift += 12;
  318.             // back
  319.             for (int i=0; i<5; i++) {
  320.                 indexList.Add (shift+2*i+0);    indexList.Add (shift+2*i+1);    indexList.Add (shift+2*i+2);
  321.                 indexList.Add (shift+2*i+2);    indexList.Add (shift+2*i+1);    indexList.Add (shift+2*i+3);
  322.             }
  323.             shift += 12;
  324.             // contour
  325.             for (int i=0; i<12; i++) {
  326.                 indexList.Add (shift+4*i+0);    indexList.Add (shift+4*i+1);    indexList.Add (shift+4*i+2);
  327.                 indexList.Add (shift+4*i+2);    indexList.Add (shift+4*i+1);    indexList.Add (shift+4*i+3);
  328.             }
  329.             shift += 12 * 4;
  330.         }
  331.  
  332.  
  333.  
  334.         /// <summary>
  335.         /// Allows the game to run logic such as updating the world,
  336.         /// checking for collisions, gathering input, and playing audio.
  337.         /// </summary>
  338.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  339.         protected override void Update(GameTime gameTime)
  340.         {
  341.             Matrix m = Matrix.CreateFromAxisAngle(Vector3.Normalize(new Vector3(3,4,5)), 0.02f);
  342.  
  343.             up = Vector3.Transform(up, m);
  344.             right = Vector3.Transform(right, m);
  345.             forward = Vector3.Transform(forward, m);
  346.  
  347.             // Allows the game to exit
  348.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  349.                 this.Exit();
  350.             #if WINDOWS
  351.             if (Keyboard.GetState().IsKeyDown(Keys.Escape))
  352.                 this.Exit();
  353.             #endif
  354.  
  355.             base.Update(gameTime);
  356.         }
  357.  
  358.  
  359.         /// <summary>
  360.         /// Determines which primitive to draw based on input from the keyboard
  361.         /// or game pad.
  362.         /// </summary>
  363.  
  364.  
  365.         /// <summary>
  366.         /// This is called when the game should draw itself.
  367.         /// </summary>
  368.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  369.         protected override void Draw(GameTime gameTime)
  370.         {
  371.             GraphicsDevice.Clear(Color.SteelBlue);
  372.  
  373.             // The effect is a compiled effect created and compiled elsewhere
  374.             // in the application.
  375.             basicEffect.World = Matrix.CreateWorld(Vector3.Zero, forward, up);
  376.  
  377.             foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
  378.             {
  379.                 pass.Apply();
  380.  
  381.                 GraphicsDevice.RasterizerState = rasterizerState;
  382.                 DrawTriangleList();
  383.             }
  384.  
  385.             base.Draw(gameTime);
  386.         }
  387.  
  388.         /// <summary>
  389.         /// Draws the triangle list.
  390.         /// </summary>
  391.         private void DrawTriangleList()
  392.         {
  393.             GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
  394.                 PrimitiveType.TriangleList,
  395.                 vertexList.ToArray(),
  396.                 0,   // vertex buffer offset to add to each element of the index buffer
  397.                 vertexList.Count(),   // number of vertices to draw
  398.                 indexList.ToArray(),
  399.                 0,   // first index element to read
  400.                 indexList.Count()/3    // number of primitives to draw
  401.                 );
  402.         }
  403.  
  404.  
  405.     }
  406. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement