Esempio n. 1
0
    private void InitInput()
    {
        Input.Subscribe('w', new Event(state => _forwardDown = state));
        Input.Subscribe('a', new Event(state => _leftDown    = state));
        Input.Subscribe('s', new Event(state => _backDown    = state));
        Input.Subscribe('d', new Event(state => _rightDown   = state));
        Input.Subscribe('q', new Event(state => _upDown      = state));
        Input.Subscribe('e', new Event(state => _downDown    = state));

        RelativeMouse.Enabled = true;

        const float SpeedReduction = 5.0f;
        const float ClampY         = 89.0f * RoxMath.ToRadians;

        // Relative mouse movement handler (Mouse lock enabled)
        RelativeMouse.AddListener((x, y) => {
            // Aggregate x and y values -- Hard Constraint on +Y axis
            _mouseX = _mouseX + (x / SpeedReduction);
            _mouseY = RoxMath.Min(_mouseY + (y / SpeedReduction), _viewport.Height - 1.0f);

            // Pull any out of bounds coordinates back into window coordinates
            _mouseX = (_mouseX % _viewport.Width);
            _mouseY = (_mouseY % _viewport.Height);

            // Map to Window ratio
            _lookRotation.X = (_mouseX / _viewport.Width) * RoxMath.TwoPi;
            _lookRotation.Y = (_mouseY / _viewport.Height) * RoxMath.Pi;

            // Constrain to:
            //   (-360, 360) for x-axis
            //   (-89, 89) for y-axis
            _lookRotation.X = RoxMath.Clamp(_lookRotation.X, RoxMath.TwoPi);
            _lookRotation.Y = RoxMath.Clamp(_lookRotation.Y, ClampY);
        });

        // TBD: Voxel modification
        Window.OnMouseCallbacks.Add((b, s, x, y) => {
            Console.WriteLine($"button: {b}, state: {s}, x: {x}, y: {y}");
            return(true);
        });
    }
Esempio n. 2
0
    public void Run()
    {
        // handle events and render the frame
        while (Window.Open)
        {
            _fps.Tick();

            Window.HandleEvents();
            RelativeMouse.HandleEvents();

            if (!IsElapsedFrame())
            {
                continue;
            }
            _fps.Frame();

            UpdateScene();

            _renderer.Clear();
            _blockTexture.Use();

            foreach (var axis in _axis)
            {
                var renderable = (OpenGLRenderable)axis.Renderable;
                var shader     = renderable.Geometry.Program;
                shader.Use();
                shader["Color"].SetValue(axis.Color);

                _renderer.Render(_mainCamera, renderable);
            }

            _renderer.Render(_mainCamera, _chunkMeshes);

            //_renderer.Render(_mainCamera, _cube);

            //UserInterface.Draw();
            SwapBuffers();
        }
    }