Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region File Description
- //-----------------------------------------------------------------------------
- // Game1.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Input.Touch;
- using Microsoft.Xna.Framework.Media;
- using System.IO;
- namespace Rob
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- Matrix worldMatrix;
- Matrix viewMatrix;
- Matrix projectionMatrix;
- Vector3 up = Vector3.Up;
- Vector3 forward = Vector3.Forward;
- Vector3 right = Vector3.Right;
- Texture2D tex;
- BasicEffect basicEffect;
- List<VertexPositionNormalTexture> vertexList;
- List<int> indexList;
- VertexBuffer vertexBuffer;
- RasterizerState rasterizerState;
- GraphicsDeviceManager graphics;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- graphics.PreferredBackBufferHeight = 800;
- graphics.PreferredBackBufferWidth = 600;
- Content.RootDirectory = "Content";
- }
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- InitializeTransform();
- InitializeEffect();
- InitializePoints();
- InitializeTriangleList();
- rasterizerState = new RasterizerState();
- rasterizerState.FillMode = FillMode.Solid;
- rasterizerState.CullMode = CullMode.CullClockwiseFace;
- base.Initialize();
- }
- /// <summary>
- /// LoadContent will be called once per game and is the place to load
- /// all of your content.
- /// </summary>
- protected override void LoadContent()
- {
- // TODO
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// all content.
- /// </summary>
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- /// <summary>
- /// Initializes the transforms used by the game.
- /// </summary>
- private void InitializeTransform()
- {
- viewMatrix = Matrix.CreateLookAt(
- new Vector3(0.0f, 0.0f, 4.0f),
- Vector3.Zero,
- Vector3.Up
- );
- projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90), 4.0f/3.0f, 1, 1000);
- }
- /// <summary>
- /// Initializes the effect (loading, parameter setting, and technique selection)
- /// used by the game.
- /// </summary>
- private void InitializeEffect()
- {
- tex = Content.Load<Texture2D>("DieTexture");
- worldMatrix = Matrix.Identity;
- basicEffect = new BasicEffect(GraphicsDevice);
- basicEffect.EnableDefaultLighting();
- basicEffect.VertexColorEnabled = false;
- basicEffect.TextureEnabled = true;
- basicEffect.Texture = tex;
- basicEffect.World = worldMatrix;
- basicEffect.View = viewMatrix;
- basicEffect.Projection = projectionMatrix;
- }
- /// <summary>
- /// Initializes the point list.
- /// </summary>
- private void InitializePoints()
- {
- vertexList = new List<VertexPositionNormalTexture>();
- //// C
- // front
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
- // back
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
- // contour
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 1), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 0), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 1), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 0), new Vector3(-0.9f, 1.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, 0.3f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 1), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-1.2f, -1.0f, 0), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 1), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 0), new Vector3(-0.2f, -1.7f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.5f, -1.2f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 1), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.3f, -1.0f, 0), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 1), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 0), new Vector3(0.2f, 1.1f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, -0.8f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 1), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(-0.8f, 0.3f, 0), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 1), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 0), new Vector3(0.7f, -1.0f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.2f, 1.0f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 1), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(0.0f, 1.2f, 0), new Vector3(0.2f, 0.2f, 0), new Vector2(0.0f, 0.0f)));
- //// G
- // front
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 1), new Vector3(0, 0, 1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 1), new Vector3(0, 0, 1), new Vector2(1.0f, 1.0f)));
- // back
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.0f, 1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, 1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.5f, -1.2f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.3f, -1.0f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.8f, -0.7f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.6f, -0.7f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.4f, -0.4f, 0), new Vector3(0, 0, -1), new Vector2(0.0f, 1.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f+0.2f, -0.5f, 0), new Vector3(0, 0, -1), new Vector2(1.0f, 1.0f)));
- // contour
- 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)));
- 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)));
- 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)));
- 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)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, 0.3f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 1), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-1.2f, -1.0f, 0), new Vector3(-1, 0, 0), new Vector2(0.0f, 0.0f)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f))); //
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, -0.8f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 1), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
- vertexList.Add(new VertexPositionNormalTexture(new Vector3(2.0f-0.8f, 0.3f, 0), new Vector3(1, 0, 0), new Vector2(0.0f, 0.0f)));
- 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))); //
- 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)));
- 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)));
- 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)));
- 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))); //
- 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)));
- 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)));
- 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)));
- // Initialize the vertex buffer, allocating memory for each vertex.
- vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration,
- vertexList.Count, BufferUsage.None);
- // Set the vertex buffer data to the array of vertices.
- vertexBuffer.SetData<VertexPositionNormalTexture>(vertexList.ToArray());
- }
- /// <summary>
- /// Initializes the triangle list.
- /// </summary>
- private void InitializeTriangleList()
- {
- int shift = 0;
- indexList = new List<int>();
- //// C
- // front
- for (int i=0; i<3; i++) {
- indexList.Add (shift+2*i+0); indexList.Add (shift+2*i+2); indexList.Add (shift+2*i+1);
- indexList.Add (shift+2*i+1); indexList.Add (shift+2*i+2); indexList.Add (shift+2*i+3);
- }
- shift += 8;
- // back
- for (int i=0; i<3; i++) {
- indexList.Add (shift+2*i+0); indexList.Add (shift+2*i+1); indexList.Add (shift+2*i+2);
- indexList.Add (shift+2*i+2); indexList.Add (shift+2*i+1); indexList.Add (shift+2*i+3);
- }
- shift += 8;
- // contour
- for (int i=0; i<8; i++) {
- indexList.Add (shift+4*i+0); indexList.Add (shift+4*i+1); indexList.Add (shift+4*i+2);
- indexList.Add (shift+4*i+2); indexList.Add (shift+4*i+1); indexList.Add (shift+4*i+3);
- }
- shift += 8 * 4;
- //// G
- // front
- for (int i=0; i<5; i++) {
- indexList.Add (shift+2*i+0); indexList.Add (shift+2*i+2); indexList.Add (shift+2*i+1);
- indexList.Add (shift+2*i+1); indexList.Add (shift+2*i+2); indexList.Add (shift+2*i+3);
- }
- shift += 12;
- // back
- for (int i=0; i<5; i++) {
- indexList.Add (shift+2*i+0); indexList.Add (shift+2*i+1); indexList.Add (shift+2*i+2);
- indexList.Add (shift+2*i+2); indexList.Add (shift+2*i+1); indexList.Add (shift+2*i+3);
- }
- shift += 12;
- // contour
- for (int i=0; i<12; i++) {
- indexList.Add (shift+4*i+0); indexList.Add (shift+4*i+1); indexList.Add (shift+4*i+2);
- indexList.Add (shift+4*i+2); indexList.Add (shift+4*i+1); indexList.Add (shift+4*i+3);
- }
- shift += 12 * 4;
- }
- /// <summary>
- /// Allows the game to run logic such as updating the world,
- /// checking for collisions, gathering input, and playing audio.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Update(GameTime gameTime)
- {
- Matrix m = Matrix.CreateFromAxisAngle(Vector3.Normalize(new Vector3(3,4,5)), 0.02f);
- up = Vector3.Transform(up, m);
- right = Vector3.Transform(right, m);
- forward = Vector3.Transform(forward, m);
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- #if WINDOWS
- if (Keyboard.GetState().IsKeyDown(Keys.Escape))
- this.Exit();
- #endif
- base.Update(gameTime);
- }
- /// <summary>
- /// Determines which primitive to draw based on input from the keyboard
- /// or game pad.
- /// </summary>
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.SteelBlue);
- // The effect is a compiled effect created and compiled elsewhere
- // in the application.
- basicEffect.World = Matrix.CreateWorld(Vector3.Zero, forward, up);
- foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
- {
- pass.Apply();
- GraphicsDevice.RasterizerState = rasterizerState;
- DrawTriangleList();
- }
- base.Draw(gameTime);
- }
- /// <summary>
- /// Draws the triangle list.
- /// </summary>
- private void DrawTriangleList()
- {
- GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
- PrimitiveType.TriangleList,
- vertexList.ToArray(),
- 0, // vertex buffer offset to add to each element of the index buffer
- vertexList.Count(), // number of vertices to draw
- indexList.ToArray(),
- 0, // first index element to read
- indexList.Count()/3 // number of primitives to draw
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement