$#include "Vector4.h" /// Four-dimensional vector. class Vector4 { public: /// Construct undefined. Vector4() { } /// Copy-construct from another vector. Vector4(const Vector4& vector) : x_(vector.x_), y_(vector.y_), z_(vector.z_), w_(vector.w_) { } /// Construct from a 3-dimensional vector and the W coordinate. Vector4(const Vector3& vector, float w) : x_(vector.x_), y_(vector.y_), z_(vector.z_), w_(w) { } /// Construct from coordinates. Vector4(float x, float y, float z, float w) : x_(x), y_(y), z_(z), w_(w) { } /// Test for equality with another vector without epsilon. bool operator == (const Vector4& rhs) const { return x_ == rhs.x_ && y_ == rhs.y_ && z_ == rhs.z_ && w_ == rhs.w_; } /// Add a vector. Vector4 operator + (const Vector4& rhs) const { return Vector4(x_ + rhs.x_, y_ + rhs.y_, z_ + rhs.z_, w_ + rhs.w_); } /// Return negation. Vector4 operator - () const { return Vector4(-x_, -y_, -z_, -w_); } /// Subtract a vector. Vector4 operator - (const Vector4& rhs) const { return Vector4(x_ - rhs.x_, y_ - rhs.y_, z_ - rhs.z_, w_ - rhs.w_); } /// Multiply with a scalar. Vector4 operator * (float rhs) const { return Vector4(x_ * rhs, y_ * rhs, z_ * rhs, w_ * rhs); } /// Multiply with a vector. Vector4 operator * (const Vector4& rhs) const { return Vector4(x_ * rhs.x_, y_ * rhs.y_, z_ * rhs.z_, w_ * rhs.w_); } /// Divide by a scalar. Vector4 operator / (float rhs) const { return Vector4(x_ / rhs, y_ / rhs, z_ / rhs, w_ / rhs); } /// Divide by a vector. Vector4 operator / (const Vector4& rhs) const { return Vector4(x_ / rhs.x_, y_ / rhs.y_, z_ / rhs.z_, w_ / rhs.w_); } Vector4 operator / (const Vector4& rhs) const; /// Calculate dot product. float DotProduct(const Vector4& rhs) const { return x_ * rhs.x_ + y_ * rhs.y_ + z_ * rhs.z_ + w_ * rhs.w_; } /// Calculate absolute dot product. 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_); } /// Return absolute vector. Vector4 Abs() const { return Vector4(Urho3D::Abs(x_), Urho3D::Abs(y_), Urho3D::Abs(z_), Urho3D::Abs(w_)); } /// Linear interpolation with another vector. Vector4 Lerp(const Vector4& rhs, float t) const { return *this * (1.0f - t) + rhs * t; } /// Test for equality with another vector with epsilon. 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_); } /// Return as string. String ToString() const; /// X coordinate. float x_ @ x; /// Y coordinate. float y_ @ y; /// Z coordinate. float z_ @ z; /// W coordinate. float w_ @ w; /// Zero vector. static const Vector4 ZERO; /// (1,1,1) vector. static const Vector4 ONE; };