Example #1
0
        protected override void OnRender(double dt)
        {
            inputManager.Update((float)dt);

            graphicsDevice.ShaderProgram = shaderProgram;
            viewUniform.SetValueMat4(inputManager.CalculateViewMatrixNoTranslation());
            graphicsDevice.VertexArray = vertexBuffer;
            graphicsDevice.DrawArrays(PrimitiveType.TriangleStrip, 0, vertexBuffer.StorageLength);
        }
Example #2
0
        protected override void OnRender(double dt)
        {
            float time = (float)stopwatch.Elapsed.TotalSeconds;

            inputManager.Update((float)dt);

            if ((inputManager.CurrentMouse != null && inputManager.CurrentMouse.IsButtonPressed(MouseButton.Right)) ||
                (inputManager.CurrentGamepad != null && inputManager.CurrentGamepad.RightBumper().Pressed))
            {
                lampPosition = inputManager.CameraPosition + 2.5f * inputManager.CalculateForwardVector();
                modelsProgram.PositionalLights[0].Position = lampPosition;
                lampProgram.World = Matrix4x4.CreateScale(0.015f) * Matrix4x4.CreateTranslation(lampPosition.X, lampPosition.Y - 0.85f, lampPosition.Z);
            }

            graphicsDevice.FaceCullingEnabled  = false;
            graphicsDevice.DepthTestingEnabled = false;
            graphicsDevice.ShaderProgram       = skyProgram;
            graphicsDevice.VertexArray         = cubeBuffer;
            skyProgram.Uniforms["View"].SetValueMat4(inputManager.CalculateViewMatrixNoTranslation());
            skyProgram.Uniforms["time"].SetValueFloat(time);
            graphicsDevice.DrawArrays(PrimitiveType.TriangleStrip, 0, cubeBuffer.StorageLength);

            graphicsDevice.DepthTestingEnabled = true;
            graphicsDevice.Clear(ClearBuffers.Depth);

            Matrix4x4 view = inputManager.CalculateViewMatrix();

            linesProgram.View  = view;
            modelsProgram.View = view;
            lampProgram.View   = view;

            graphicsDevice.VertexArray   = linesBuffer;
            graphicsDevice.ShaderProgram = linesProgram;
            linesProgram.World           = Matrix4x4.Identity;
            graphicsDevice.DrawArrays(PrimitiveType.Lines, 0, linesBuffer.StorageLength);



            graphicsDevice.FaceCullingEnabled = true;
            graphicsDevice.ShaderProgram      = modelsProgram;

            graphicsDevice.VertexArray = dragonBuffer;
            modelsProgram.World        = Matrix4x4.CreateScale(0.33f) * Matrix4x4.CreateRotationY(time * 0.1f * MathF.PI) * Matrix4x4.CreateTranslation(-1, 0.5f, -2);
            graphicsDevice.DrawArrays(PrimitiveType.Triangles, 0, dragonBuffer.StorageLength);

            graphicsDevice.VertexArray = donutBuffer;
            modelsProgram.World        = Matrix4x4.CreateScale(0.7f) * Matrix4x4.CreateTranslation(2, 0, 2);
            graphicsDevice.DrawArrays(PrimitiveType.Triangles, 0, donutBuffer.StorageLength);

            graphicsDevice.VertexArray = sphereBuffer;
            modelsProgram.World        = Matrix4x4.CreateScale(1.2f) * Matrix4x4.CreateTranslation(4, 2, -5);
            graphicsDevice.DrawArrays(PrimitiveType.Triangles, 0, sphereBuffer.StorageLength);

            graphicsDevice.VertexArray   = lampBuffer;
            graphicsDevice.ShaderProgram = lampProgram;
            graphicsDevice.DrawArrays(PrimitiveType.Triangles, 0, lampBuffer.StorageLength);

            graphicsDevice.DepthTestingEnabled = false;
            graphicsDevice.ShaderProgram       = linesProgram;
            graphicsDevice.VertexArray         = crossBuffer;
            Vector3 translation = inputManager.CameraPosition + inputManager.CalculateForwardVector();

            linesProgram.World = Matrix4x4.CreateScale(0.1f) * Matrix4x4.CreateTranslation(translation);
            graphicsDevice.DrawArrays(PrimitiveType.Lines, 0, crossBuffer.StorageLength);
        }