Beispiel #1
0
        public FCameraCacheEntry CameraCache; //0x03C0

        public bool WorldToScreen(Vector3 WorldLocation, Vector2 screenSize, out Vector2 Screenlocation)
        {
            Screenlocation = new Vector2(0, 0);

            var     POV      = CameraCache.POV;
            Rotator 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.Dot(vDelta, vAxisY), Vector3.Dot(vDelta, vAxisZ), Vector3.Dot(vDelta, vAxisX));

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

            float FovAngle      = POV.FOV;
            float ScreenCenterX = screenSize.X / 2;
            float ScreenCenterY = screenSize.Y / 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;

            if (Screenlocation.X <= (int)screenSize.X + 50 && Screenlocation.X >= -0 && Screenlocation.Y <= (screenSize.Y) && Screenlocation.Y >= 0)
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public Vector2 WorldToScreen(Vector3 WorldLocation, Vector2 screenSize)
        {
            Vector2 Screenlocation;

            Screenlocation = new Vector2(0, 0);

            FMinimalViewInfo POV      = CameraCache.POV;
            Rotator          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.Dot(vDelta, vAxisY), Vector3.Dot(vDelta, vAxisZ), Vector3.Dot(vDelta, vAxisX));

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

            float FovAngle      = POV.FOV;
            float ScreenCenterX = screenSize.X / 2;
            float ScreenCenterY = screenSize.Y / 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(Screenlocation);
        }