Advertisement
Alan468

Kostki 3d XNA

Nov 6th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 21.79 KB | None | 0 0
  1. /*_________GAME1______________________________________________________________________________________________________________*/
  2. #region GAME1
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Microsoft.Xna.Framework;
  7. using Microsoft.Xna.Framework.Audio;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.GamerServices;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Microsoft.Xna.Framework.Input;
  12. using Microsoft.Xna.Framework.Media;
  13. using GrafikaRuchoma_04a_Kamera_3d.CameraComponent;
  14. using GrafikaRuchoma_04a_Kamera_3d.CustomClasses;
  15.  
  16. namespace GrafikaRuchoma_04a_Kamera_3d
  17. {
  18.     public class Game1 : Game
  19.     {
  20.         GraphicsDeviceManager graphics;
  21.         SpriteBatch spriteBatch;
  22.         KeyboardState prevState;
  23.  
  24.         public BasicEffect basicEffect;
  25.         public Camera camera;
  26.         Floor floor;
  27.         Cube cube, cubeMoon, mars;
  28.  
  29.         public Game1()
  30.         {
  31.             graphics = new GraphicsDeviceManager(this);
  32.             Content.RootDirectory = "Content";
  33.  
  34.             Window.AllowUserResizing = false;
  35.             graphics.PreferredBackBufferHeight = 720;
  36.             graphics.PreferredBackBufferWidth = 1280;
  37.             graphics.IsFullScreen = false;
  38.             IsMouseVisible = true;
  39.         }
  40.  
  41.         protected override void Initialize()
  42.         {
  43.             basicEffect = new BasicEffect(GraphicsDevice)
  44.             {
  45.                 Alpha = 1,
  46.                 VertexColorEnabled = true,
  47.                 LightingEnabled = false,
  48.             };
  49.  
  50.             camera = new Camera(this, new Vector3(0, 10, 0), Vector3.Zero, 5);
  51.             Components.Add(camera);
  52.  
  53.             floor = new Floor(GraphicsDevice, 50, 50);
  54.  
  55.             cube = new Cube(this, new Vector3(0, 20, 0), new Vector3(0, 0, 0), new Vector3(4), 4, GraphicsDevice);
  56.             Components.Add(cube);
  57.  
  58.             cubeMoon = new Cube(this, new Vector3(0, 10, 0), new Vector3(0, 0, 0), new Vector3(2), 6, GraphicsDevice);
  59.             Components.Add(cubeMoon);
  60.  
  61.             mars = new Cube(this, new Vector3(0, 50, 0), new Vector3(0, 0, 0), new Vector3(2), 3, GraphicsDevice, Color.Red, Color.DarkRed);
  62.             Components.Add(mars);
  63.  
  64.             base.Initialize();
  65.         }
  66.  
  67.         protected override void LoadContent()
  68.         {
  69.             spriteBatch = new SpriteBatch(GraphicsDevice);
  70.         }
  71.  
  72.         protected override void UnloadContent() { }
  73.  
  74.         protected override void Update(GameTime gameTime)
  75.         {
  76.             var keyboardState = Keyboard.GetState();
  77.             var mouseState = Mouse.GetState();
  78.             var mousePostion = new Point(mouseState.X, mouseState.Y);
  79.  
  80.             if (keyboardState.IsKeyDown(Keys.Escape))
  81.             {
  82.                 Exit();
  83.             }
  84.  
  85.             if (keyboardState.IsKeyDown(Keys.LeftShift))
  86.             {
  87.                 camera.cameraSpeed = 25;
  88.             }
  89.             else if (prevState.IsKeyDown(Keys.LeftShift) && keyboardState.IsKeyUp(Keys.LeftShift))
  90.             {
  91.                 camera.cameraSpeed = 5;
  92.             }
  93.  
  94.             cubeMoon.rotationCenter = cube.GetActualPosition();
  95.  
  96.             base.Update(gameTime);
  97.             prevState = keyboardState;
  98.         }
  99.  
  100.         protected override void Draw(GameTime gameTime)
  101.         {
  102.             GraphicsDevice.Clear(Color.CornflowerBlue);
  103.  
  104.             RasterizerState rasterizerState = new RasterizerState()
  105.             {
  106.                 CullMode = CullMode.None
  107.             };
  108.             GraphicsDevice.RasterizerState = rasterizerState;
  109.  
  110.             var depthStencilState = new DepthStencilState
  111.             {
  112.                 DepthBufferEnable = true
  113.             };
  114.             GraphicsDevice.DepthStencilState = depthStencilState;
  115.  
  116.             floor.Draw(camera, basicEffect);
  117.  
  118.             cube.Draw();
  119.             cubeMoon.Draw();
  120.             mars.Draw();
  121.  
  122.             base.Draw(gameTime);
  123.         }
  124.     }
  125. }
  126. #endregion
  127. /*_________CAMERA______________________________________________________________________________________________________________*/
  128. #region CAMERA
  129. using System;
  130. using System.Collections.Generic;
  131. using System.Linq;
  132. using Microsoft.Xna.Framework;
  133. using Microsoft.Xna.Framework.Audio;
  134. using Microsoft.Xna.Framework.Content;
  135. using Microsoft.Xna.Framework.GamerServices;
  136. using Microsoft.Xna.Framework.Graphics;
  137. using Microsoft.Xna.Framework.Input;
  138. using Microsoft.Xna.Framework.Media;
  139. using GrafikaRuchoma_04a_Kamera_3d.CustomClasses;
  140.  
  141. namespace GrafikaRuchoma_04a_Kamera_3d.CameraComponent
  142. {
  143.     public class Camera : GameComponent
  144.     {
  145.         private KeyboardState prevState;
  146.  
  147.         private Vector3 cameraPosition;
  148.         public Vector3 cameraRotation;
  149.  
  150.         public float cameraSpeed { get; set; }
  151.         public Vector3 cameraLookAt;
  152.  
  153.         private Vector3 mouseRotationBuffer;
  154.         private MouseState currentMouseState;
  155.         private MouseState prevMouseState;
  156.  
  157.         public BoundingBox ColliderBox{ get { return new BoundingBox(cameraPosition - new Vector3(0.3f), cameraPosition + new Vector3(0.3f)); } }
  158.  
  159.         public bool ShowCenterLine { get; set; }
  160.  
  161.         public Vector3 Position
  162.         {
  163.             get { return cameraPosition; }
  164.             set
  165.             {
  166.                 cameraPosition = value;
  167.                 UpdateLookAt();
  168.             }
  169.         }
  170.  
  171.         public Vector3 Rotation
  172.         {
  173.             get { return cameraRotation; }
  174.             set
  175.             {
  176.                 cameraRotation = value;
  177.                 UpdateLookAt();
  178.             }
  179.         }
  180.  
  181.         public Matrix Projection { get; protected set; }
  182.  
  183.         public Matrix View {get{return Matrix.CreateLookAt(cameraPosition, cameraLookAt, Vector3.Up); }}
  184.  
  185.         public Camera(Game game, Vector3 position, Vector3 rotation, float speed) : base(game)
  186.         {
  187.             cameraSpeed = speed;
  188.             Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Game.GraphicsDevice.Viewport.AspectRatio, 0.05f, 1000);
  189.             MoveTo(position, rotation);
  190.  
  191.             prevMouseState = Mouse.GetState();
  192.         }
  193.  
  194.         private void MoveTo(Vector3 pos, Vector3 rot)
  195.         {
  196.             Position = pos;
  197.             Rotation = rot;
  198.         }
  199.  
  200.         private void UpdateLookAt()
  201.         {
  202.             var rotationMartix = Matrix.CreateRotationX(cameraRotation.X) * Matrix.CreateRotationY(cameraRotation.Y);
  203.  
  204.             var lookAtOffset = Vector3.Transform(Vector3.UnitZ, rotationMartix);
  205.             cameraLookAt = cameraPosition + lookAtOffset;
  206.         }
  207.  
  208.         private Vector3 PreviewMove(Vector3 amount)
  209.         {
  210.             var rotate = Matrix.CreateRotationY(cameraRotation.Y);
  211.  
  212.             var movment = new Vector3(amount.X, amount.Y, amount.Z);
  213.             movment = Vector3.Transform(movment, rotate);
  214.  
  215.             return cameraPosition + movment;
  216.         }
  217.  
  218.         public Vector3 cameraAxiesPosition
  219.         {
  220.             get
  221.             {
  222.                 var rotate = Matrix.CreateRotationX(cameraRotation.X) * Matrix.CreateRotationY(cameraRotation.Y) * Matrix.CreateRotationZ(cameraRotation.Z);
  223.                 var movment = new Vector3(-0.3f, -0.15f, 0.5f);
  224.                 movment = Vector3.Transform(movment, rotate);
  225.  
  226.                 return cameraPosition + movment;
  227.             }
  228.         }
  229.        
  230.         private void Move(Vector3 scale)
  231.         {
  232.             MoveTo(PreviewMove(scale), Rotation);
  233.         }
  234.  
  235.         public override void Update(GameTime gameTime)
  236.         {
  237.             if (Game.IsActive)
  238.             {
  239.                 currentMouseState = Mouse.GetState();
  240.                 var keyboardState = Keyboard.GetState();
  241.                 var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
  242.  
  243.                 var moveVector = Vector3.Zero;
  244.  
  245.                 if (keyboardState.IsKeyDown(Keys.W))
  246.                     moveVector.Z = 1;
  247.                 if (keyboardState.IsKeyDown(Keys.S))
  248.                     moveVector.Z = -1;
  249.  
  250.                 if (keyboardState.IsKeyDown(Keys.A))
  251.                     moveVector.X = 1;
  252.                 if (keyboardState.IsKeyDown(Keys.D))
  253.                     moveVector.X = -1;
  254.                                
  255.                     if (keyboardState.IsKeyDown(Keys.Space))
  256.                         moveVector.Y = 1;
  257.                     if (keyboardState.IsKeyDown(Keys.C))
  258.                         moveVector.Y = -1;
  259.                
  260.  
  261.                 if (keyboardState.IsKeyDown(Keys.P) && prevState.IsKeyUp(Keys.P))
  262.                     ShowCenterLine = !ShowCenterLine;
  263.  
  264.                 if (moveVector != Vector3.Zero)
  265.                 {
  266.                     moveVector.Normalize();
  267.                     moveVector *= dt * cameraSpeed;
  268.  
  269.                     Move(moveVector);
  270.                 }
  271.  
  272.                 #region Camera Mouse
  273.                 if (currentMouseState != prevMouseState)
  274.                 {
  275.                     var deltaX = currentMouseState.X - (Game.GraphicsDevice.Viewport.Width / 2);
  276.                     var deltaY = currentMouseState.Y - (Game.GraphicsDevice.Viewport.Height / 2);
  277.  
  278.                     mouseRotationBuffer.X -= 0.05F * deltaX * dt;
  279.                     mouseRotationBuffer.Y -= 0.05F * deltaY * dt;
  280.  
  281.                     if (mouseRotationBuffer.Y < MathHelper.ToRadians(-75))
  282.                         mouseRotationBuffer.Y -= mouseRotationBuffer.Y - MathHelper.ToRadians(-75);
  283.  
  284.                     if (mouseRotationBuffer.Y > MathHelper.ToRadians(75))
  285.                         mouseRotationBuffer.Y -= mouseRotationBuffer.Y - MathHelper.ToRadians(75);
  286.  
  287.                     Rotation = new Vector3(
  288.                         -MathHelper.Clamp(mouseRotationBuffer.Y, MathHelper.ToRadians(-75f), MathHelper.ToRadians(75f)),
  289.                         MathHelper.WrapAngle(mouseRotationBuffer.X),
  290.                         0);
  291.                 }
  292.  
  293.                 Mouse.SetPosition(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height / 2);
  294.  
  295.                 prevMouseState = currentMouseState;
  296.                 #endregion
  297.  
  298.                 prevState = keyboardState;
  299.  
  300.                 base.Update(gameTime);
  301.  
  302.             }
  303.         }
  304.     }
  305. }
  306.  
  307. #endregion
  308. /*_________LINE______________________________________________________________________________________________________________*/
  309. #region LINE
  310. using System;
  311. using System.Collections.Generic;
  312. using System.Linq;
  313. using System.Text;
  314. using Microsoft.Xna.Framework;
  315. using Microsoft.Xna.Framework.Graphics;
  316.  
  317. namespace GrafikaRuchoma_04a_Kamera_3d.CustomClasses
  318. {
  319.     public class Line : IDisposable
  320.     {
  321.         public Vector3 startPoint;
  322.         public Vector3 endPoint;
  323.         private VertexPositionColor[] vertices;
  324.  
  325.         public Line(Vector3 startPoint, Vector3 endPoint)
  326.         {
  327.             this.startPoint = startPoint;
  328.             this.endPoint = endPoint;
  329.         }
  330.  
  331.         public Line() { }
  332.  
  333.         public void DrawLine(BasicEffect basicEffect, GraphicsDevice graphicsDevice)
  334.         {
  335.             basicEffect.CurrentTechnique.Passes[0].Apply();
  336.             vertices = new[] { new VertexPositionColor(startPoint, Color.White), new VertexPositionColor(endPoint, Color.White) };
  337.             graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 1);
  338.         }
  339.  
  340.         public void DrawLine(BasicEffect basicEffect, GraphicsDevice graphicsDevice, Vector3 start, Vector3 end)
  341.         {
  342.             basicEffect.CurrentTechnique.Passes[0].Apply();
  343.             vertices = new[] { new VertexPositionColor(start, Color.White), new VertexPositionColor(end, Color.White) };
  344.             graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 1);
  345.         }
  346.  
  347.         public void DrawLine(BasicEffect basicEffect, GraphicsDevice graphicsDevice, Vector3 start, Vector3 end, Color color)
  348.         {
  349.             basicEffect.CurrentTechnique.Passes[0].Apply();
  350.             vertices = new[] { new VertexPositionColor(start, color), new VertexPositionColor(end, color) };
  351.             graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 1);
  352.         }
  353.  
  354.         public void Dispose()
  355.         {
  356.             throw new NotImplementedException();
  357.         }
  358.     }
  359. }
  360.  
  361. #endregion
  362. /*_________FLOOR______________________________________________________________________________________________________________*/
  363. #region Floor
  364. using System;
  365. using System.Collections.Generic;
  366. using System.Linq;
  367. using System.Text;
  368. using GrafikaRuchoma_04a_Kamera_3d.CameraComponent;
  369. using Microsoft.Xna.Framework.Graphics;
  370. using Microsoft.Xna.Framework;
  371.  
  372. namespace GrafikaRuchoma_04a_Kamera_3d.CustomClasses
  373. {
  374.     public class Floor
  375.     {
  376.         private int floorWidth;
  377.         private int floorHeight;
  378.         private VertexBuffer floorBuffer;
  379.         private GraphicsDevice device;
  380.         Color[] floorColors = new Color[2] { Color.Black, Color.White };
  381.  
  382.         public Floor(GraphicsDevice device, int width, int height)
  383.         {
  384.             this.device = device;
  385.             floorWidth = width;
  386.             floorHeight = height;
  387.             BuildFloorBuffer();
  388.         }
  389.  
  390.         private void BuildFloorBuffer()
  391.         {
  392.             List<VertexPositionColor> vertexList = new List<VertexPositionColor>();
  393.             int counter = 0;
  394.  
  395.             for (int x = 0; x < floorWidth; x++)
  396.             {
  397.                 counter++;
  398.                 for (int z = 0; z < floorHeight; z++)
  399.                 {
  400.                     counter++;
  401.  
  402.                     foreach (var vertex in FloorTile(x, z, floorColors[counter % 2]))
  403.                     {
  404.                         vertexList.Add(vertex);
  405.                     }
  406.                 }
  407.             }
  408.  
  409.             floorBuffer = new VertexBuffer(device, VertexPositionColor.VertexDeclaration, vertexList.Count, BufferUsage.None);
  410.             floorBuffer.SetData(vertexList.ToArray());
  411.         }
  412.  
  413.         private List<VertexPositionColor> FloorTile(int xOffset, int zOffset, Color tileColor)
  414.         {
  415.             var vList = new List<VertexPositionColor>()
  416.             {
  417.                 new VertexPositionColor(new Vector3(0 + xOffset, 0, 0 + zOffset), tileColor),
  418.                 new VertexPositionColor(new Vector3(1 + xOffset, 0, 0 + zOffset), tileColor),
  419.                 new VertexPositionColor(new Vector3(0 + xOffset, 0, 1 + zOffset), tileColor),
  420.                 new VertexPositionColor(new Vector3(1 + xOffset, 0, 0 + zOffset), tileColor),
  421.                 new VertexPositionColor(new Vector3(1 + xOffset, 0, 1 + zOffset), tileColor),
  422.                 new VertexPositionColor(new Vector3(0 + xOffset, 0, 1 + zOffset), tileColor),
  423.             };
  424.  
  425.             return vList;
  426.         }
  427.  
  428.         public void Draw(Camera camera, BasicEffect effect)
  429.         {
  430.             effect.VertexColorEnabled = true;
  431.             effect.View = camera.View;
  432.             effect.Projection = camera.Projection;
  433.             effect.World = Matrix.Identity;
  434.  
  435.             foreach (var pass in effect.CurrentTechnique.Passes)
  436.             {
  437.                 pass.Apply();
  438.                 device.SetVertexBuffer(floorBuffer);
  439.                 device.DrawPrimitives(PrimitiveType.TriangleList, 0, floorBuffer.VertexCount / 3);
  440.             }
  441.         }
  442.     }
  443. }
  444.  
  445. #endregion
  446. /*_________CUBE______________________________________________________________________________________________________________*/
  447. #region CUBE
  448. using System;
  449. using System.Collections.Generic;
  450. using System.Linq;
  451. using System.Text;
  452. using Microsoft.Xna.Framework;
  453. using Microsoft.Xna.Framework.Graphics;
  454. using GrafikaRuchoma_04a_Kamera_3d.CameraComponent;
  455.  
  456. namespace GrafikaRuchoma_04a_Kamera_3d.CustomClasses
  457. {
  458.     public class Cube : GameComponent
  459.     {
  460.         public Vector3 middleLocation;
  461.         VertexPositionColor[] planetVertices;
  462.         GraphicsDevice graphicsDevice;
  463.         float speed;
  464.  
  465.         Vector3 size;
  466.         Vector3 angle;
  467.         Game1 game;
  468.         public Vector3 rotationCenter;
  469.         Camera camera;
  470.  
  471.         private Matrix World;
  472.  
  473.         Vector3 vectorZero = Vector3.Zero;
  474.  
  475.         public List<Color> Colors;
  476.  
  477.         public Cube(Game game, Vector3 middleLocation, Vector3 rotationCenter, Vector3 size, float speed, GraphicsDevice graphicsDevice, params Color[] colors)
  478.             : base(game)
  479.         {
  480.  
  481.             Colors = colors.ToList();
  482.  
  483.             if (!Colors.Any())
  484.             {
  485.                 Colors = new List<Color>() { Color.White, Color.Black, Color.White, Color.Black };
  486.             }
  487.  
  488.             this.game = game as Game1;
  489.             this.camera = this.game.camera;
  490.  
  491.             this.middleLocation = middleLocation;
  492.  
  493.             angle = Vector3.Zero;
  494.             this.size = size;
  495.             this.speed = speed;
  496.             this.rotationCenter = rotationCenter;
  497.             this.graphicsDevice = graphicsDevice;
  498.  
  499.             this.basicEffect = new BasicEffect(graphicsDevice)
  500.             {
  501.                 Alpha = 1,
  502.                 VertexColorEnabled = true,
  503.                 LightingEnabled = false,
  504.             };
  505.  
  506.             planetVertices = CubeVerticles();
  507.  
  508.         }
  509.  
  510.         public VertexPositionColor[] GetPlanetVertices()
  511.         {
  512.             return this.planetVertices;
  513.         }
  514.  
  515.         public Vector3 GetActualPosition()
  516.         {
  517.             return Vector3.Transform(middleLocation, World);
  518.         }
  519.  
  520.         public override void Update(GameTime gameTime)
  521.         {
  522.             angle.X += speed;
  523.  
  524.             World = Matrix.Identity;
  525.             World *= Matrix.CreateRotationX(MathHelper.ToRadians(angle.X));
  526.             World *= Matrix.CreateRotationY(MathHelper.ToRadians(angle.Y));
  527.             World *= Matrix.CreateRotationZ(MathHelper.ToRadians(angle.Z));
  528.             World *= Matrix.CreateTranslation(rotationCenter);
  529.  
  530.             basicEffect.World = World;
  531.             basicEffect.View = camera.View;
  532.             basicEffect.Projection = camera.Projection;
  533.         }
  534.  
  535.         private VertexPositionColor[] CubeVerticles()
  536.         {
  537.             Vector3 topLeftFront = new Vector3(-size.X + middleLocation.X, size.Y + middleLocation.Y, size.Z + middleLocation.Z);
  538.             Vector3 bottomLeftFront = new Vector3(-size.X + middleLocation.X, -size.Y + middleLocation.Y, size.Z + middleLocation.Z);
  539.             Vector3 topRightFront = new Vector3(size.X + middleLocation.X, size.Y + middleLocation.Y, size.Z + middleLocation.Z);
  540.             Vector3 bottomRightFront = new Vector3(size.X + middleLocation.X, -size.Y + middleLocation.Y, size.Z + middleLocation.Z);
  541.             Vector3 topLeftBack = new Vector3(-size.X + middleLocation.X, size.Y + middleLocation.Y, -size.Z + middleLocation.Z);
  542.             Vector3 topRightBack = new Vector3(size.X + middleLocation.X, size.Y + middleLocation.Y, -size.Z + middleLocation.Z);
  543.             Vector3 bottomLeftBack = new Vector3(-size.X + middleLocation.X, -size.Y + middleLocation.Y, -size.Z + middleLocation.Z);
  544.             Vector3 bottomRightBack = new Vector3(size.X + middleLocation.X, -size.Y + middleLocation.Y, -size.Z + middleLocation.Z);
  545.  
  546.             Random rnd = new Random();
  547.  
  548.             VertexPositionColor[] verticles = new VertexPositionColor[8]{
  549.                 new VertexPositionColor(topLeftFront, Colors[rnd.Next(0,Colors.Count())]),//1
  550.                 new VertexPositionColor(bottomLeftFront, Colors[rnd.Next(0,Colors.Count())]),//1
  551.                 new VertexPositionColor(topRightFront, Colors[rnd.Next(0,Colors.Count())]),//2
  552.                 new VertexPositionColor(bottomRightFront, Colors[rnd.Next(0,Colors.Count())]),//3
  553.                 new VertexPositionColor(topLeftBack, Colors[rnd.Next(0,Colors.Count())]),//4
  554.                 new VertexPositionColor(topRightBack, Colors[rnd.Next(0,Colors.Count())]),//5
  555.                 new VertexPositionColor(bottomLeftBack, Colors[rnd.Next(0,Colors.Count())]),//6
  556.                 new VertexPositionColor(bottomRightBack, Colors[rnd.Next(0,Colors.Count())])//7
  557.             };
  558.             List<VertexPositionColor> cubeVertices = new List<VertexPositionColor>();
  559.             //Front
  560.             cubeVertices.Add(verticles[2]); cubeVertices.Add(verticles[3]); cubeVertices.Add(verticles[0]);
  561.             cubeVertices.Add(verticles[3]); cubeVertices.Add(verticles[1]); cubeVertices.Add(verticles[0]);
  562.             //Left
  563.             cubeVertices.Add(verticles[0]); cubeVertices.Add(verticles[1]); cubeVertices.Add(verticles[4]);
  564.             cubeVertices.Add(verticles[1]); cubeVertices.Add(verticles[6]); cubeVertices.Add(verticles[4]);
  565.             //Back
  566.             cubeVertices.Add(verticles[4]); cubeVertices.Add(verticles[6]); cubeVertices.Add(verticles[7]);
  567.             cubeVertices.Add(verticles[5]); cubeVertices.Add(verticles[4]); cubeVertices.Add(verticles[7]);
  568.             //Right
  569.             cubeVertices.Add(verticles[5]); cubeVertices.Add(verticles[7]); cubeVertices.Add(verticles[2]);
  570.             cubeVertices.Add(verticles[7]); cubeVertices.Add(verticles[3]); cubeVertices.Add(verticles[2]);
  571.             //Top
  572.             cubeVertices.Add(verticles[2]); cubeVertices.Add(verticles[0]); cubeVertices.Add(verticles[5]);
  573.             cubeVertices.Add(verticles[5]); cubeVertices.Add(verticles[0]); cubeVertices.Add(verticles[4]);
  574.             //Bottom
  575.             cubeVertices.Add(verticles[1]); cubeVertices.Add(verticles[3]); cubeVertices.Add(verticles[6]);
  576.             cubeVertices.Add(verticles[6]); cubeVertices.Add(verticles[3]); cubeVertices.Add(verticles[7]);
  577.             return cubeVertices.ToArray();
  578.         }
  579.  
  580.         public void Draw()
  581.         {
  582.             basicEffect.CurrentTechnique.Passes[0].Apply();
  583.             this.graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, planetVertices, 0, planetVertices.Length / 3);
  584.         }
  585.  
  586.         public BasicEffect basicEffect { get; set; }
  587.     }
  588. }
  589.  
  590. #endregion
  591. /*_______________________________________________________________________________________________________________________*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement