Vector.cpp 1.4 KB

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