Vector.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "common/math/Vector.h"
  2. template<>
  3. Vector<3>::Vector(float x, float y, float z) {
  4. values[0] = x;
  5. values[1] = y;
  6. values[2] = z;
  7. }
  8. template<>
  9. Vector<2>::Vector(float x, float y) {
  10. values[0] = x;
  11. values[1] = y;
  12. }
  13. template<>
  14. Vector<3>& Vector<3>::setAngles(float lengthAngle, float widthAngle) {
  15. lengthAngle *= (M_PI / 180.0f);
  16. widthAngle *= (M_PI / 180.0f);
  17. values[0] = cosf(widthAngle) * sinf(lengthAngle);
  18. values[1] = sinf(widthAngle);
  19. values[2] = cosf(widthAngle) * cosf(lengthAngle);
  20. return *this;
  21. }
  22. template<>
  23. Vector<3>::Vector(float lengthAngle, float widthAngle) {
  24. setAngles(lengthAngle, widthAngle);
  25. }
  26. template<>
  27. Vector<3>& Vector<3>::set(float x, float y, float z) {
  28. values[0] = x;
  29. values[1] = y;
  30. values[2] = z;
  31. return *this;
  32. }
  33. template<>
  34. Vector<3> Vector<3>::cross(const Vector<3>& other) const {
  35. return Vector<3>(
  36. values[1] * other.values[2] - values[2] * other.values[1],
  37. values[2] * other.values[0] - values[0] * other.values[2],
  38. values[0] * other.values[1] - values[1] * other.values[0]);
  39. }