Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Pi 3.14159265358979323846264338327950288
- bool WorldToScreen (vector ObjectPoint, vector CameraPoint, vector CameraAngle, vector AOV, vector Resolution, vector Screen)
- {
- vector Location, AngleA, Angle, ViewAngle, FOV;
- Location.x = ObjectPoint.x - CameraPoint.x;
- Location.y = ObjectPoint.y - CameraPoint.y;
- float Distance = sqrt((Location.x * Location.x) + (Location.y * Location.y));
- if (ObjectPoint.x > CameraPoint.x && ObjectPoint.y > CameraPoint.y)
- {
- Location.x = ObjectPoint.x - CameraPoint.x;
- Location.y = ObjectPoint.y - CameraPoint.y;
- AngleA.x = atan(Location.y / Location.x) * (Pi / 180);
- Angle.x = AngleA.x - AngleB.x;
- ViewAngle.x = cos(Angle.x) * Distance;
- FOV.x = tan(AOV.x / 2) * ViewAngle.x;
- Screen.x = (Resolution.x / 2) + (ViewAngle.x / FOV.x) * (Resolution.x / 2);
- }
- else if (ObjectPoint.x < CameraPoint.x && ObjectPoint.y > CameraPoint.y)
- {
- Location.x = CameraPoint.x - ObjectPoint.x;
- Location.y = ObjectPoint.y - CameraPoint.y;
- AngleA.x = 180 - (atan(Location.y / Location.x) * (Pi / 180));
- Angle.x = AngleB.x - AngleA.x;
- ViewAngle.x = cos(Angle.x) * Distance;
- FOV.x = tan(AOV.x / 2) * ViewAngle.x;
- Screen.x = (Resolution.x / 2) - (ViewAngle.x / FOV.x) * (Resolution.x / 2);
- }
- else if (ObjectPoint.x < CameraPoint.x && ObjectPoint.y < CameraPoint.y)
- {
- Location.x = CameraPoint.x - ObjectPoint.x;
- Location.y = CameraPoint.y - ObjectPoint.y;
- AngleA.x = 180 + (atan(Location.y / Location.x) * (Pi / 180);
- Angle.x = AngleB.x - AngleA.x;
- ViewAngle.x = cos(Angle.x) * Distance;
- FOV.x = tan(AOV.x / 2) * ViewAngle.x;
- Screen.x = (Resolution.x / 2) - (ViewAngle.x / FOV.x) * (Resolution.x / 2);
- }
- else if (ObjectPoint.x > CameraPoint.x && ObjectPoint.y < CameraPoint.y)
- {
- Location.x = ObjectPoint.x - CameraPoint.x;
- Location.y = CameraPoint.y - ObjectPoint.y;
- AngleA.x = 360 - (atan(Location.y / Location.x) * (Pi / 180);
- Angle.x = AngleA.x - AngleB.x;
- ViewAngle.x = cos(Angle.x) * Distance;
- FOV.x = tan(AOV.x / 2) * ViewAngle.x;
- Screen.x = (Resolution.x / 2) + (ViewAngle.x / FOV.x) * (Resolution.x / 2);
- }
- Location.x = ObjectPoint.x - CameraPoint.x;
- Location.y = ObjectPoint.y - CameraPoint.y;
- Distance = sqrt((Location.x * Location.x) + (Location.y * Location.y));
- if (ObjectPoint.z > CameraPoint.z)
- {
- Location.z = ObjectPoint.z - CameraPoint.z;
- AngleA.y = atan(Location.z / Distance) * (Pi / 180);
- Angle.y = AngleA.y - AngleB.y;
- ViewAngle.y = sin(Angle.y) * Distance;
- FOV.y = tan(AOV.y / 2) * ViewAngle.y;
- Screen.y = (Resolution.y / 2) + (ViewAngle.y / FOV.y) * (Resolution.y / 2);
- }
- else if (ObjectPoint.z < CameraPoint.z)
- {
- Location.z = CameraPoint.z - ObjectPoint.z;
- AngleA.y = atan(Location.z / Distance) * (Pi / 180);
- Angle.y = AngleB.y - AngleA.y;
- ViewAngle.y = sin(Angle.y) * Distance;
- FOV.y = tan(AOV.y / 2) * ViewAngle.y;
- Screen.y = (Resolution.y / 2) - (ViewAngle.y / FOV.y) * (Resolution.y / 2);
- }
- else if (ObjectPoint.z == CameraPoint.z)
- {
- AngleA.y = 0.0;
- Screen.y = (Resolution.y / 2);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement