暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

olcPGE_Common.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef OLC_PGE_COMMON
  2. #define OLC_PGE_COMMON
  3. #ifdef _WIN32
  4. // Link to libraries
  5. #ifndef __MINGW32__
  6. #pragma comment(lib, "user32.lib")
  7. #pragma comment(lib, "gdi32.lib")
  8. #pragma comment(lib, "gdiplus.lib")
  9. #else
  10. // In Code::Blocks, Select C++14 in your build options, and add the
  11. // following libs to your linker: user32 gdi32 opengl32 gdiplus
  12. #if !defined _WIN32_WINNT
  13. #ifdef HAVE_MSMF
  14. #define _WIN32_WINNT 0x0600 // Windows Vista
  15. #else
  16. #define _WIN32_WINNT 0x0500 // Windows 2000
  17. #endif
  18. #endif
  19. #endif
  20. // Include WinAPI
  21. #include <windows.h>
  22. #include <gdiplus.h>
  23. #else
  24. #endif
  25. #include <string>
  26. namespace olc {
  27. enum rcode {
  28. FAIL = 0,
  29. OK = 1,
  30. NO_FILE = -1,
  31. };
  32. std::wstring ConvertS2W(std::string s);
  33. template <class T>
  34. struct v2d_generic
  35. {
  36. T x = 0;
  37. T y = 0;
  38. inline v2d_generic() : x(0), y(0) { }
  39. inline v2d_generic(T _x, T _y) : x(_x), y(_y) { }
  40. inline v2d_generic(const v2d_generic& v) : x(v.x), y(v.y){ }
  41. inline T mag() { return sqrt(x * x + y * y); }
  42. inline v2d_generic norm() { T r = 1 / mag(); return v2d_generic(x*r, y*r); }
  43. inline v2d_generic perp() { return v2d_generic(-y, x); }
  44. inline T dot(const v2d_generic& rhs) { return this->x * rhs.x + this->y * rhs.y; }
  45. inline T cross(const v2d_generic& rhs) { return this->x * rhs.y - this->y * rhs.x; }
  46. inline v2d_generic operator + (const v2d_generic& rhs) const { return v2d_generic(this->x + rhs.x, this->y + rhs.y);}
  47. inline v2d_generic operator - (const v2d_generic& rhs) const { return v2d_generic(this->x - rhs.x, this->y - rhs.y);}
  48. inline v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); }
  49. inline v2d_generic operator / (const T& rhs) const { return v2d_generic(this->x / rhs, this->y / rhs); }
  50. inline v2d_generic& operator += (const v2d_generic& rhs) { this->x += rhs.x; this->y += rhs.y; return *this; }
  51. inline v2d_generic& operator -= (const v2d_generic& rhs) { this->x -= rhs.x; this->y -= rhs.y; return *this; }
  52. inline v2d_generic& operator *= (const T& rhs) { this->x *= rhs; this->y *= rhs; return *this; }
  53. inline v2d_generic& operator /= (const T& rhs) { this->x /= rhs; this->y /= rhs; return *this; }
  54. inline T& operator [] (std::size_t i) { return *((T*)this + i); /* <-- D'oh :( */ }
  55. };
  56. template<class T> inline v2d_generic<T> operator * (const float& lhs, const v2d_generic<T>& rhs) { return v2d_generic<T>(lhs * rhs.x, lhs * rhs.y); }
  57. template<class T> inline v2d_generic<T> operator * (const double& lhs, const v2d_generic<T>& rhs){ return v2d_generic<T>(lhs * rhs.x, lhs * rhs.y); }
  58. template<class T> inline v2d_generic<T> operator * (const int& lhs, const v2d_generic<T>& rhs) { return v2d_generic<T>(lhs * rhs.x, lhs * rhs.y); }
  59. template<class T> inline v2d_generic<T> operator / (const float& lhs, const v2d_generic<T>& rhs) { return v2d_generic<T>(lhs / rhs.x, lhs / rhs.y); }
  60. template<class T> inline v2d_generic<T> operator / (const double& lhs, const v2d_generic<T>& rhs){ return v2d_generic<T>(lhs / rhs.x, lhs / rhs.y); }
  61. template<class T> inline v2d_generic<T> operator / (const int& lhs, const v2d_generic<T>& rhs) { return v2d_generic<T>(lhs / rhs.x, lhs / rhs.y); }
  62. typedef v2d_generic<int> vi2d;
  63. typedef v2d_generic<float> vf2d;
  64. typedef v2d_generic<double> vd2d;
  65. }
  66. #endif