Vector3.pkg 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. $#include "Vector3.h"
  2. /// Three-dimensional vector.
  3. class Vector3
  4. {
  5. public:
  6. /// Construct undefined.
  7. Vector3();
  8. /// Copy-construct from another vector.
  9. Vector3(const Vector3& vector);
  10. /// Construct from a two-dimensional vector and the Z coordinate.
  11. Vector3(const Vector2& vector, float z);
  12. /// Construct from coordinates.
  13. Vector3(float x, float y, float z);
  14. /// Test for equality with another vector without epsilon.
  15. bool operator == (const Vector3& rhs) const;
  16. /// Add a vector.
  17. Vector3 operator + (const Vector3& rhs) const;
  18. /// Return negation.
  19. Vector3 operator - () const;
  20. /// Subtract a vector.
  21. Vector3 operator - (const Vector3& rhs) const;
  22. /// Multiply with a scalar.
  23. Vector3 operator * (float rhs) const;
  24. /// Multiply with a vector.
  25. Vector3 operator * (const Vector3& rhs) const;
  26. /// Divide by a scalar.
  27. Vector3 operator / (float rhs) const;
  28. /// Divide by a vector.
  29. Vector3 operator / (const Vector3& rhs) const;
  30. /// Normalize to unit length and return the previous length.
  31. float Normalize();
  32. /// Return length.
  33. float Length() const;
  34. /// Return squared length.
  35. float LengthSquared() const;
  36. /// Calculate dot product.
  37. float DotProduct(const Vector3& rhs) const;
  38. /// Calculate absolute dot product.
  39. float AbsDotProduct(const Vector3& rhs) const;
  40. /// Calculate cross product.
  41. Vector3 CrossProduct(const Vector3& rhs) const;
  42. /// Return absolute vector.
  43. Vector3 Abs() const;
  44. /// Linear interpolation with another vector.
  45. Vector3 Lerp(const Vector3& rhs, float t) const;
  46. /// Test for equality with another vector with epsilon.
  47. bool Equals(const Vector3& rhs) const;
  48. /// Return normalized to unit length.
  49. Vector3 Normalized() const;
  50. /// X coordinate.
  51. float x_ @ x;
  52. /// Y coordinate.
  53. float y_ @ y;
  54. /// Z coordinate.
  55. float z_ @ z;
  56. /// Zero vector.
  57. static const Vector3 ZERO;
  58. /// (-1,0,0) vector.
  59. static const Vector3 LEFT;
  60. /// (1,0,0) vector.
  61. static const Vector3 RIGHT;
  62. /// (0,1,0) vector.
  63. static const Vector3 UP;
  64. /// (0,-1,0) vector.
  65. static const Vector3 DOWN;
  66. /// (0,0,1) vector.
  67. static const Vector3 FORWARD;
  68. /// (0,0,-1) vector.
  69. static const Vector3 BACK;
  70. /// (1,1,1) vector.
  71. static const Vector3 ONE;
  72. };