Example #1
0
        /// <summary>
        /// Updates the rotation, if dirty, for the current object and returns
        /// a status.
        /// </summary>
        /// <returns></returns>
        protected virtual bool UpdateRotation()
        {
            if (!IsRotationDirty)
            {
                return(false);
            }

            Rotation = RoxMath.Euler(0.0f, _yRotation, 0.0f)
                       * RoxMath.Euler(_xRotation, 0.0f, 0.0f)
                       * RoxMath.Euler(0.0f, 0.0f, _zRotation);

            _rotationMatrix = Rotation.Matrix4;

            _dirty &= ~DirtyFlag.Rotation;

            return(true);
        }
Example #2
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);
        });
    }
Example #3
0
 public static Vector3 ToEulerAngles(this Quaternion @this)
 {
     return(RoxMath.ToEuler(@this));
 }