Vector4.pkg 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. $#include "Vector4.h"
  2. /// Four-dimensional vector.
  3. class Vector4
  4. {
  5. public:
  6. /// Construct undefined.
  7. Vector4()
  8. {
  9. }
  10. /// Copy-construct from another vector.
  11. Vector4(const Vector4& vector) :
  12. x_(vector.x_),
  13. y_(vector.y_),
  14. z_(vector.z_),
  15. w_(vector.w_)
  16. {
  17. }
  18. /// Construct from a 3-dimensional vector and the W coordinate.
  19. Vector4(const Vector3& vector, float w) :
  20. x_(vector.x_),
  21. y_(vector.y_),
  22. z_(vector.z_),
  23. w_(w)
  24. {
  25. }
  26. /// Construct from coordinates.
  27. Vector4(float x, float y, float z, float w) :
  28. x_(x),
  29. y_(y),
  30. z_(z),
  31. w_(w)
  32. {
  33. }
  34. /// Test for equality with another vector without epsilon.
  35. bool operator == (const Vector4& rhs) const { return x_ == rhs.x_ && y_ == rhs.y_ && z_ == rhs.z_ && w_ == rhs.w_; }
  36. /// Add a vector.
  37. Vector4 operator + (const Vector4& rhs) const { return Vector4(x_ + rhs.x_, y_ + rhs.y_, z_ + rhs.z_, w_ + rhs.w_); }
  38. /// Return negation.
  39. Vector4 operator - () const { return Vector4(-x_, -y_, -z_, -w_); }
  40. /// Subtract a vector.
  41. Vector4 operator - (const Vector4& rhs) const { return Vector4(x_ - rhs.x_, y_ - rhs.y_, z_ - rhs.z_, w_ - rhs.w_); }
  42. /// Multiply with a scalar.
  43. Vector4 operator * (float rhs) const { return Vector4(x_ * rhs, y_ * rhs, z_ * rhs, w_ * rhs); }
  44. /// Multiply with a vector.
  45. Vector4 operator * (const Vector4& rhs) const { return Vector4(x_ * rhs.x_, y_ * rhs.y_, z_ * rhs.z_, w_ * rhs.w_); }
  46. /// Divide by a scalar.
  47. Vector4 operator / (float rhs) const { return Vector4(x_ / rhs, y_ / rhs, z_ / rhs, w_ / rhs); }
  48. /// Divide by a vector.
  49. Vector4 operator / (const Vector4& rhs) const { return Vector4(x_ / rhs.x_, y_ / rhs.y_, z_ / rhs.z_, w_ / rhs.w_); }
  50. Vector4 operator / (const Vector4& rhs) const;
  51. /// Calculate dot product.
  52. float DotProduct(const Vector4& rhs) const { return x_ * rhs.x_ + y_ * rhs.y_ + z_ * rhs.z_ + w_ * rhs.w_; }
  53. /// Calculate absolute dot product.
  54. float AbsDotProduct(const Vector4& rhs) const { return Urho3D::Abs(x_ * rhs.x_) + Urho3D::Abs(y_ * rhs.y_) + Urho3D::Abs(z_ * rhs.z_) + Urho3D::Abs(w_ * rhs.w_); }
  55. /// Return absolute vector.
  56. Vector4 Abs() const { return Vector4(Urho3D::Abs(x_), Urho3D::Abs(y_), Urho3D::Abs(z_), Urho3D::Abs(w_)); }
  57. /// Linear interpolation with another vector.
  58. Vector4 Lerp(const Vector4& rhs, float t) const { return *this * (1.0f - t) + rhs * t; }
  59. /// Test for equality with another vector with epsilon.
  60. bool Equals(const Vector4& rhs) const { return Urho3D::Equals(x_, rhs.x_) && Urho3D::Equals(y_, rhs.y_) && Urho3D::Equals(z_, rhs.z_) && Urho3D::Equals(w_, rhs.w_); }
  61. /// Return as string.
  62. String ToString() const;
  63. /// X coordinate.
  64. float x_ @ x;
  65. /// Y coordinate.
  66. float y_ @ y;
  67. /// Z coordinate.
  68. float z_ @ z;
  69. /// W coordinate.
  70. float w_ @ w;
  71. /// Zero vector.
  72. static const Vector4 ZERO;
  73. /// (1,1,1) vector.
  74. static const Vector4 ONE;
  75. };