fork download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. struct Vector2D
  5. {
  6. float x, y;
  7. Vector2D() : x(0), y(0) {}
  8. Vector2D(float x, float y) : x(x), y(y) {}
  9. Vector2D operator -(const Vector2D& v) const
  10. {
  11. return (Vector2D(x - v.x, y - v.y));
  12. }
  13. Vector2D operator -(void) const
  14. {
  15. return (Vector2D(-x, -y));
  16. }
  17. float magnitude() { return (float)sqrt(x * x + y * y); }
  18. };
  19.  
  20. const Vector2D minimapCenter(627, 135);
  21.  
  22. float dot(const Vector2D& a, const Vector2D& b)
  23. {
  24. return a.x * b.y + a.y * b.x;
  25. }
  26.  
  27. void rotate(Vector2D& p, float theta)
  28. {
  29. p.x = cos(theta) * (p.x) - sin(theta) * (p.y);
  30. p.y = sin(theta) * (p.x) + cos(theta) * (p.y);
  31. }
  32.  
  33. float getTheta(const Vector2D& texCoord0, const Vector2D& texCoord1)
  34. {
  35. Vector2D a(0, -1), b = texCoord0 - texCoord1;
  36. return atan2(a.y,a.x) - atan2(b.y,b.x);
  37. }
  38.  
  39. Vector2D getRelativePosition(const Vector2D& texCoord0, const Vector2D& texCoord1)
  40. {
  41. Vector2D p = texCoord0 - minimapCenter;
  42. rotate(p, getTheta(texCoord0, texCoord1));
  43. //p = -p;
  44. return p;
  45. }
  46.  
  47. using std::cout;
  48. using std::endl;
  49. int main()
  50. {
  51. Vector2D texCoord0(309.88147, -144.74777); // top left
  52. Vector2D texCoord1(305.99057, 389.2381); // bottom left
  53.  
  54. cout << getTheta(texCoord0, texCoord1) << endl;
  55.  
  56. Vector2D p = getRelativePosition(texCoord0, texCoord1);
  57. cout << "(" << p.x << ", " << p.y << ")" << endl;
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
-0.00728639
(-319.148, -277.415)