示例#1
0
        /// <summary>
        /// Nastavi, zda bude ci nebude videt hrac a vse s nim spojene
        /// </summary>
        /// <param name="enable">True - hrac bude videt, jinak false</param>
        public static void SetShowPlayer(bool enable)
        {
            showPlayer = enable;

            SceneManager sceneManager = GraphicCore.GetCurrentSceneManager();

            if (enable)
            {
                Camera  cam      = Camera.GetCameraInstance();
                Vector3 position = cam.GetVector3Position();
                Vector3 dir      = cam.GetVector3LookAt() - position;
                dir.Normalize();

                Scene.SceneManager.SceneObject pl = sceneManager.GetObject("Hrac");

                if (pl != null)
                {
                    player = (Objects.Player)pl.generalObject;

                    if ((Scene.SceneManager.DetailLevel)Properties.Settings.Default.DetailLevel == Scene.SceneManager.DetailLevel.Low)
                    {
                        player.SetModel(null);
                    }
                }
                else
                {
                    sceneManager.AddObject("Hrac", player, (Effect)null);
                }

                Vector3 playerPosition = position;
                playerPosition.Y -= HeightOfEye.Y;
                playerPosition   -= HeightOfEye.Z * dir;
                player.SetPosition(playerPosition);

                SceneManager.SceneObject pochoden = sceneManager.GetObject("Hrac_Pochoden");

                if (pochoden != null)
                {
                    player.EquipItem(pochoden.generalObject);
                }
            }
            else
            {
                if (player != null)
                {
                    player.SetMatrixWorld(originalPlayerWorld);
                    sceneManager.DeleteObject("Hrac");
                }
            }
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }