Advertisement
dcomicboy

W2S Halo

Jul 22nd, 2012
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. vect3 CCamera::WorldToScreen(vect3 coord)//i do this vect3 vWorldToScreen(vect3 coord)
  2. {
  3. float Y_fov = aCamera->Fov / aspect_ratio;//then lose the aspect_ratio cuz its in the class
  4. vect3 cam_to_obj(coord.x - aCamera->vWorld.x, coord.y - aCamera->vWorld.y, coord.z - aCamera->vWorld.z);
  5. float dist_to_obj = sqrt(cam_to_obj.x*cam_to_obj.x + cam_to_obj.y*cam_to_obj.y + cam_to_obj.z*cam_to_obj.z);
  6. D3DXVec3Normalize(&cam_to_obj, &cam_to_obj);
  7.  
  8. // All angles are in radians, -PI<angle<PI, and no i dont know which could be equal to. but who cares - it's a float so it's impossible.
  9. float cam_yaw = atan2f(aCamera->vLookAt.y, aCamera->vLookAt.x);
  10. float obj_yaw = atan2f(cam_to_obj.y, cam_to_obj.x);
  11.  
  12. // Relative(to cam) yaw ends up from -2 PI < yaw < 2 PI, but we want it from -PI<yaw<PI
  13. float relative_yaw = obj_yaw - cam_yaw;
  14. if(relative_yaw > D3DX_PI) // yaw>180 degrees. convert to negative, smaller.
  15. relative_yaw -= 2*D3DX_PI;
  16. if(relative_yaw < -D3DX_PI)
  17. relative_yaw += 2*D3DX_PI;
  18. // [/Difference]
  19.  
  20. float obj_pitch = asin(cam_to_obj.z);
  21. float cam_pitch = asin(aCamera->vLookAt.z);
  22.  
  23. float relative_pitch = cam_pitch - obj_pitch;
  24. float x_pos = -relative_yaw * 2 / aCamera->Fov; // radian angle measurement cancels here.
  25. float y_pos = relative_pitch * 2 / Y_fov; // and that's the (relative pitch) / (fov / 2)
  26.  
  27. x_pos = (x_pos + 1) / 2; // Lastly, change from range (-1,1) to (0,1) Also, it CAN be outside of that range - if it's outside of the FOV.
  28. y_pos = (y_pos + 1) / 2;
  29.  
  30. vect3 onscreen(x_pos, y_pos, dist_to_obj); //you have working camera struct? its here
  31. return onscreen;
  32. }
  33.  
  34.  
  35. way hack is used
  36.  
  37. if(opt.hacks.test1)
  38. {
  39. for(unsigned short i = 0; i < StaticPlayerHeader->SlotsTaken; i++)
  40. {
  41. if(GetLocalPlayer(Local->PlayerIndex))
  42. {
  43. if(GetPlayerByIndex(i))
  44. {
  45. if(LocalPlayer->Team == StaticPlayer->Team)
  46. continue;
  47.  
  48. //if(!Masterchief)
  49. // continue;
  50.  
  51. D3DXVECTOR3 HeadPos, Head2DPos;
  52. HeadPos.x = Masterchief->Head[10] - aCamera->vWorld[0];
  53. HeadPos.y = Masterchief->Head[11] - aCamera->vWorld[1];
  54. HeadPos.z = Masterchief->Head[12] - aCamera->vWorld[2];
  55.  
  56. if(Head2DPos = vWorldToScreen(HeadPos))
  57. {
  58. char strPlayerName[12];
  59. wcstombs(strPlayerName, StaticPlayer->PlayerName1, wcslen(StaticPlayer->PlayerName1)+1);
  60.  
  61.  
  62. Menu.font->DrawTextA(Head2DPos.x, Head2DPos.y, D3DCOLOR_ARGB(255,255,255,255), strPlayerName, DT_CENTER|DT_SHADOW);
  63.  
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement