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"); } }
public void Load() { _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.Orientation = new Quaternion(0, 0, 0, 0); _terrain.Position = new Vector(0, 0, 0); _mountain = StaticModelManager.GetModel("Mountain"); _mountain.Scale = new Vector(5000, 5000, 5000); _mountain.Orientation = new Quaternion(0, 0, 0, 0); _mountain.Position = new Vector(4000, 0, 1000); _mountain2 = StaticModelManager.GetModel("Mountain2"); _mountain2.Scale = new Vector(3500, 3500, 3500); _mountain2.Orientation = new Quaternion(0, 0, 0, 0); _mountain2.Position = new Vector(0, 0, 2500); GenerateUnits(); Renderer.Font = TextManager.GetFont("Calibri"); // ONCE YOU ARE DONE LOADING, BE SURE TO SET YOUR READY // PROPERTY TO TRUE SO MY ENGINE DOESN'T SCREAM AT YOU _isReady = true; }
public static void DrawSkybox(SkyBox skybox) { // Apply the 3D projection matrix transformation SetProjectionMatrix(); //if (skybox.ShaderOverride != null) // GL.UseProgram(_defaultShaderProgram.GpuHandle); //else // GL.UseProgram(ShaderManager.DefaultShader.GpuHandle); GL.UseProgram(_defaultShaderProgram.GpuHandle); // Apply the model view matrix transformations GL.MatrixMode(MatrixMode.Modelview); // Apply the camera transformation Matrix4 cameraTransform = _currentCamera.GetMatrix(); GL.LoadMatrix(ref cameraTransform); // Apply the world transformation GL.Translate(skybox.Position.X, skybox.Position.Y, skybox.Position.Z); GL.Scale(skybox.Scale.X, skybox.Scale.Y, skybox.Scale.Z); // Set up verteces GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero); GL.EnableClientState(ArrayCap.VertexArray); // Select texture and set up texture coordinates GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, IntPtr.Zero); GL.EnableClientState(ArrayCap.TextureCoordArray); // Render left side of skybox GL.BindTexture(TextureTarget.Texture2D, skybox.Left.GpuHandle); //GL.DrawArrays(PrimitiveType.Triangles, 0, 6); GL.DrawArrays(BeginMode.Triangles, 0, 6); // Render front side of skybox GL.BindTexture(TextureTarget.Texture2D, skybox.Front.GpuHandle); //GL.DrawArrays(PrimitiveType.Triangles, 6, 6); GL.DrawArrays(BeginMode.Triangles, 6, 6); // Render right side of skybox GL.BindTexture(TextureTarget.Texture2D, skybox.Right.GpuHandle); //GL.DrawArrays(PrimitiveType.Triangles, 12, 6); GL.DrawArrays(BeginMode.Triangles, 12, 6); // Render back side of skybox GL.BindTexture(TextureTarget.Texture2D, skybox.Back.GpuHandle); //GL.DrawArrays(PrimitiveType.Triangles, 18, 6); GL.DrawArrays(BeginMode.Triangles, 18, 6); // Render top side of skybox GL.BindTexture(TextureTarget.Texture2D, skybox.Top.GpuHandle); //GL.DrawArrays(PrimitiveType.Triangles, 24, 6); GL.DrawArrays(BeginMode.Triangles, 24, 6); // Render bottom side of skybox //GL.BindTexture(TextureTarget.Texture2D, skybox.Bottom.GpuHandle); //GL.DrawArrays(PrimitiveType.Triangles, 30, 6); //GL.DrawArrays(BeginMode.Triangles, 30, 6); }
public SkyboxState() { // 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); _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"); }
public void Load() { _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.Orientation = new Quaternion(0, 0, 0, 0); _terrain.Position = new Vector(0, 0, 0); _mushroomCloud = StaticModelManager.GetModel("MushroomCloud"); _mushroomCloud.Scale = new Vector(500, 20, 500); _mushroomCloud.Orientation = new Quaternion(0, 0, 0, 0); _mushroomCloud.Position.X = 0; _mushroomCloud.Position.Y = _terrain.Position.Y + 30; _mushroomCloud.Position.Z = 0; _time = 0; _bool = false; _mountain = StaticModelManager.GetModel("Mountain"); _mountain.Scale = new Vector(5000, 5000, 5000); _mountain.Orientation = new Quaternion(0, 0, 0, 0); _mountain.Position = new Vector(4000, 0, 1000); _mountain2 = StaticModelManager.GetModel("Mountain2"); _mountain2.Scale = new Vector(3500, 3500, 3500); _mountain2.Orientation = new Quaternion(0, 0, 0, 0); _mountain2.Position = new Vector(0, 0, 2500); string[] colors = new string[] { "YellowRanger", "RedRanger", "BlueRanger", "BlackRanger", "PinkRanger" }; Random random = new Random(); _rangers = new StaticModel[80]; for (int i = 0; i < _rangers.Length; i++) { _rangers[i] = StaticModelManager.GetModel(colors[random.Next(0, 5)]); _rangers[i].Position.X = -100; _rangers[i].Position.Y = _terrain.Position.Y + 10; _rangers[i].Position.Z = -i * 50; _rangers[i].Scale = new Vector(5, 5, 5); _rangers[i].Orientation = new Quaternion(0, 1, 0, 0); _rangers[i].Orientation.W = i * 2; _rangers[i].Id = "Ranger" + i; _octree.Add(_rangers[i]); } _tuxes = new StaticModel[80]; for (int i = 0; i < _tuxes.Length; i++) { _tuxes[i] = StaticModelManager.GetModel("Tux"); _tuxes[i].Position.X = 100; _tuxes[i].Position.Y = _terrain.Position.Y + 10; _tuxes[i].Position.Z = i * 50; _tuxes[i].Scale = new Vector(25, 25, 25); _tuxes[i].Orientation = new Quaternion(0, 1, 0, 0); _tuxes[i].Orientation.W = i * 2; _tuxes[i].Id = "Tux" + i; _octree.Add(_tuxes[i]); } for (int i = 0; i < _rangers.Length; i += 2) { _rangers[i].Meshes.Remove("Body"); //_octree.Remove("Ranger" + i); _tuxes[i].Meshes.Remove("Body"); } Renderer.Font = TextManager.GetFont("Calibri"); // ONCE YOU ARE DONE LOADING, BE SURE TO SET YOUR READY // PROPERTY TO TRUE SO MY ENGINE DOESN'T SCREAM AT YOU _isReady = true; }
public static void DrawSkybox(SkyBox skybox) { SetProjectionMatrix(); GL.MatrixMode(MatrixMode.Modelview); Matrix4 cameraTransform = _currentCamera.GetMatrix(); GL.LoadMatrix(ref cameraTransform); GL.Translate(skybox.Position.X, skybox.Position.Y, skybox.Position.Z); GL.Scale(skybox.Scale.X, skybox.Scale.Y, skybox.Scale.Z); // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); // 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); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Left.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); // 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); // 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, skybox.GpuVertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, 6); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Front.GpuHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 6, 6); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Right.GpuHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 12, 6); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Back.GpuHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 18, 6); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Top.GpuHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 24, 6); /*//DRAW FACE 1 (LEFT) // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); // 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); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Left.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); // 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); // 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, skybox.GpuVertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, 6); //DRAW FACE 2 (FRONT) // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.VertexPointer(3, VertexPointerType.Float, 0, new IntPtr(18)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.VertexArray); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Front.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, new IntPtr(12)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.TextureCoordArray); // 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, skybox.GpuVertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, 6); //DRAW FACE 3 (Right) // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.VertexPointer(3, VertexPointerType.Float, 0, new IntPtr(36)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.VertexArray); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Right.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, new IntPtr(24)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.TextureCoordArray); // 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, skybox.GpuVertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, 6); //DRAW FACE 4 (Back) // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.VertexPointer(3, VertexPointerType.Float, 0, new IntPtr(54)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.VertexArray); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Back.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, new IntPtr(36)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.TextureCoordArray); // 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, skybox.GpuVertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, 6); //DRAW FACE 5 (Top) // Vertex Array Buffer // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GpuVertexBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.VertexPointer(3, VertexPointerType.Float, 0, new IntPtr(72)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.VertexArray); // Bind the texture to which the UVs are mapping to. GL.BindTexture(TextureTarget.Texture2D, skybox.Top.GpuHandle); // Bind to the Array Buffer ID GL.BindBuffer(BufferTarget.ArrayBuffer, skybox.GPUTextureCoordinateBufferHandle); // Set the Pointer to the current bound array describing how the data ia stored GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, new IntPtr(48)); // Enable the client state so it will use this array buffer pointer GL.EnableClientState(ArrayCap.TextureCoordArray); // 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, skybox.GpuVertexBufferHandle); // There is no index buffer, so we shoudl use "DrawArrays()" instead of "DrawIndeces()". GL.DrawArrays(BeginMode.Triangles, 0, 6);*/ }