Example #1
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            timestep = mTimer.GetElapsedSeconds();

            Sphere.Update();
            Light.Update();
            EmitterBox.Update();
            SpotLight.Update();
            Camera.Update(camera);
        }
Example #2
0
        }  //Draw

        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            timestep = mTimer.GetElapsedSeconds();

            Portal_Camera();

            Sphere.Update();
            Light.Update();
            Emitter.Update();
            SpotLight.Update();
            Camera.Update(camera);
            OutputDetails.Update();
            splash.Update();

            foreach (ParticleSystem sp in ActiveParticleSystems)
            {
                sp.Update();
            }

            //Updates the portal views
            mTopPortalView    = Matrix4.Invert(mGroundModel) * Matrix4.CreateTranslation(-9, -15, 0) * Matrix4.CreateRotationY(-(float)Math.PI / 2) * Matrix4.CreateRotationZ(-(float)Math.PI / 2) * topRotation;
            mBottomPortalView = Matrix4.Invert(mGroundModel) * Matrix4.CreateTranslation(0, 25, 0f) * Matrix4.CreateRotationX(-(float)Math.PI / 2) * bottomRotation;
        }  //Update
Example #3
0
        protected override void OnLoad(EventArgs e)
        {
            // On  load methods to  reading shaders ,models , textures ...
            GL.ClearColor(Color4.Black);
            GL.Enable(EnableCap.DepthTest);
            Camera.Type = CameraType.FreeCam;

            mShader = new ShaderUtility(@"ACW/Shaders/vSdr.vert", @"ACW/Shaders/fLight.frag");

            mSphereModel   = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            mCubeModel     = ModelUtility.LoadModel(@"Utility/Models/MainCube.sjg");
            mCylinderModel = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");


            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int vTexCoords        = GL.GetAttribLocation(mShader.ShaderProgramID, "vTexCoords");

            int size;

            GL.UseProgram(mShader.ShaderProgramID);

            GL.GenVertexArrays(mVAO.Length, mVAO);
            GL.GenBuffers(mVBO.Length, mVBO);

            //Textures
            Txt1 = new Texture(@"ACW/Shaders/tx2.jpg", TextureUnit.Texture0);
            Txt2 = new Texture(@"ACW/Shaders/tx.jpg", TextureUnit.Texture1);

            #region Spheres
            GL.BindVertexArray(mVAO[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModel.Vertices.Length * sizeof(float)), mSphereModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModel.Indices.Length * sizeof(float)), mSphereModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion // Binds Spheres

            #region Cubes
            GL.BindVertexArray(mVAO[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[2]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCubeModel.Vertices.Length * sizeof(float)), mCubeModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[3]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCubeModel.Indices.Length * sizeof(float)), mCubeModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 8 * sizeof(float), 3 * sizeof(float));

            GL.EnableVertexAttribArray(vTexCoords);
            GL.VertexAttribPointer(vTexCoords, 2, VertexAttribPointerType.Float, true, 8 * sizeof(float), 6 * sizeof(float));
            #endregion  // Bind Cubes

            #region Cylinders
            GL.BindVertexArray(mVAO[2]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[4]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCylinderModel.Vertices.Length * sizeof(float)), mCylinderModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[5]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCylinderModel.Indices.Length * sizeof(float)), mCylinderModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion


            //Checking acctivity o gravity is on
            if (gravityAcceleration.Y == 0)
            {
                gravityOn = false;
            }
            else
            {
                gravityOn = true;
            }

            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");
            GL.UniformMatrix4(uView, true, ref mView);

            //Manages the projection for resizing the window
            int     uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
            Matrix4 projection          = Matrix4.CreatePerspectiveFieldOfView(1, (float)ClientRectangle.Width / ClientRectangle.Height, 0.5f, viewDistance);
            GL.UniformMatrix4(uProjectionLocation, true, ref projection);


            Light.Inside();
            Level.Inside();
            EmitterBox.Inside();
            SpotLight.Inside();



            GL.BindVertexArray(0);

            base.OnLoad(e);
        }
Example #4
0
        }  //Update

        protected override void OnLoad(EventArgs e)
        {
            //Init
            GL.ClearColor(Color4.Black);
            GL.Enable(EnableCap.DepthTest);

            Camera.Type = CameraType.Static;

            mShader = new ShaderUtility(@"ACW/Shaders/s.vert", @"ACW/Shaders/Light.frag");

            mSphereModel   = ModelUtility.LoadModel(@"Utility/Models/sphere.bin");
            mCubeModel     = ModelUtility.LoadModel(@"Utility/Models/MainCube.sjg");
            mCylinderModel = ModelUtility.LoadModel(@"Utility/Models/cylinder.bin");
            mParticleCube  = ModelUtility.LoadModel(@"Utility/Models/Particle_Cube.sjg");

            int vPositionLocation = GL.GetAttribLocation(mShader.ShaderProgramID, "vPosition");
            int vNormalLocation   = GL.GetAttribLocation(mShader.ShaderProgramID, "vNormal");
            int vTexCoords        = GL.GetAttribLocation(mShader.ShaderProgramID, "vTexCoords");

            int size;

            GL.UseProgram(mShader.ShaderProgramID);

            GL.GenVertexArrays(mVAO.Length, mVAO);
            GL.GenBuffers(mVBO.Length, mVBO);

            //Textures
            BrickWall = new Texture(@"ACW/Textures/BrickWall.jpg", TextureUnit.Texture0);

            //Frame buffers
            Bottom_Portal = new Frame_Buffer(TextureUnit.Texture2, FramebufferAttachment.ColorAttachment0);
            Top_Portal    = new Frame_Buffer(TextureUnit.Texture3, FramebufferAttachment.ColorAttachment0);

            #region Sphere
            GL.BindVertexArray(mVAO[0]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[0]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mSphereModel.Vertices.Length * sizeof(float)), mSphereModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mSphereModel.Indices.Length * sizeof(float)), mSphereModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mSphereModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion

            #region Cube
            GL.BindVertexArray(mVAO[1]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[2]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCubeModel.Vertices.Length * sizeof(float)), mCubeModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[3]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCubeModel.Indices.Length * sizeof(float)), mCubeModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCubeModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 8 * sizeof(float), 3 * sizeof(float));

            GL.EnableVertexAttribArray(vTexCoords);
            GL.VertexAttribPointer(vTexCoords, 2, VertexAttribPointerType.Float, true, 8 * sizeof(float), 6 * sizeof(float));
            #endregion

            #region Cylinder
            GL.BindVertexArray(mVAO[2]);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVBO[4]);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mCylinderModel.Vertices.Length * sizeof(float)), mCylinderModel.Vertices, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mVBO[5]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(mCylinderModel.Indices.Length * sizeof(float)), mCylinderModel.Indices, BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Vertices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Vertex data not loaded onto graphics card correctly");
            }

            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (mCylinderModel.Indices.Length * sizeof(float) != size)
            {
                throw new ApplicationException("Index data not loaded onto graphics card correctly");
            }

            GL.EnableVertexAttribArray(vPositionLocation);
            GL.VertexAttribPointer(vPositionLocation, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);

            GL.EnableVertexAttribArray(vNormalLocation);
            GL.VertexAttribPointer(vNormalLocation, 3, VertexAttribPointerType.Float, true, 6 * sizeof(float), 3 * sizeof(float));
            #endregion

            #region General Init
            //Checks if gravity is on
            if (gravityAcceleration.Y == 0)
            {
                gravityOn = false;
            }
            else
            {
                gravityOn = true;
            }

            int uView = GL.GetUniformLocation(mShader.ShaderProgramID, "uView");
            GL.UniformMatrix4(uView, true, ref mView);

            //Manages the projection for resizing the window
            int     uProjectionLocation = GL.GetUniformLocation(mShader.ShaderProgramID, "uProjection");
            Matrix4 projection          = Matrix4.CreatePerspectiveFieldOfView(1, (float)ClientRectangle.Width / ClientRectangle.Height, 0.5f, viewDistance);
            GL.UniformMatrix4(uProjectionLocation, true, ref projection);
            #endregion

            //---------------INIT-----------------//
            Light.Init();
            Level.Init();
            Emitter.Init();
            SpotLight.Init();

            float spawnRate = 0.01f;
            float lifetime  = 2f;
            ActiveParticleSystems.Add(new Floating_CubeSystem(mParticleCube, new Vector3(-100, -100, 100), 200, 200, 200, lifetime, spawnRate, 100, Material.white)); //1
            ActiveParticleSystems.Add(new Floating_CubeSystem(mParticleCube, new Vector3(-5, -15, 5), 10, 10, lifetime, 0.2f, 100, Material.crimson_Red));            //1
            //------------------------------------//

            GL.BindVertexArray(0);

            base.OnLoad(e);
        }