Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace _3D_Trening
- {
- /// <summary>
- /// This is the main type for your game.
- /// </summary>
- public class Game1 : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Texture2D Background;
- Matrix ViewMatrix, WorldMatrix, ProjectionMatrix;
- BasicEffect BasicEffect;
- VertexPositionColor[] geometryLines;
- VertexPositionColor[] geometryPlanetSun;
- VertexPositionColor[] geometryPlanetBlue;
- VertexPositionColor[] geometryPlanetRed;
- VertexPositionColor[] geometryPlanetGreen;
- float Anglex = 0.0f, Angley = 0.0f,Anglez= 0.0f;
- float near, far;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- 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()
- {
- // TODO: Add your initialization logic here
- this.Window.AllowUserResizing = true;
- this.IsMouseVisible = true;
- 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()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- BasicEffect = new BasicEffect(GraphicsDevice);
- BasicEffect.VertexColorEnabled = true;
- geometryLines = new VertexPositionColor[2];
- geometryPlanetSun = new VertexPositionColor[24];
- geometryPlanetBlue = new VertexPositionColor[24];
- geometryPlanetRed = new VertexPositionColor[24];
- geometryPlanetGreen = new VertexPositionColor[24];
- geometryLines[0] = new VertexPositionColor(new Vector3(20, 0, 1), Color.Red);
- geometryLines[1] = new VertexPositionColor(new Vector3(-20, 0, 1), Color.Red);
- #region Sun
- geometryPlanetSun[0] = new VertexPositionColor(new Vector3(-1, -1, 1), Color.Yellow);
- geometryPlanetSun[1] = new VertexPositionColor(new Vector3(-1, 1, 1), Color.Yellow);
- geometryPlanetSun[2] = new VertexPositionColor(new Vector3(1, -1, 1), Color.Yellow);
- geometryPlanetSun[3] = new VertexPositionColor(new Vector3(-1, 1, 1), Color.Yellow);
- geometryPlanetSun[4] = new VertexPositionColor(new Vector3(1, 1, 1), Color.Yellow);
- geometryPlanetSun[5] = new VertexPositionColor(new Vector3(1, -1, 1), Color.Yellow);
- geometryPlanetSun[6] = new VertexPositionColor(new Vector3(1, -1, 1), Color.Yellow);
- geometryPlanetSun[7] = new VertexPositionColor(new Vector3(1, 1, 1), Color.Yellow);
- geometryPlanetSun[8] = new VertexPositionColor(new Vector3(1, 1, -1), Color.Yellow);
- geometryPlanetSun[9] = new VertexPositionColor(new Vector3(1, -1, -1), Color.Yellow);
- geometryPlanetSun[10] = new VertexPositionColor(new Vector3(1, -1, 1), Color.Yellow);
- geometryPlanetSun[11] = new VertexPositionColor(new Vector3(1, 1, -1), Color.Yellow);
- geometryPlanetSun[13] = new VertexPositionColor(new Vector3(-1, 1, -1), Color.Yellow);
- geometryPlanetSun[12] = new VertexPositionColor(new Vector3(1, 1, -1), Color.Yellow);
- geometryPlanetSun[14] = new VertexPositionColor(new Vector3(-1, -1, -1), Color.Yellow);
- geometryPlanetSun[16] = new VertexPositionColor(new Vector3(1, 1, -1), Color.Yellow);
- geometryPlanetSun[15] = new VertexPositionColor(new Vector3(1, -1, -1), Color.Yellow);
- geometryPlanetSun[17] = new VertexPositionColor(new Vector3(-1, -1, -1), Color.Yellow);
- geometryPlanetSun[18] = new VertexPositionColor(new Vector3(-1, 1, -1), Color.Yellow);
- geometryPlanetSun[19] = new VertexPositionColor(new Vector3(-1, 1, 1), Color.Yellow);
- geometryPlanetSun[20] = new VertexPositionColor(new Vector3(-1, -1, 1), Color.Yellow);
- geometryPlanetSun[22] = new VertexPositionColor(new Vector3(-1, 1, -1), Color.Yellow);
- geometryPlanetSun[21] = new VertexPositionColor(new Vector3(-1, -1, -1), Color.Yellow);
- geometryPlanetSun[23] = new VertexPositionColor(new Vector3(-1, -1, 1), Color.Yellow);
- #endregion
- #region BluePlanet
- //- 4 = -1 , -2 = 1
- geometryPlanetBlue[0] = new VertexPositionColor(new Vector3(-4, -4, -2), Color.Red);
- geometryPlanetBlue[1] = new VertexPositionColor(new Vector3(-4, -2, -2), Color.Red);
- geometryPlanetBlue[2] = new VertexPositionColor(new Vector3(-2, -4, -2), Color.Red);
- geometryPlanetBlue[3] = new VertexPositionColor(new Vector3(-4, -2, -2), Color.Red);
- geometryPlanetBlue[4] = new VertexPositionColor(new Vector3(-2, -2, -2), Color.Red);
- geometryPlanetBlue[5] = new VertexPositionColor(new Vector3(-2, -4, -2), Color.Red);
- geometryPlanetBlue[6] = new VertexPositionColor(new Vector3(-2, -4, -2),Color.Blue);
- geometryPlanetBlue[7] = new VertexPositionColor(new Vector3(-2, -2, -2), Color.Blue);
- geometryPlanetBlue[8] = new VertexPositionColor(new Vector3(-2, -2, -4), Color.Blue);
- geometryPlanetBlue[9] = new VertexPositionColor(new Vector3(-2, -4, -4), Color.Blue);
- geometryPlanetBlue[10] = new VertexPositionColor(new Vector3(-2, -4, -2), Color.Blue);
- geometryPlanetBlue[11] = new VertexPositionColor(new Vector3(-2, -2, -4), Color.Blue);
- geometryPlanetBlue[12] = new VertexPositionColor(new Vector3(-2, -2, -4), Color.Green);
- geometryPlanetBlue[13] = new VertexPositionColor(new Vector3(-4, -2, -4), Color.Green);
- geometryPlanetBlue[14] = new VertexPositionColor(new Vector3(-4, -4, -4), Color.Green);
- geometryPlanetBlue[15] = new VertexPositionColor(new Vector3(-2, -4, -4), Color.Green);
- geometryPlanetBlue[16] = new VertexPositionColor(new Vector3(-2, -2, -4), Color.Green);
- geometryPlanetBlue[17] = new VertexPositionColor(new Vector3(-4, -4, -4), Color.Green);
- geometryPlanetBlue[18] = new VertexPositionColor(new Vector3(-4, -2, -4), Color.Purple);
- geometryPlanetBlue[19] = new VertexPositionColor(new Vector3(-4, -2, -2), Color.Purple);
- geometryPlanetBlue[20] = new VertexPositionColor(new Vector3(-4, -4, -2), Color.Purple);
- geometryPlanetBlue[21] = new VertexPositionColor(new Vector3(-4, -4, -4), Color.Purple);
- geometryPlanetBlue[22] = new VertexPositionColor(new Vector3(-4, -2, -4), Color.Purple);
- geometryPlanetBlue[23] = new VertexPositionColor(new Vector3(-4, -4, -2), Color.Purple);
- #endregion
- #region RedPlanet
- // 2 - -1 , 4 - 1
- geometryPlanetRed[0] = new VertexPositionColor(new Vector3(2, 2, 4), Color.Red);
- geometryPlanetRed[1] = new VertexPositionColor(new Vector3(2, 4, 4), Color.Red);
- geometryPlanetRed[2] = new VertexPositionColor(new Vector3(4, 2, 4), Color.Red);
- geometryPlanetRed[3] = new VertexPositionColor(new Vector3(2, 4, 4), Color.Red);
- geometryPlanetRed[4] = new VertexPositionColor(new Vector3(4, 4, 4), Color.Red);
- geometryPlanetRed[5] = new VertexPositionColor(new Vector3(4, 2, 4), Color.Red);
- geometryPlanetRed[6] = new VertexPositionColor(new Vector3(4, 2, 4), Color.Blue);
- geometryPlanetRed[7] = new VertexPositionColor(new Vector3(4, 4, 4), Color.Blue);
- geometryPlanetRed[8] = new VertexPositionColor(new Vector3(4, 4, 2), Color.Blue);
- geometryPlanetRed[9] = new VertexPositionColor(new Vector3(4, 2, 2), Color.Blue);
- geometryPlanetRed[10] = new VertexPositionColor(new Vector3(4, 2, 4), Color.Blue);
- geometryPlanetRed[11] = new VertexPositionColor(new Vector3(4, 4, 2), Color.Blue);
- geometryPlanetRed[12] = new VertexPositionColor(new Vector3(4, 4, 2), Color.Green);
- geometryPlanetRed[13] = new VertexPositionColor(new Vector3(2, 4, 2), Color.Green);
- geometryPlanetRed[14] = new VertexPositionColor(new Vector3(2, 2, 2), Color.Green);
- geometryPlanetRed[15] = new VertexPositionColor(new Vector3(4, 2, 2), Color.Green);
- geometryPlanetRed[16] = new VertexPositionColor(new Vector3(4, 4, 2), Color.Green);
- geometryPlanetRed[17] = new VertexPositionColor(new Vector3(2, 2, 2), Color.Green);
- geometryPlanetRed[18] = new VertexPositionColor(new Vector3(2, 4, 2), Color.Purple);
- geometryPlanetRed[19] = new VertexPositionColor(new Vector3(2, 4, 4), Color.Purple);
- geometryPlanetRed[20] = new VertexPositionColor(new Vector3(2, 2, 4), Color.Purple);
- geometryPlanetRed[22] = new VertexPositionColor(new Vector3(2, 4, 2), Color.Purple);
- geometryPlanetRed[21] = new VertexPositionColor(new Vector3(2, 2, 2), Color.Purple);
- geometryPlanetRed[23] = new VertexPositionColor(new Vector3(2, 2, 4), Color.Purple);
- #endregion
- #region GreenPlanet
- // 1 - -1 , 3 - 1
- geometryPlanetGreen[0] = new VertexPositionColor(new Vector3(1, 1, 3), Color.Red);
- geometryPlanetGreen[1] = new VertexPositionColor(new Vector3(1, 3, 3), Color.Red);
- geometryPlanetGreen[2] = new VertexPositionColor(new Vector3(3, 1, 3), Color.Red);
- geometryPlanetGreen[3] = new VertexPositionColor(new Vector3(1, 3, 3), Color.Red);
- geometryPlanetGreen[4] = new VertexPositionColor(new Vector3(3, 3, 3), Color.Red);
- geometryPlanetGreen[5] = new VertexPositionColor(new Vector3(3, 1, 3), Color.Red);
- geometryPlanetGreen[6] = new VertexPositionColor(new Vector3(3, 1, 3), Color.Blue);
- geometryPlanetGreen[7] = new VertexPositionColor(new Vector3(3, 3, 3), Color.Blue);
- geometryPlanetGreen[8] = new VertexPositionColor(new Vector3(3, 3, 1), Color.Blue);
- geometryPlanetGreen[9] = new VertexPositionColor(new Vector3(3, 1, 1), Color.Blue);
- geometryPlanetGreen[10] = new VertexPositionColor(new Vector3(3, 1, 3), Color.Blue);
- geometryPlanetGreen[11] = new VertexPositionColor(new Vector3(3, 3, 1), Color.Blue);
- geometryPlanetGreen[12] = new VertexPositionColor(new Vector3(3, 3, 1), Color.Green);
- geometryPlanetGreen[13] = new VertexPositionColor(new Vector3(1, 3, 1), Color.Green);
- geometryPlanetGreen[14] = new VertexPositionColor(new Vector3(1, 1, 1), Color.Green);
- geometryPlanetGreen[15] = new VertexPositionColor(new Vector3(3, 1, 1), Color.Green);
- geometryPlanetGreen[16] = new VertexPositionColor(new Vector3(3, 3, 1), Color.Green);
- geometryPlanetGreen[17] = new VertexPositionColor(new Vector3(1, 1, 1), Color.Green);
- geometryPlanetGreen[18] = new VertexPositionColor(new Vector3(1, 3, 1), Color.Purple);
- geometryPlanetGreen[19] = new VertexPositionColor(new Vector3(1, 3, 3), Color.Purple);
- geometryPlanetGreen[20] = new VertexPositionColor(new Vector3(1, 1, 3), Color.Purple);
- #endregion
- Background = Content.Load<Texture2D>("kosmos");
- // TODO: use this.Content to load your game content here
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// game-specific content.
- /// </summary>
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- /// <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)
- {
- var keyboard = Keyboard.GetState(); // zmienna pomocnicza
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- // TODO: Add your update logic here
- if (keyboard.IsKeyDown(Keys.Right)) Angley += 0.02f;
- if (keyboard.IsKeyDown(Keys.Left)) Angley -= 0.02f;
- if (keyboard.IsKeyDown(Keys.Up)) Anglex += 0.02f;
- if (keyboard.IsKeyDown(Keys.Down)) Anglex -= 0.02f;
- if (keyboard.IsKeyDown(Keys.Z)) Anglez += 0.2f;
- if (keyboard.IsKeyDown(Keys.P)) Anglez -= 0.2f;
- WorldMatrix = Matrix.Identity;
- ViewMatrix = Matrix.CreateLookAt
- (
- new Vector3(0.0f, 0.0f, 20.0f),
- Vector3.Zero, Vector3.Up
- );
- ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(50)
- , GraphicsDevice.Viewport.AspectRatio, 0.01f, 1000.0f);
- ViewMatrix = Matrix.CreateRotationX(Anglex) *
- Matrix.CreateRotationY(Angley) * Matrix.CreateRotationZ(Anglez) * ViewMatrix;
- BasicEffect.View = ViewMatrix;
- BasicEffect.World = WorldMatrix;
- BasicEffect.Projection = ProjectionMatrix;
- base.Update(gameTime);
- }
- /// <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.CornflowerBlue);
- spriteBatch.Begin();
- spriteBatch.Draw(Background, GraphicsDevice.Viewport.TitleSafeArea, Color.White);
- spriteBatch.End();
- BasicEffect.CurrentTechnique.Passes[0].Apply();
- GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, geometryPlanetSun, 0, 8);
- GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, geometryPlanetBlue, 0, 8);
- GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, geometryPlanetRed, 0, 8);
- // GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, geometryPlanetGreen, 0, 8);
- GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, geometryLines, 0, 1);
- // TODO: Add your drawing code here
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement