Advertisement
thebigbum

Untitled

Mar 1st, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. bool WorldToScreen(Vector3D World, float *ScreenX, float *ScreenY)
  2. {
  3. //Get the enemy position
  4. Vector3D Position = VectorSubtract(World, RefDef->Origin);
  5. Vector3D Transform;
  6.  
  7. //Get the Dot Products from the View Angles of the player
  8. Transform.x = DotProduct(Position, RefDef->viewAxis[1]);
  9. Transform.y = DotProduct(Position, RefDef->viewAxis[2]);
  10. Transform.z = DotProduct(Position, RefDef->viewAxis[0]);
  11.  
  12. //Make sure the enemy is in front of the player. If not, return.
  13. if (Transform.z < 0.1f)
  14. return false;
  15.  
  16. //Calculate the center of the screen
  17. Vector2D Center = Vector2D((float)RefDef->Width * 0.5f, (float)RefDef->Height * 0.5f);
  18.  
  19. //Calculates the screen coordinates
  20. *ScreenX = Center.x * (1 - (Transform.x / RefDef->fov.x / Transform.z));
  21. *ScreenY = Center.y * (1 - (Transform.y / RefDef->fov.y / Transform.z));
  22.  
  23. return true;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement