Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool WorldToScreen(Vector3D World, float *ScreenX, float *ScreenY)
- {
- //Get the enemy position
- Vector3D Position = VectorSubtract(World, RefDef->Origin);
- Vector3D Transform;
- //Get the Dot Products from the View Angles of the player
- Transform.x = DotProduct(Position, RefDef->viewAxis[1]);
- Transform.y = DotProduct(Position, RefDef->viewAxis[2]);
- Transform.z = DotProduct(Position, RefDef->viewAxis[0]);
- //Make sure the enemy is in front of the player. If not, return.
- if (Transform.z < 0.1f)
- return false;
- //Calculate the center of the screen
- Vector2D Center = Vector2D((float)RefDef->Width * 0.5f, (float)RefDef->Height * 0.5f);
- //Calculates the screen coordinates
- *ScreenX = Center.x * (1 - (Transform.x / RefDef->fov.x / Transform.z));
- *ScreenY = Center.y * (1 - (Transform.y / RefDef->fov.y / Transform.z));
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement