Advertisement
CorrM

w2s c#

Dec 4th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. public static float[] ReadMatrix(long Address)
  2. {
  3. byte[] numArray = new byte[64];
  4. numArray = Program.CorrM.MemLib.readBytes(Address.ToString("X"), numArray.Length);
  5. return ConvertToFloatArray(numArray);
  6. }
  7. public static float[] ConvertToFloatArray(byte[] bytes)
  8. {
  9. if ((bytes.Length % 4) > 0) throw new ArgumentException();
  10.  
  11. float[] numArray = new float[bytes.Length / 4];
  12. for (int index = 0; index < numArray.Length; ++index)
  13. {
  14. numArray[index] = BitConverter.ToSingle(bytes, index * 4);
  15. }
  16. return numArray;
  17. }
  18.  
  19. bool WorldToScreenCpp(Vector3 position, out Vector2 Screen)
  20. {
  21. Screen = new Vector2();
  22. GetWindowRect(EmulatorRenderBox, out Vector2 ScreenSize);
  23. float[] viewMatrix = ReadMatrix(AddressSaver.Matrix);
  24.  
  25. double x = (position.X * viewMatrix[0] + position.Y * viewMatrix[4] + position.Z * viewMatrix[8]) + viewMatrix[12];
  26. double y = (position.X * viewMatrix[1] + position.Y * viewMatrix[5] + position.Z * viewMatrix[9]) + viewMatrix[13];
  27. double w = (position.X * viewMatrix[3] + position.Y * viewMatrix[7] + position.Z * viewMatrix[11]) + viewMatrix[15];
  28.  
  29. if (w < 0.100000001490116)
  30. return false;
  31.  
  32. int width = (int)ScreenSize.X;
  33. int height = (int)ScreenSize.Y;
  34.  
  35. x /= w;
  36. y /= w;
  37.  
  38. float halfW = width / 2;
  39. float halfH = height / 2;
  40.  
  41. Screen.X = (float)(halfW * x + (x + halfW));
  42. Screen.Y = (float)(-(halfH * y) + (y + halfH));
  43. return true;
  44. }
  45. bool WorldToScreenCpp2(Vector3 pos, out Vector2 screen)
  46. {
  47. screen = new Vector2(0, 0);
  48. float[] matrixF = ReadMatrix(AddressSaver.Matrix);
  49.  
  50. // NOT inversed matrix.
  51. Vector3 clipCoords = new Vector3
  52. {
  53. X = pos.X * matrixF[0] + pos.Z * matrixF[4] + pos.Y * matrixF[8] + matrixF[12],
  54. Y = pos.X * matrixF[1] + pos.Z * matrixF[5] + pos.Y * matrixF[9] + matrixF[13],
  55. Z = pos.X * matrixF[3] + pos.Z * matrixF[7] + pos.Y * matrixF[11] + matrixF[15]
  56. };
  57.  
  58. if (clipCoords.Z < 0.100000001490116)
  59. return false;
  60.  
  61. Vector3 SP = new Vector3
  62. {
  63. X = clipCoords.X / clipCoords.Z,
  64. Y = clipCoords.Y / clipCoords.Z
  65. };
  66.  
  67. GetWindowRect(EmulatorRenderBox, out Vector2 ScreenSize);
  68.  
  69. screen.X = (ScreenSize.X / 2 * SP.X) + (SP.X + ScreenSize.X / 2);
  70. screen.Y = -(ScreenSize.Y / 2 * SP.Y) + (SP.Y + ScreenSize.Y / 2);
  71. return true;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement