BsVectorNI.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisitesUtil.h"
  5. #include "BsVector2I.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Math
  9. * @{
  10. */
  11. /** A N dimensional vector with integer coordinates. */
  12. template<int N>
  13. struct VectorNI
  14. {
  15. INT32 v[N];
  16. VectorNI()
  17. {
  18. memset(v, 0, sizeof(v));
  19. }
  20. VectorNI(INT32 val[N])
  21. {
  22. memcpy(v, val, sizeof(v));
  23. }
  24. INT32 operator[] (size_t i) const
  25. {
  26. assert(i < N);
  27. return v[i];
  28. }
  29. INT32& operator[] (size_t i)
  30. {
  31. assert(i < N);
  32. return v[i];
  33. }
  34. VectorNI& operator= (const VectorNI& rhs)
  35. {
  36. memcpy(v, rhs.v, sizeof(v));
  37. return *this;
  38. }
  39. bool operator== (const Vector2I& rhs) const
  40. {
  41. for (UINT32 i = 0; i < N; i++)
  42. {
  43. if (v[i] != rhs[i])
  44. return false;
  45. }
  46. return true;
  47. }
  48. bool operator!= (const Vector2I& rhs) const
  49. {
  50. return !operator==(*this, rhs);
  51. }
  52. };
  53. /** @} */
  54. typedef VectorNI<3> Vector3I;
  55. typedef VectorNI<4> Vector4I;
  56. }