Пример #1
0
        /// <summary>
        /// Presune hrace na startovani pozici (0,0,0)
        /// </summary>
        public static void MoveToStartPosition()
        {
            Vector3 pos = new Vector3(-3000, 0, -3000);

            pos += HeightOfEye;

            Camera cam = Camera.GetCameraInstance();

            Vector3 dir = cam.GetVector3LookAt() - cam.GetVector3Position();

            dir.Y = 0;

            RepairPositionInNonFreeLook(pos, ref pos);

            //if (freeLook)
            //  pos += new Vector3(0, 1800, 0);

            cam.SetCameraPositionVector(pos);
            cam.SetCameraLookAtVector(pos + dir);
        }
Пример #2
0
        /// <summary>
        /// Necha hrace rozhlizet se
        /// </summary>
        /// <param name="x">Vychyleni v horizontalnim smeru</param>
        /// <param name="y">Vychyleni ve vertikalnim smeru</param>
        public static void LookAround(float x, float y)
        {
            Camera cam = Camera.GetCameraInstance();

            Vector3 lookat   = cam.GetVector3LookAt();
            Vector3 position = cam.GetVector3Position();


            Vector3 dir = lookat - position;

            dir.Normalize();

            Vector3 ndir = Vector3.Cross(dir, cam.GetVector3Up());

            ndir.Normalize();

            Vector3 undir = Vector3.Cross(dir, ndir);

            undir.Normalize();

            float invert = 1;

            if (invertedmouse)
            {
                invert *= -1;
            }

            Vector3 dx = -(Sensitivity / 2000f) * x * ndir;
            Vector3 dy = invert * (Sensitivity / 2000f) * y * undir;

            Vector3 newLookAt = lookat;

            newLookAt = newLookAt + dx;
            newLookAt = newLookAt + dy;

            Vector3 newdir = newLookAt - position;

            newdir.Normalize();

            lookat = position + newdir;

            if (newdir.Y > -0.9999f && newdir.Y < 0.9999f)
            {
                cam.SetCameraLookAtVector(lookat);
            }

            if (player == null)
            {
                return;
            }

            newdir   = cam.GetVector3LookAt() - cam.GetVector3Position();
            newdir.Y = 0;
            newdir.Normalize();

            Vector3 positionPlayer = cam.GetVector3Position();

            positionPlayer.Y -= HeightOfEye.Y;
            positionPlayer   -= HeightOfEye.Z * newdir;

            player.SetPosition(positionPlayer);
            player.SetDirection(newdir);
        }
Пример #3
0
        /// <summary>
        /// Pohne s hracem o jeden krok ve smeru zadaneho uhlu
        /// </summary>
        /// <param name="angle">Uhel v radianech urcujici smer pohybu</param>
        public static void MoveByAngle(float angle)
        {
            Camera cam = Camera.GetCameraInstance();

            Vector3 lookat   = cam.GetVector3LookAt();
            Vector3 position = cam.GetVector3Position();

            Matrix  rotation = Matrix.RotationY(angle);
            Vector3 dir      = lookat - position;

            if (freeLook)
            {
                dir.Normalize();
                dir.TransformCoordinate(rotation);
                dir.Normalize();

                if (Math.Abs(angle - Math.PI) < 0.5)
                {
                    dir.Y = -dir.Y;
                }
                else if (Math.Abs(angle - Math.PI / 2f) < 0.5 || Math.Abs(angle - Math.PI / 2f + Math.PI) < 0.5)
                {
                    dir.Y = 0;
                }

                Vector3 newposition = position + (Speed * time) * dir;
                Vector3 newlookAt   = lookat + (Speed * time) * dir;

                cam.SetCameraLookAtVector(newlookAt);
                cam.SetCameraPositionVector(newposition);
                return;
            }


            dir.Y = 0;
            dir.Normalize();

            dir.TransformCoordinate(rotation);
            dir.Normalize();

            Vector3 newPosition = position + (Speed * time) * dir;

            RepairPositionInNonFreeLook(position, ref newPosition);

            if (position == newPosition)
            {
                return;
            }

            Vector3 newLookAt = lookat + newPosition - position;

            cam.SetCameraLookAtVector(newLookAt);
            cam.SetCameraPositionVector(newPosition);

            if (player == null)
            {
                return;
            }

            dir   = newLookAt - newPosition;
            dir.Y = 0;
            dir.Normalize();

            Vector3 playerPosition = newPosition;

            playerPosition.Y -= HeightOfEye.Y;
            playerPosition   -= HeightOfEye.Z * dir;

            player.SetPosition(playerPosition);
        }