Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

cPoint3D.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #pragma once
  2. class cPoint3D {
  3. public:
  4. cPoint3D()
  5. {
  6. }
  7. cPoint3D(float nx, float ny, float nz)
  8. {
  9. x = nx;
  10. y = ny;
  11. z = nz;
  12. }
  13. bool operator ==(cPoint3D p3dOther)
  14. {
  15. if (x != p3dOther.x) return false;
  16. if (y != p3dOther.y) return false;
  17. if (z != p3dOther.z) return false;
  18. return true;
  19. }
  20. bool operator !=(cPoint3D p3dOther)
  21. {
  22. return !((x == p3dOther.x) && (y == p3dOther.y) && (z == p3dOther.z));
  23. }
  24. cPoint3D operator *(float fOther)
  25. {
  26. return cPoint3D(x * fOther, y * fOther, z * fOther);
  27. }
  28. cPoint3D operator /(float fOther)
  29. {
  30. return cPoint3D(x / fOther, y / fOther, z / fOther);
  31. }
  32. cPoint3D operator +(cPoint3D p3dOther)
  33. {
  34. return cPoint3D(x + p3dOther.x, y + p3dOther.y, z + p3dOther.z);
  35. }
  36. cPoint3D operator -(cPoint3D p3dOther)
  37. {
  38. return cPoint3D(x - p3dOther.x, y - p3dOther.y, z - p3dOther.z);
  39. }
  40. void operator *=(float fOther)
  41. {
  42. x *= fOther;
  43. y *= fOther;
  44. z *= fOther;
  45. return; //true;
  46. }
  47. void operator /=(float fOther)
  48. {
  49. x /= fOther;
  50. y /= fOther;
  51. z /= fOther;
  52. return; //true;
  53. }
  54. void operator +=(cPoint3D p3dOther)
  55. {
  56. x += p3dOther.x;
  57. y += p3dOther.y;
  58. z += p3dOther.z;
  59. return; //true;
  60. }
  61. void operator -=(cPoint3D p3dOther)
  62. {
  63. x -= p3dOther.x;
  64. y -= p3dOther.y;
  65. z -= p3dOther.z;
  66. return; //true;
  67. }
  68. void RotateAround(cPoint3D Center, cPoint3D Rotation)
  69. {
  70. float tpx, tpy, tpz;
  71. x -= Center.x;
  72. y -= Center.y;
  73. z -= Center.z;
  74. tpy = y * (float) cos(Rotation.x) - z * (float) sin(Rotation.x);
  75. tpz = z * (float) cos(Rotation.x) + y * (float) sin(Rotation.x);
  76. z = tpz * (float) cos(Rotation.y) - x * (float) sin(Rotation.y) + Center.z;
  77. tpx = x * (float) cos(Rotation.y) + tpz * (float) sin(Rotation.y);
  78. x = tpx * (float) cos(Rotation.z) - tpy * (float) sin(Rotation.z) + Center.x;
  79. y = tpy * (float) cos(Rotation.z) + tpx * (float) sin(Rotation.z) + Center.y;
  80. }
  81. cPoint3D CrossProduct(cPoint3D p3dOther)
  82. {
  83. return cPoint3D(y*p3dOther.z - p3dOther.y*z, z*p3dOther.x - p3dOther.z*x, x*p3dOther.y - p3dOther.x*y);
  84. }
  85. float DotProduct(cPoint3D p3dOther)
  86. {
  87. return x*p3dOther.x + y*p3dOther.y + z*p3dOther.z;
  88. }
  89. void Normalize()
  90. {
  91. float fTemp = (float) Abs();
  92. x /= fTemp;
  93. y /= fTemp;
  94. z /= fTemp;
  95. }
  96. void CalcFromLocation(stLocation *Loc)
  97. {
  98. z = Loc->zOffset / 240.0f;
  99. DWORD dwBlockX = (Loc->landblock & 0xff000000) >> 24;
  100. DWORD dwBlockY = (Loc->landblock & 0x00ff0000) >> 16;
  101. if (dwBlockX < 3)
  102. {
  103. // dungeon, dwBlockX and dwBlockY remain constant - just use x and y
  104. x = Loc->xOffset / 240.0f;
  105. y = Loc->yOffset / 240.0f;
  106. }
  107. else
  108. {
  109. // outdoors
  110. x = (float) ((((float (dwBlockX)+1.0f) * 8.0f + (Loc->xOffset / 24.0)) - 1027.5) / 10.0f);
  111. y = (float) ((((float (dwBlockY)+1.0f) * 8.0f + (Loc->yOffset / 24.0)) - 1027.5) / 10.0f);
  112. }
  113. }
  114. float Abs()
  115. {
  116. return (float) sqrt(x*x+y*y+z*z);
  117. }
  118. float x, y, z;
  119. };