Exemplo n.º 1
0
        private Vector3 DoCameraPosition(Vector2 m)
        {
            _currentCameraRotationDegrees.X += m.X * 40;
            _currentCameraRotationDegrees.Y += m.Y * 40;
            if (_currentCameraRotationDegrees.Y < -75)
            {
                _currentCameraRotationDegrees.Y = -75;
            }
            if (_currentCameraRotationDegrees.Y > 5)
            {
                _currentCameraRotationDegrees.Y = 5;
            }

            float lav_factor  = (0.00012f * (_currentCameraRotationDegrees.Y * _currentCameraRotationDegrees.Y) + 0.02099f * _currentCameraRotationDegrees.Y + 0.89190f);
            float lav_factor2 = _currentCameraRotationDegrees.Y >= -15 ? (_currentCameraRotationDegrees.Y + 15) / 20f : 0f;

            Vector3 offset1       = HelperRotation.RotateVector(GetLookAtVector(), -90, Plane.Y) * 1 + GetLookAtVector() * 5 * lav_factor;
            Vector3 offset2       = HelperRotation.RotateVector(GetLookAtVector(), -90, Plane.Y) * 1 + GetLookAtVector() * 2 + _offsetVertical * 2 * lav_factor2;
            Vector3 arcBallCenter = new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z);

            Vector3 newCamPos = HelperRotation.CalculateRotationForArcBallCamera(
                arcBallCenter,
                10f,
                _currentCameraRotationDegrees.X,
                _currentCameraRotationDegrees.Y,
                false,
                false);

            CurrentWorld.SetCameraPosition(newCamPos + offset1);
            CurrentWorld.SetCameraTarget(new Vector3(Position.X, GetCenterPointForAllHitboxes().Y, Position.Z) + offset2);

            return(offset2);
        }
Exemplo n.º 2
0
        public override void Act(KeyboardState ks, MouseState ms, float deltaTimeFactor)
        {
            bool runs = false;

            if (CurrentWorld.IsFirstPersonMode && CurrentWorld.GetFirstPersonObject().Equals(this))
            {
                float forward = 0;
                float strafe  = 0;
                if (ks[Key.A])
                {
                    strafe -= 1;
                    runs    = true;
                }
                if (ks[Key.D])
                {
                    strafe += 1;
                    runs    = true;
                }
                if (ks[Key.W])
                {
                    forward += 1;
                    runs     = true;
                }
                if (ks[Key.S])
                {
                    forward -= 1;
                    runs     = true;
                }
                MoveFPSCamera(ms);
                MoveAndStrafeFirstPerson(forward, strafe, 0.1f * deltaTimeFactor);
                FPSEyeOffset = 5;
                if (ks[Key.Q])
                {
                    MoveOffset(0, -0.2f, 0);
                }
                if (ks[Key.E])
                {
                    MoveOffset(0, +0.2f, 0);
                }
            }
            else
            {
                TurnTowardsXZ(GetMouseIntersectionPoint(ms, Plane.Y));
                Vector3 cameraLookAt = GetCameraLookAtVector();
                cameraLookAt.Y = 0;
                cameraLookAt.NormalizeFast();

                Vector3 strafe = HelperRotation.RotateVector(cameraLookAt, 90, Plane.Y);

                if (ks[Key.A])
                {
                    MoveAlongVector(strafe, 0.1f * deltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.D])
                {
                    MoveAlongVector(strafe, -0.1f * deltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.W])
                {
                    MoveAlongVector(cameraLookAt, 0.1f * deltaTimeFactor);
                    runs = true;
                }
                if (ks[Key.S])
                {
                    MoveAlongVector(cameraLookAt, -0.1f * deltaTimeFactor);
                    runs = true;
                }

                if (ks[Key.T])
                {
                    MoveOffset(0, 0.2f * deltaTimeFactor, 0);
                }

                if (ks[Key.Q])
                {
                    _height += 0.5f;
                }
                if (ks[Key.E])
                {
                    _height -= 0.5f;
                }
            }

            if (IsMouseCursorInsideMyHitbox(ms))
            {
                SetColorOutline(0, 1, 0, 0.2f);
            }
            else
            {
                SetColorOutline(0, 1, 0, 0);
            }

            /*
             * if (ms.LeftButton == ButtonState.Pressed)
             * {
             *  GameObject o = PickGameObject(ms);
             *  Console.WriteLine(o);
             * }
             */

            MoveOffset(0, -0.1f * deltaTimeFactor, 0);
            List <Intersection> intersections = GetIntersections();

            foreach (Intersection i in intersections)
            {
                if (i.IsTerrain)
                {
                    SetPosition(Position.X, i.HeightOnTerrainSuggested, Position.Z);
                }
                else
                {
                    Position += i.MTV;
                }
            }

            AdjustFlashlight();
            AdjustAnimation(runs, deltaTimeFactor);

            Vector3 camPos = this.Position + new Vector3(50, _height, 50);

            camPos.Y = _height;
            CurrentWorld.SetCameraPosition(camPos);
            CurrentWorld.SetCameraTarget(Position.X, 0, Position.Z);
        }