You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
838 B

5 years ago
  1. #include "vector3.h"
  2. Vector3f::Vector3f(float x, float y, float z)
  3. {
  4. this->x = x;
  5. this->y = y;
  6. this->z = z;
  7. }
  8. Vector3f Vector3f::operator+(Vector3f & r)
  9. {
  10. return Vector3f(x + r.x, y + r.y, z + r.z);
  11. }
  12. Vector3f Vector3f::operator-(Vector3f & r)
  13. {
  14. return Vector3f(x - r.x, y - r.y, z - r.z);
  15. }
  16. Vector3f Vector3f::operator*(float scaler)
  17. {
  18. return Vector3f(x*scaler, y*scaler, z*scaler);
  19. }
  20. float Vector3f::operator*(Vector3f & r)
  21. {
  22. return x *r.x + y * r.y + z*r.z;
  23. }
  24. void Vector3f::operator=(Vector3f & r)
  25. {
  26. x = r.x;
  27. y = r.y;
  28. z = r.z;
  29. }
  30. void Vector3f::Normalize()
  31. {
  32. float len = Magnitude();
  33. x /= len;
  34. y /= len;
  35. z /= len;
  36. }
  37. float Vector3f::Magnitude()
  38. {
  39. return sqrtf(x*x + y*y + z*z);
  40. }
  41. Vector3f Cross(Vector3f v1, Vector3f v2)
  42. {
  43. return Vector3f(v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x);
  44. }