Vector.cpp 1.1 KB

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