暫無描述
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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <cmath>
  27. namespace olc {
  28. enum rcode {
  29. FAIL = 0,
  30. OK = 1,
  31. NO_FILE = -1,
  32. };
  33. std::wstring ConvertS2W(std::string s);
  34. template <class T>
  35. struct v2d_generic
  36. {
  37. T x = 0;
  38. T y = 0;
  39. inline v2d_generic() : x(0), y(0) { }
  40. inline v2d_generic(T _x, T _y) : x(_x), y(_y) { }
  41. inline v2d_generic(const v2d_generic& v) : x(v.x), y(v.y){ }
  42. inline T mag() { return sqrt(x * x + y * y); }
  43. inline v2d_generic norm() { T r = 1 / mag(); return v2d_generic(x*r, y*r); }
  44. inline v2d_generic perp() { return v2d_generic(-y, x); }
  45. inline T dot(const v2d_generic& rhs) { return this->x * rhs.x + this->y * rhs.y; }
  46. inline T cross(const v2d_generic& rhs) { return this->x * rhs.y - this->y * rhs.x; }
  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 v2d_generic& rhs) const { return v2d_generic(this->x - rhs.x, this->y - rhs.y);}
  49. inline v2d_generic operator * (const T& rhs) const { return v2d_generic(this->x * rhs, this->y * rhs); }
  50. inline v2d_generic operator / (const T& rhs) const { return v2d_generic(this->x / rhs, this->y / rhs); }
  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 v2d_generic& rhs) { this->x -= rhs.x; this->y -= rhs.y; return *this; }
  53. inline v2d_generic& operator *= (const T& rhs) { this->x *= rhs; this->y *= rhs; return *this; }
  54. inline v2d_generic& operator /= (const T& rhs) { this->x /= rhs; this->y /= rhs; return *this; }
  55. inline T& operator [] (std::size_t i) { return *((T*)this + i); /* <-- D'oh :( */ }
  56. };
  57. 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); }
  58. 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); }
  59. 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); }
  60. 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); }
  61. 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); }
  62. 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); }
  63. typedef v2d_generic<int> vi2d;
  64. typedef v2d_generic<float> vf2d;
  65. typedef v2d_generic<double> vd2d;
  66. }
  67. #endif