示例#1
0
        public GameState()
        {
            // Creates a camera and sets the initial positions
              _camera = new Camera();
              _camera.PositionSpeed = 5;
              _camera.Move(_camera.Up, 400);
              _camera.Move(_camera.Backward, 1500);
              _camera.Move(_camera.Backward, 300);

              // Gets a copy of the "Terrain" model and tracks the number of hardware instances of each component
              _terrain = StaticModelManager.GetModel("Terrain");
              _terrain.Scale = new Vector(500, 20, 500);
              _terrain.RotationAmmounts = new Vector(0, 0, 0);
              _terrain.Position = new Vector(0, 0, 0);

              // Gets a copy of the "RedRanger" model and tracks the number of hardware instances of each component
              _redRanger = StaticModelManager.GetModel("RedRanger");
              _redRanger.RotationAmmounts = new Vector(0, 1, 0);
              _redRanger.RotationAngle = 180f;
              _redRanger.Scale = new Vector(5, 5, 5);
              _redRanger.Position = new Vector(_terrain.Position.X + 200, _terrain.Position.Y + 130, _terrain.Position.Z);

              // Gets a copy of the "YellowRanger" model and tracks the number of hardware instances of each component
              _yellowRanger = StaticModelManager.GetModel("YellowRanger");
              _yellowRanger.RotationAmmounts = new Vector(0, 1, 1);
              _yellowRanger.Scale = new Vector(10, 10, 10);
              _yellowRanger.Position = new Vector(_terrain.Position.X + 100, _terrain.Position.Y + 130, _terrain.Position.Z);

              // Gets a copy of the "BlackRanger" model and tracks the number of hardware instances of each component
              _blackRanger = StaticModelManager.GetModel("BlackRanger");
              _blackRanger.RotationAmmounts = new Vector(1, 1, 0);
              _blackRanger.Scale = new Vector(10, 10, 10);
              _blackRanger.Position = new Vector(_terrain.Position.X + 0, _terrain.Position.Y + 130, _terrain.Position.Z);

              // Gets a copy of the "BlueRanger" model and tracks the number of hardware instances of each component
              _blueRanger = StaticModelManager.GetModel("BlueRanger");
              _blueRanger.RotationAmmounts = new Vector(0, 1, 2);
              _blueRanger.Scale = new Vector(10, 10, 10);
              _blueRanger.Position = new Vector(_terrain.Position.X - 200, _terrain.Position.Y + 130, _terrain.Position.Z);

              // Gets a copy of the "PinkRanger" model and tracks the number of hardware instances of each component
              _pinkRanger = StaticModelManager.GetModel("PinkRanger");
              _pinkRanger.RotationAmmounts = new Vector(0, 1, 0);
              _pinkRanger.Scale = new Vector(10, 10, 10);
              _pinkRanger.Position = new Vector(_terrain.Position.X - 100, _terrain.Position.Y + 130, _terrain.Position.Z);

              // Gets a copy of the "RedRangerSeven" model and tracks the number of hardware instances of each component
              _RedRangerTwo = StaticModelManager.GetModel("RedRangerSeven");
              _RedRangerTwo.RotationAmmounts = new Vector(0, 1, 0);
              _RedRangerTwo.Scale = new Vector(20, 20, 20);
              _RedRangerTwo.Position = new Vector(_terrain.Position.X - 500, _terrain.Position.Y + 130, _terrain.Position.Z + 700);
        }
示例#2
0
        public PowerRangerDNA()
        {
            _camera = new Camera();
              _camera.PositionSpeed = 5;
              _camera.Move(_camera.Up, 400);
              _camera.Move(_camera.Backward, 1500);
              _camera.Move(_camera.Backward, 300);

              _skybox = new SkyBox();
              _skybox.Scale.X = 10000;
              _skybox.Scale.Y = 10000;
              _skybox.Scale.Z = 10000;
              _skybox.Left = TextureManager.Get("SkyboxLeft");
              _skybox.Right = TextureManager.Get("SkyboxRight");
              _skybox.Front = TextureManager.Get("SkyboxFront");
              _skybox.Back = TextureManager.Get("SkyboxBack");
              _skybox.Top = TextureManager.Get("SkyboxTop");

              _terrain = StaticModelManager.GetModel("Terrain");
              _terrain.Scale = new Vector(500, 20, 500);
              _terrain.RotationAmmounts = new Vector(0, 0, 0);
              _terrain.Position = new Vector(0, 0, 0);

              string[] colors = new string[] { "YellowRanger", "RedRanger", "BlueRanger", "BlackRanger", "PinkRanger" };

              Random random = new Random();
              _rangers = new StaticModel[300];
              for (int i = 0; i < _rangers.Length; i++)
              {
            _rangers[i] = StaticModelManager.GetModel(colors[random.Next(0, 5)]);
            _rangers[i].Position.X = i * 10 - 500;
            _rangers[i].Position.Y = _terrain.Position.Y + 130;
            _rangers[i].Position.Z = i * 10 - 530;
            _rangers[i].Scale = new Vector(5, 5, 5);
            _rangers[i].RotationAmmounts = new Vector(0, 1, 0);
            _rangers[i].RotationAngle = i * 2;
              }

              for (int i = 0; i < _rangers.Length; i+=2)
              {
            _rangers[i].Meshes.Remove("Body");
              }
        }
示例#3
0
        public SpriteState()
        {
            _camera = new Camera();
              _camera.PositionSpeed = 5;
              _camera.Move(_camera.Up, 400);
              _camera.Move(_camera.Backward, 1500);
              _camera.Move(_camera.Backward, 300);

              _terrain = StaticModelManager.GetModel("Terrain");
              _terrain.Scale = new Vector(500, 20, 500);
              _terrain.RotationAmmounts = new Vector(0, 0, 0);
              _terrain.Position = new Vector(0, 0, 0);

              _sprites = new Sprite(TextureManager.Get("Menu"));
              _sprites.Scale.X = 50;
              _sprites.Scale.Y = 50;
              _sprites2 = new Sprite(TextureManager.Get("Menu"));
              _sprites2.Scale.X = 50;
              _sprites2.Scale.Y = 50;
              _sprites3 = new Sprite(TextureManager.Get("Menu"));
              _sprites3.Scale.X = 50;
              _sprites3.Scale.Y = 50;
        }
示例#4
0
 public static void AddStaticModel(StaticModel model)
 {
     _staticModelBatch.Enqueue(
     model,
     (int)Math.Sqrt(
     Math.Pow(Renderer.CurrentCamera.Position.X - model.Position.X, 2) +
     Math.Pow(Renderer.CurrentCamera.Position.Y - model.Position.Y, 2) +
     Math.Pow(Renderer.CurrentCamera.Position.Z - model.Position.Z, 2)));
 }
示例#5
0
        ///// <summary>Renders a single static model using "GL.DrawArrays()".</summary>
        ///// <param name="camera">The camera used to capture the world (needed for the world to camera transformation).</param>
        ///// <param name="staticModel">The mesh to be rendered.</param>
        //public static void DrawStaticModel(StaticModel staticModel)
        //{
        //  SetProjectionMatrix();
        //  // Select the model view matrix to apply the world and camera transformation.
        //  GL.MatrixMode(MatrixMode.Modelview);
        //  // This line is not necessary when the camera matrix is loaded in just after.
        //  //GL.LoadIdentity();
        //  // Get and load the camera transformatino matrix.
        //  Matrix4 cameraTransform = _currentCamera.GetMatrix();
        //  GL.LoadMatrix(ref cameraTransform);
        //  //GL.Translate(-camera.Position.X, -camera.Position.Y, -camera.Position.Z);
        //  //GL.Rotate(-camera.RotationX, 1, 0, 0);
        //  //GL.Rotate(-camera.RotationY, 0, 1, 0);
        //  //GL.Rotate(-camera.RotationZ, 0, 0, 1);
        //  // Apply the world transformation due to the mesh's position, scale, and rotation
        //  GL.Translate(staticModel.Position.X, staticModel.Position.Y, staticModel.Position.Z);
        //  GL.Rotate(staticModel.RotationAngle, staticModel.RotationAmmounts.X, staticModel.RotationAmmounts.Y, staticModel.RotationAmmounts.Z);
        //  GL.Scale(staticModel.Scale.X, staticModel.Scale.Y, staticModel.Scale.Z);
        //  for (int i = 0; i < staticModel.Meshes.Count; i++)
        //  //foreach (Link<Texture, StaticMesh> link in staticModel.Meshes)
        //  {
        //    // If there is no vertex buffer, nothing will render anyway, so we can stop it now.
        //    if (staticModel.Meshes[i].Right.VertexBufferHandle == 0 ||
        //      // If there is no color or texture, nothing will render anyway
        //      (staticModel.Meshes[i].Right.ColorBufferHandle == 0 && staticModel.Meshes[i].Right.TextureCoordinateBufferHandle == 0))
        //      return;
        //    // Push current Array Buffer state so we can restore it later
        //    GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);
        //    if (GL.IsEnabled(EnableCap.Lighting))
        //    {
        //      // Normal Array Buffer
        //      if (staticModel.Meshes[i].Right.NormalBufferHandle != 0)
        //      {
        //        // Bind to the Array Buffer ID
        //        GL.BindBuffer(BufferTarget.ArrayBuffer, staticModel.Meshes[i].Right.NormalBufferHandle);
        //        // Set the Pointer to the current bound array describing how the data ia stored
        //        GL.NormalPointer(NormalPointerType.Float, 0, IntPtr.Zero);
        //        // Enable the client state so it will use this array buffer pointer
        //        GL.EnableClientState(ArrayCap.NormalArray);
        //      }
        //    }
        //    else
        //    {
        //      // Color Array Buffer (Colors not used when lighting is enabled)
        //      if (staticModel.Meshes[i].Right.ColorBufferHandle != 0)
        //      {
        //        // Bind to the Array Buffer ID
        //        GL.BindBuffer(BufferTarget.ArrayBuffer, staticModel.Meshes[i].Right.ColorBufferHandle);
        //        // Set the Pointer to the current bound array describing how the data ia stored
        //        GL.ColorPointer(3, ColorPointerType.Float, 0, IntPtr.Zero);
        //        // Enable the client state so it will use this array buffer pointer
        //        GL.EnableClientState(ArrayCap.ColorArray);
        //      }
        //    }
        //    // Texture Array Buffer
        //    if (GL.IsEnabled(EnableCap.Texture2D))
        //    {
        //      if (staticModel.Meshes[i].Right.TextureCoordinateBufferHandle != 0)
        //      {
        //        // Bind the texture to which the UVs are mapping to.
        //        GL.BindTexture(TextureTarget.Texture2D, staticModel.Meshes[i].Left.GpuHandle);
        //        // Bind to the Array Buffer ID
        //        GL.BindBuffer(BufferTarget.ArrayBuffer, staticModel.Meshes[i].Right.TextureCoordinateBufferHandle);
        //        // Set the Pointer to the current bound array describing how the data ia stored
        //        GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero);
        //        // Enable the client state so it will use this array buffer pointer
        //        GL.EnableClientState(ArrayCap.TextureCoordArray);
        //      }
        //      else
        //        // Nothing will render if this branching is reached.
        //        return;
        //    }
        //    // Vertex Array Buffer
        //    // Bind to the Array Buffer ID
        //    GL.BindBuffer(BufferTarget.ArrayBuffer, staticModel.Meshes[i].Right.VertexBufferHandle);
        //    // Set the Pointer to the current bound array describing how the data ia stored
        //    GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero);
        //    // Enable the client state so it will use this array buffer pointer
        //    GL.EnableClientState(ArrayCap.VertexArray);
        //    if (staticModel.Meshes[i].Right.ElementBufferHandle != 0)
        //    {
        //      // Element Array Buffer
        //      // Bind to the Array Buffer ID
        //      GL.BindBuffer(BufferTarget.ElementArrayBuffer, staticModel.Meshes[i].Right.ElementBufferHandle);
        //      // Set the Pointer to the current bound array describing how the data ia stored
        //      GL.IndexPointer(IndexPointerType.Int, 0, IntPtr.Zero);
        //      // Enable the client state so it will use this array buffer pointer
        //      GL.EnableClientState(ArrayCap.IndexArray);
        //      // Draw the elements in the element array buffer
        //      // Draws up items in the Color, Vertex, TexCoordinate, and Normal Buffers using indices in the ElementArrayBuffer
        //      GL.DrawElements(BeginMode.Triangles, staticModel.Meshes[i].Right.VertexCount, DrawElementsType.UnsignedInt, 0);
        //    }
        //    else
        //    {
        //      // Select the vertex buffer as the active buffer (I don't think this is necessary but I haven't tested it yet).
        //      GL.BindBuffer(BufferTarget.ArrayBuffer, staticModel.Meshes[i].Right.VertexBufferHandle);
        //      // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()".
        //      GL.DrawArrays(BeginMode.Triangles, 0, staticModel.Meshes[i].Right.VertexCount);
        //    }
        //    GL.PopClientAttrib();
        //  }
        //}
        /// <summary>Renders a single static model using "GL.DrawArrays()".</summary>
        /// <param name="camera">The camera used to capture the world (needed for the world to camera transformation).</param>
        /// <param name="staticModel">The mesh to be rendered.</param>
        public static void DrawStaticModel(StaticModel staticModel)
        {
            SetProjectionMatrix();

              // Select the model view matrix to apply the world and camera transformation.
              GL.MatrixMode(MatrixMode.Modelview);

              // This line is not necessary when the camera matrix is loaded in just after.
              //GL.LoadIdentity();

              // Get and load the camera transformatino matrix.
              Matrix4 cameraTransform = _currentCamera.GetMatrix();
              GL.LoadMatrix(ref cameraTransform);

              // Apply the world transformation due to the mesh's position, scale, and rotation
              GL.Translate(staticModel.Position.X, staticModel.Position.Y, staticModel.Position.Z);
              GL.Rotate(staticModel.RotationAngle, staticModel.RotationAmmounts.X, staticModel.RotationAmmounts.Y, staticModel.RotationAmmounts.Z);
              GL.Scale(staticModel.Scale.X, staticModel.Scale.Y, staticModel.Scale.Z);

              staticModel.Meshes.Foreach(DrawStaticModelPart);
        }