OldSchoolHack

Register / Login English

Falsche World2Screen Berechnung

icon Thread: Falsche World2Screen Berechnung

Join Date: Aug 2007

Posts: 8643

User-Rating:

199 positive
33 negative
am einfachsten ist es World to Screen von der Engine zu benutzen, das passt immer. Ob man bei CSS deine Methode überhaupt anwenden kann, weiß ich nicht.

CPP Code:
  1. class Engine
  2. {
  3. public:
  4. virtual void function1() = 0;
  5. virtual void function2() = 0;
  6. virtual void function3() = 0;
  7. virtual void function4() = 0;
  8. virtual void function5() = 0;
  9. virtual void function6() = 0;
  10. virtual void function7() = 0;
  11. virtual void function8() = 0;
  12. virtual bool GetPlayerInfo(int ent_num, player_info_t *pinfo) = 0;
  13. virtual int GetPlayerForUserID(int userID) = 0;
  14. virtual void function9() = 0;
  15. virtual bool Con_IsVisible() = 0;
  16. virtual int GetLocalPlayer() = 0;
  17. virtual void function10() = 0;
  18. virtual void function11() = 0;
  19. virtual void function12() = 0;
  20. virtual void function13() = 0;
  21. virtual void function14() = 0;
  22. virtual void function15() = 0;
  23. virtual void function16() = 0;
  24. virtual void function17() = 0;
  25. virtual int GetMaxClients() = 0;
  26. virtual void function18() = 0;
  27. virtual void function19() = 0;
  28. virtual void function20() = 0;
  29. virtual void function21() = 0;
  30. virtual bool IsInGame() = 0;
  31. virtual void function22() = 0;
  32. virtual void function23() = 0;
  33. virtual void function24() = 0;
  34. virtual void function25() = 0;
  35. virtual void function26() = 0;
  36. virtual void function27() = 0;
  37. virtual void function28() = 0;
  38. virtual void function29() = 0;
  39. virtual void function30() = 0;
  40. virtual float* WorldToScreenMatrix() = 0;
  41. };
  42.  
  43. bool ScreenTransform(Vector &point, Vector &screen)
  44. {
  45. float w;
  46. float *WorldToScreen = engine->WorldToScreenMatrix(); //hier bekommste von der Engine die WorldToScreenMatrix
  47. screen.x = WorldToScreen[0] * point.x + WorldToScreen[1] * point.y + WorldToScreen[2] * point.z + WorldToScreen[3];
  48. screen.y = WorldToScreen[4] * point.x + WorldToScreen[5] * point.y + WorldToScreen[6] * point.z + WorldToScreen[7];
  49. w = WorldToScreen[12] * point.x + WorldToScreen[13] * point.y + WorldToScreen[14] * point.z + WorldToScreen[15];
  50. screen.z = 0.0f;
  51.  
  52. bool behind = false;
  53.  
  54. if (w < 0.001f)
  55. {
  56. behind = true;
  57. }
  58. else
  59. {
  60. behind = false;
  61. float invw = 1.0f / w;
  62. screen.x *= invw;
  63. screen.y *= invw;
  64. }
  65. return behind;
  66. }
  67. //---------------------------------------------------------------------------
  68. bool WorldToScreen(Vector &vOrigin, Vector &vScreen)
  69. {
  70. if (ScreenTransform(vOrigin, vScreen) == false)
  71. {
  72. int iScreenWidth = gui.Viewport.Width, iScreenHeight = gui.Viewport.Height;
  73.  
  74. float x = iScreenWidth / 2;
  75. float y = iScreenHeight / 2;
  76. x += 0.5 * vScreen.x * iScreenWidth + 0.5;
  77. y -= 0.5 * vScreen.y * iScreenHeight + 0.5;
  78. vScreen.x = x;
  79. vScreen.y = y;
  80. return true;
  81. }
  82. return false;
  83. }

greetz KN4CK3R

__________________

Hallo