Advertisement
Guest User

Untitled

a guest
Feb 4th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. //globals:
  2. static float fWidth, fHeight, fHWidth, fHHeight;
  3. static float fFovMod;
  4. static Vector3 v3View, v3Right, v3Up, v3Forward;
  5.  
  6. static public Memory.Matrix viewProj { get { return Memory.ReadMatrix(Mem.p, Memory.ReadPtr<IntPtr>(Mem.p, (long)Offsets.PlayerManagerPtr, new int[] { Offsets.PlayerManager.LocalPlayer, Offsets.Player.Camera, Offsets.Camera.Matrix })); } }
  7. //call this function only after a resolution has changed...
  8. public static void W2S_initonce(int dwWidth, int dwHeight/*, IDirect3DDevice9 *dev*/ )
  9. {
  10. fWidth = (float)dwWidth;
  11. fHeight = (float)dwHeight;
  12. fHWidth = fWidth / 2.0f;
  13. fHHeight = fHeight / 2.0f;
  14. }
  15.  
  16. //call this function in your render function before drawing (once every frame)
  17. public static void W2S_update(Player plr)
  18. {
  19. //stuff that doesnt change while drawing doesnt need to be recalced EVERY FUCKING CALL TO W2S
  20.  
  21. float fFov = plr.zoom; //get the current view fov from anywhere =)
  22. float fMod = fWidth / fHeight;
  23. v3Right = new Vector3(viewProj.m11, viewProj.m12, viewProj.m13); //viewmatrix->right
  24. v3Up = new Vector3(viewProj.m21, viewProj.m22, viewProj.m23); //viewmatrix->up
  25. v3Forward = new Vector3(viewProj.m31, viewProj.m32, viewProj.m33); //viewmatrix->fwd
  26. v3View = new Vector3(viewProj.m41, viewProj.m42, viewProj.m43); //viewmatrix->origin
  27.  
  28. float fFovTmp = plr.zoom * (1.25f + ((1.1f - plr.zoom) / 10.0f));
  29. fFovMod = (float)(fHWidth / Math.Tan(fFovTmp / 2.0f));
  30. }
  31.  
  32.  
  33.  
  34. //the actual W2S
  35. public static bool W2S_project(ref Vector3 coord)
  36. {
  37. Vector3 diff = Vector3.Zero;
  38. Vector3.Subtract(ref v3View, ref coord, out diff);
  39. float z = Vector3.Dot(diff, v3Forward);
  40.  
  41. if (z <= 0.1f)
  42. {
  43. return false;
  44. }
  45.  
  46. coord.X = fHWidth + Vector3.Dot(diff, v3Right) / z * fFovMod;
  47. coord.Y = fHHeight - Vector3.Dot(diff, v3Up) / z * fFovMod;
  48. coord.Z = z;
  49.  
  50. return true;
  51. }
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement