Ejemplo n.º 1
0
        public static bool ColorEdit3(string label, ref Color color)
        {
            var value = color.ToVector3();
            var ret   = ImGui.ColorEdit3(label, ref value);

            color = Color.FromVector3(value);
            return(ret);
        }
Ejemplo n.º 2
0
        public override void Render(float time, float deltaTime)
        {
            _viewMatrix       = Matrix4x4.CreateLookAt(_cameraPosition, _cameraTarget, Vector3Helper.Up);
            _modelMatrix      = Matrix4x4.CreateRotationY(0f * 3f);
            _projectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView(1.0f, Window.AspectRatio, 0.1f, 10_000.0f);

            _shader.SetUniform("model", ref _modelMatrix);
            _shader.SetUniform("view", ref _viewMatrix);
            _shader.SetUniform("projection", ref _projectionMatrix);

            _shader.TrySetUniform("lightPos", _lightPos);
            _shader.TrySetUniform("lightColor", _lightColor.ToVector3());
            _shader.TrySetUniform("cameraPos", _cameraPosition);

            RenderContext.Clear(Color.Black);

            if (_skybox0 != null)
            {
                var viewMatrixNoTranslation = _viewMatrix;
                viewMatrixNoTranslation.Translation = Vector3.Zero;

                _skyboxShader.SetUniform("view", ref viewMatrixNoTranslation);
                _skyboxShader.SetUniform("projection", ref _projectionMatrix);
                _skyboxShader.SetUniform("skybox", 0);

                _skybox0.Bind(0, RenderContext);
                RenderContext.DepthMask = false;
                _skyboxMesh.Render(RenderContext, _skyboxShader);
                RenderContext.DepthMask = true;
            }

            if (_nanosuit != null)
            {
                RenderContext.Render(_nanosuit, _shader);
            }

            _shader.SetUniform("model", Matrix4x4.CreateTranslation(_lightPos));

            _mesh.Render(RenderContext, _shader);

            ImGuiHelper.BeginGlobalDocking(false);
            ImGui.End();

            ImGui.Begin("Controls");
            {
                ImGui.DragFloat3("Camera Position", ref _cameraPosition);
                ImGui.DragFloat3("Camera Target", ref _cameraTarget);

                ImGui.Separator();

                ImGuiHelper.ColorEdit4("Light Color", ref _lightColor);
                ImGui.DragFloat3("Light Position", ref _lightPos);
            }
            ImGui.End();

            if (ImGui.Button("Quit"))
            {
                Quit();
            }

            ImGui.Separator();

            if (Window.VSync == VSyncMode.On)
            {
                if (ImGui.Button("Disable VSync"))
                {
                    Window.VSync = VSyncMode.Off;
                    _log.Info("VSync disabled.");
                }
            }
            else
            {
                if (ImGui.Button("Enable VSync"))
                {
                    Window.VSync = VSyncMode.On;
                    _log.Info("VSync enabled.");
                }
            }

            if (ImGui.Button("Set Fullscreen"))
            {
                Window.FullscreenState = FullscreenState.Fullscreen;
            }

            if (ImGui.Button("Set Windowed"))
            {
                Window.FullscreenState = FullscreenState.Windowed;
            }

            ImGui.End();

            ImGui.ShowMetricsWindow();
        }