Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using TheMarket.Share;
- namespace Entities
- {
- internal class FirmaGraph : IEntity
- {
- private BasicEffect basicEffect;
- private Vector3 ct = Vector3.Zero;
- private Vector3 ctpos = Vector3.Zero;
- private Vector3 ctposWorld = Vector3.Zero;
- private Vector3 ctrotWorld = Vector3.Zero;
- private int movmode;
- private Matrix projection; //Matrix.CreateOrthographic(720f, 1280f, -2000f,2000f);
- private TimeSpan ts = TimeSpan.Zero;
- private string tx = "";
- private VertexBuffer vertexBuffer;
- private Matrix view;
- private VertexPositionColor[] vp =
- {
- new VertexPositionColor(new Vector3(0, 0, 0), Color.Black),
- new VertexPositionColor(new Vector3(10, 10, 0), Color.Black),
- new VertexPositionColor(new Vector3(10, 0, 0), Color.Black),
- new VertexPositionColor(new Vector3(0, 10, 0), Color.Black),
- new VertexPositionColor(new Vector3(10, 10, 0), Color.Black),
- new VertexPositionColor(new Vector3(0, 0, 10), Color.Black)
- };
- private Matrix world = Matrix.CreateTranslation(0, 0, 0);
- public Vector2 Draw(GameTime gameTime, SpriteBatch spriteBatch)
- {
- var cameraPosition = new Vector3(350, 350, 350);
- var cameraLookAtVector = new Vector3(350, 350, 0);
- var cameraUpVector = Vector3.UnitZ;
- basicEffect.View = Matrix.CreateLookAt(
- cameraPosition, cameraLookAtVector, cameraUpVector);
- //+ Matrix.CreateTranslation(ctpos) + Matrix.CreateRotationX((float)MathHelper.Degree2Radian(ct.X)) + Matrix.CreateRotationY((float)MathHelper.Degree2Radian(ct.Y)) + Matrix.CreateRotationZ((float)MathHelper.Degree2Radian(ct.Z));
- basicEffect.Projection = Matrix.CreateOrthographicOffCenter(new Rectangle(0, 0, 700, 700), 0.1f, 1000);
- basicEffect.VertexColorEnabled = true;
- /*
- * old
- basicEffect.World = world + Matrix.CreateTranslation(ctposWorld) + Matrix.CreateRotationX((float)MathHelper.Degree2Radian(ctrotWorld.X)) + Matrix.CreateRotationY((float)MathHelper.Degree2Radian(ctrotWorld.Y)) + Matrix.CreateRotationZ((float)MathHelper.Degree2Radian(ctrotWorld.Z));
- basicEffect.View = view +Matrix.CreateTranslation(ctpos)+ Matrix.CreateRotationX((float)MathHelper.Degree2Radian(ct.X)) + Matrix.CreateRotationY((float)MathHelper.Degree2Radian(ct.Y)) + Matrix.CreateRotationZ((float)MathHelper.Degree2Radian(ct.Z));
- basicEffect.Projection = projection;
- basicEffect.VertexColorEnabled = true;*/
- spriteBatch.Begin(); //Show information of positions on screen
- InDrawFunctions.Set(spriteBatch, new Vector2(250, 675), tx, 0);
- InDrawFunctions.Set(spriteBatch, new Vector2(0, 600), ct.ToString(), 0);
- InDrawFunctions.Set(spriteBatch, new Vector2(0, 640), ctpos.ToString(), 0);
- InDrawFunctions.Set(spriteBatch, new Vector2(350, 600), ctrotWorld.ToString(), 0);
- InDrawFunctions.Set(spriteBatch, new Vector2(350, 640), ctposWorld.ToString(), 0);
- spriteBatch.End();
- Manager.Game.GraphicsDevice.SetVertexBuffer(vertexBuffer);
- var rasterizerState = new RasterizerState();
- rasterizerState.CullMode = CullMode.None;
- Manager.Game.GraphicsDevice.RasterizerState = rasterizerState;
- foreach (var pass in basicEffect.CurrentTechnique.Passes)
- {
- pass.Apply();
- Manager.Game.GraphicsDevice.DrawPrimitives(PrimitiveType.LineList, 0, 7);
- }
- return Vector2.One;
- }
- public void Initialize()
- {
- var center = new Vector2(350, 350);
- /*center.X = Manager.Game.GraphicsDevice.Viewport.Width * 0.5f;
- center.Y = Manager.Game.GraphicsDevice.Viewport.Height * 0.5f;*/
- }
- public void LoadContent()
- {
- basicEffect = new BasicEffect(Manager.Game.GraphicsDevice);
- var vertices = new VertexPositionColor[14];
- vertices[0] = new VertexPositionColor(new Vector3(0, 0, 0f), Color.Red);
- vertices[1] = new VertexPositionColor(new Vector3(100, 0, 0), Color.Black); // not visible
- vertices[2] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Blue);
- vertices[3] = new VertexPositionColor(new Vector3(0, 0, 100), Color.Black);
- vertices[4] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Green);
- vertices[5] = new VertexPositionColor(new Vector3(0, 100, 0), Color.Black);
- vertices[6] = new VertexPositionColor(new Vector3(0, 0, 0), Color.White);
- vertices[7] = new VertexPositionColor(new Vector3(100, 100, 0), Color.Black);
- vertices[8] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Chocolate);
- vertices[9] = new VertexPositionColor(new Vector3(700, 701, 0), Color.Black);
- vertices[10] = new VertexPositionColor(new Vector3(0, 100, 0), Color.Yellow);
- vertices[11] = new VertexPositionColor(new Vector3(0, 100, 100), Color.Black);
- vertices[12] = new VertexPositionColor(new Vector3(0, 0, 100), Color.Yellow);
- vertices[13] = new VertexPositionColor(new Vector3(0, 100, 100), Color.Black);
- vertexBuffer = new VertexBuffer(Manager.Game.GraphicsDevice, typeof(VertexPositionColor), 14,
- BufferUsage.WriteOnly);
- vertexBuffer.SetData(vertices);
- }
- public void Unload()
- {
- }
- public void Update(GameTime gameTime)
- {
- var ks = Keyboard.GetState();
- var repeat = 1;
- ts += gameTime.ElapsedGameTime;
- if (ts > TimeSpan.FromMilliseconds(ks.IsKeyDown(Keys.LeftShift) ? 50 : 500))
- {
- if (ks.IsKeyDown(Keys.LeftControl)) repeat = 10;
- for (var i = 0; i < repeat; i++)
- switch (movmode)
- {
- case 0:
- if (ks.IsKeyDown(Keys.Up)) ct.Y++;
- if (ks.IsKeyDown(Keys.Down)) ct.Y--;
- if (ks.IsKeyDown(Keys.Left)) ct.X--;
- if (ks.IsKeyDown(Keys.Right)) ct.X++;
- if (ks.IsKeyDown(Keys.RightShift)) ct.Z++;
- if (ks.IsKeyDown(Keys.RightControl)) ct.Z--;
- tx = "Rotate Camera";
- break;
- case 1:
- if (ks.IsKeyDown(Keys.Up)) ctpos.Y++;
- if (ks.IsKeyDown(Keys.Down)) ctpos.Y--;
- if (ks.IsKeyDown(Keys.Left)) ctpos.X--;
- if (ks.IsKeyDown(Keys.Right)) ctpos.X++;
- if (ks.IsKeyDown(Keys.RightShift)) ctpos.Z++;
- if (ks.IsKeyDown(Keys.RightControl)) ctpos.Z--;
- tx = "Move Camera";
- break;
- case 2:
- if (ks.IsKeyDown(Keys.Up)) ctposWorld.Y++;
- if (ks.IsKeyDown(Keys.Down)) ctposWorld.Y--;
- if (ks.IsKeyDown(Keys.Left)) ctposWorld.X--;
- if (ks.IsKeyDown(Keys.Right)) ctposWorld.X++;
- if (ks.IsKeyDown(Keys.RightShift)) ctposWorld.Z++;
- if (ks.IsKeyDown(Keys.RightControl)) ctposWorld.Z--;
- tx = "Move World";
- break;
- case 3:
- if (ks.IsKeyDown(Keys.Up)) ctrotWorld.Y++;
- if (ks.IsKeyDown(Keys.Down)) ctrotWorld.Y--;
- if (ks.IsKeyDown(Keys.Left)) ctrotWorld.X--;
- if (ks.IsKeyDown(Keys.Right)) ctrotWorld.X++;
- if (ks.IsKeyDown(Keys.RightShift)) ctrotWorld.Z++;
- if (ks.IsKeyDown(Keys.RightControl)) ctrotWorld.Z--;
- tx = "Rotate World";
- break;
- default:
- tx = "Unknown";
- break;
- }
- if (ks.IsKeyDown(Keys.PageUp)) movmode++;
- else if (ks.IsKeyDown(Keys.PageDown)) movmode--;
- ts = TimeSpan.Zero;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement