Пример #1
0
        private void UpdateInput()
        {
            float speed = 2.5f * Time.deltaTime;

            if (Key.W.IsPressed())
            {
                this.position -= front * speed;
            }
            if (Key.S.IsPressed())
            {
                this.position += front * speed;
            }
            if (Key.A.IsPressed())
            {
                this.position += front.Cross(up).Normalize() * speed;
            }
            if (Key.D.IsPressed())
            {
                this.position -= front.Cross(up).Normalize() * speed;
            }
            if (Key.E.IsPressed())
            {
                this.position += up * speed;
            }
            if (Key.Q.IsPressed())
            {
                this.position -= up * speed;
            }

            var mouseNow   = Input.mousePos;
            var mouseDelta = mouseNow - lastMousePos;

            this.lastMousePos = mouseNow;

            if (firstMouseDelta)
            {
                firstMouseDelta = false;
                return;
            }

            mouseDelta *= 0.1f; //sensitivity

            this.euler += mouseDelta;
            if (this.euler.y > 89.0)
            {
                this.euler.y = 89.0f;
            }
            if (this.euler.y < -89.0)
            {
                this.euler.y = -89.0f;
            }

            this.front.x = (float)Math.Cos(MathV.Radians(euler.x)) * (float)Math.Cos(MathV.Radians(euler.y));
            this.front.y = (float)Math.Sin(MathV.Radians(euler.y));
            this.front.z = (float)Math.Sin(MathV.Radians(euler.x)) * (float)Math.Cos(MathV.Radians(euler.y));

            this.front = this.front.Normalize();
        }
Пример #2
0
 public float Yaw()
 {
     return(MathF.Asin(MathV.Clamp(-2.0f * (x * z - w * y), -1.0f, 1.0f)));
 }