Esempio n. 1
0
        private bool WorldToScreen(Vector3 worldLocation, PlayerCameraManager cameraManager, out Vector2 screenlocation)
        {
            screenlocation = new Vector2(0, 0);

            var pov      = cameraManager.CameraCache.POV;
            var rotation = pov.Rotation;

            rotation.GetAxes(out var vAxisX, out var vAxisY, out var vAxisZ);

            var vDelta       = worldLocation - pov.Location;
            var vTransformed = new Vector3(Vector3.DotProduct(vDelta, vAxisY), Vector3.DotProduct(vDelta, vAxisZ), Vector3.DotProduct(vDelta, vAxisX));

            if (vTransformed.Z < 1f)
            {
                vTransformed.Z = 1f;
            }

            var fovAngle      = pov.Fov;
            var screenCenterX = Setting.Screen.Width / 2;
            var screenCenterY = Setting.Screen.Height / 2;

            screenlocation.X = screenCenterX + vTransformed.X * (screenCenterX / (float)Math.Tan(fovAngle * (float)Math.PI / 360)) / vTransformed.Z;
            screenlocation.Y = screenCenterY - vTransformed.Y * (screenCenterX / (float)Math.Tan(fovAngle * (float)Math.PI / 360)) / vTransformed.Z;

            //超出屏幕边界返回false
            return(!(screenlocation.X > Setting.Screen.Width | screenlocation.Y > Setting.Screen.Height));
        }
Esempio n. 2
0
        private bool WorldToScreen(Vector3 WorldLocation, PlayerCameraManager CameraManager, out Vector2 Screenlocation)
        {
            Screenlocation = new Vector2(0, 0);

            var      POV      = CameraManager.CameraCache.POV;
            FRotator Rotation = POV.Rotation;

            Vector3 vAxisX, vAxisY, vAxisZ;

            Rotation.GetAxes(out vAxisX, out vAxisY, out vAxisZ);

            Vector3 vDelta       = WorldLocation - POV.Location;
            Vector3 vTransformed = new Vector3(Vector3.DotProduct(vDelta, vAxisY), Vector3.DotProduct(vDelta, vAxisZ), Vector3.DotProduct(vDelta, vAxisX));

            if (vTransformed.Z < 1f)
            {
                vTransformed.Z = 1f;
            }

            float FovAngle      = POV.Fov;
            float ScreenCenterX = 2560 / 2;
            float ScreenCenterY = 1440 / 2;

            Screenlocation.X = ScreenCenterX + vTransformed.X * (ScreenCenterX / (float)Math.Tan(FovAngle * (float)Math.PI / 360)) / vTransformed.Z;
            Screenlocation.Y = ScreenCenterY - vTransformed.Y * (ScreenCenterX / (float)Math.Tan(FovAngle * (float)Math.PI / 360)) / vTransformed.Z;

            return(true);
        }