Vector.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #define _USE_MATH_DEFINES
  2. #include <cmath>
  3. #include "Vector.h"
  4. Vec3f::Vec3f(float x, float y, float z)
  5. {
  6. this->x = x;
  7. this->y = y;
  8. this->z = z;
  9. }
  10. /*The length of the vector*/
  11. float Vec3f::Length()
  12. {
  13. return (float)sqrt(x*x+y*y+z*z);
  14. }
  15. float Vec3f::Distance(const Vec3f &other)
  16. {
  17. return (float)sqrt(pow(other.x - x, 2)+pow(other.y - y, 2)+pow(other.z - z, 2));
  18. }
  19. Vec3f::Vec3f()
  20. {
  21. this->x = 0;
  22. this->y = 0;
  23. this->z = 0;
  24. }
  25. Vec3f::Vec3f(Vec3f &other)
  26. {
  27. this->x = other.x;
  28. this->y = other.y;
  29. this->z = other.z;
  30. }
  31. float& Vec3f::operator [](int index)
  32. {
  33. return v[index];
  34. }
  35. Vec3f Vec3f::operator+(const Vec3f & other)
  36. {
  37. return Vec3f(x + other.x, y + other.y, z + other.z);
  38. }
  39. Vec3f Vec3f::operator/(float value)
  40. {
  41. return Vec3f(x / value, y / value, z / value);
  42. }
  43. bool Vec3f::operator==(const Vec3f & other)
  44. {
  45. /*bool xb, yb,zb;
  46. xb = x == other.x;
  47. yb = y == other.y;
  48. zb = z == other.z;
  49. if (xb & yb & zb)
  50. return true;*/
  51. return x == other.x & y == other.y & z == other.z;
  52. }
  53. bool Vec3f::operator!=(const Vec3f & other)
  54. {
  55. return x != other.x & y != other.y & z != other.z;
  56. }
  57. Vec2f::Vec2f(float x, float y)
  58. {
  59. this->x = x;
  60. this->y = y;
  61. }
  62. Vec2f::Vec2f()
  63. {
  64. this->x = 0;
  65. this->y = 0;
  66. }
  67. Vec2f::Vec2f(Vec2f &other)
  68. {
  69. this->x = other.x;
  70. this->y = other.y;
  71. }
  72. float& Vec2f::operator [](int index)
  73. {
  74. return v[index];
  75. }
  76. Vec2f Vec2f::operator+(const Vec2f & other)
  77. {
  78. return Vec2f(x + other.x, y+other.y);
  79. }
  80. float Vec2f::length()
  81. {
  82. return (float)sqrt(x*x + y*y);
  83. }