Browse Source

Changed the binary operators to return a const qualified value in order to avoid issues like:
Matrix a, b, c;
(a*b) = c;

Darryl Gough 14 years ago
parent
commit
64e91c1bde

+ 1 - 1
gameplay/src/BoundingBox.h

@@ -191,7 +191,7 @@ public:
  * @param box The bounding box to transform.
  * @return The resulting transformed bounding box.
  */
-inline BoundingBox operator*(const Matrix& matrix, const BoundingBox& box);
+inline const BoundingBox operator*(const Matrix& matrix, const BoundingBox& box);
 
 }
 

+ 1 - 1
gameplay/src/BoundingBox.inl

@@ -9,7 +9,7 @@ inline BoundingBox& BoundingBox::operator*=(const Matrix& matrix)
     return *this;
 }
 
-inline BoundingBox operator*(const Matrix& matrix, const BoundingBox& box)
+inline const BoundingBox operator*(const Matrix& matrix, const BoundingBox& box)
 {
     BoundingBox b(box);
     b.transform(matrix);

+ 1 - 1
gameplay/src/BoundingSphere.h

@@ -183,7 +183,7 @@ private:
  * @param sphere The bounding sphere to transform.
  * @return The resulting transformed bounding sphere.
  */
-inline BoundingSphere operator*(const Matrix& matrix, const BoundingSphere& sphere);
+inline const BoundingSphere operator*(const Matrix& matrix, const BoundingSphere& sphere);
 
 }
 

+ 1 - 1
gameplay/src/BoundingSphere.inl

@@ -9,7 +9,7 @@ inline BoundingSphere& BoundingSphere::operator*=(const Matrix& matrix)
     return *this;
 }
 
-inline BoundingSphere operator*(const Matrix& matrix, const BoundingSphere& sphere)
+inline const BoundingSphere operator*(const Matrix& matrix, const BoundingSphere& sphere)
 {
     BoundingSphere s(sphere);
     s.transform(matrix);

+ 9 - 9
gameplay/src/Matrix.h

@@ -831,7 +831,7 @@ public:
      * @param m The matrix to add.
      * @return The matrix sum.
      */
-    inline Matrix operator+(const Matrix& m) const;
+    inline const Matrix operator+(const Matrix& m) const;
     
     /**
      * Adds the given matrix to this matrix.
@@ -842,14 +842,14 @@ public:
     inline Matrix& operator+=(const Matrix& m);
 
     /**
-     * Calculates the sum of this matrix with the given matrix.
+     * Calculates the difference of this matrix with the given matrix.
      * 
      * Note: this does not modify this matrix.
      * 
-     * @param m The matrix to add.
-     * @return The matrix sum.
+     * @param m The matrix to subtract.
+     * @return The matrix difference.
      */
-    inline Matrix operator-(const Matrix& m) const;
+    inline const Matrix operator-(const Matrix& m) const;
 
     /**
      * Subtracts the given matrix from this matrix.
@@ -866,7 +866,7 @@ public:
      * 
      * @return The negation of this matrix.
      */
-    inline Matrix operator-() const;
+    inline const Matrix operator-() const;
 
     /**
      * Calculates the matrix product of this matrix with the given matrix.
@@ -876,7 +876,7 @@ public:
      * @param m The matrix to multiply by.
      * @return The matrix product.
      */
-    inline Matrix operator*(const Matrix& m) const;
+    inline const Matrix operator*(const Matrix& m) const;
 
     /**
      * Right-multiplies this matrix by the given matrix.
@@ -907,7 +907,7 @@ inline Vector3& operator*=(Vector3& v, const Matrix& m);
  * @param v The vector to transform.
  * @return The resulting transformed vector.
  */
-inline Vector3 operator*(const Matrix& m, const Vector3& v);
+inline const Vector3 operator*(const Matrix& m, const Vector3& v);
 
 /**
  * Transforms the given vector by the given matrix.
@@ -929,7 +929,7 @@ inline Vector4& operator*=(Vector4& v, const Matrix& m);
  * @param v The vector to transform.
  * @return The resulting transformed vector.
  */
-inline Vector4 operator*(const Matrix& m, const Vector4& v);
+inline const Vector4 operator*(const Matrix& m, const Vector4& v);
 
 }
 

+ 6 - 6
gameplay/src/Matrix.inl

@@ -3,7 +3,7 @@
 namespace gameplay
 {
 
-inline Matrix Matrix::operator+(const Matrix& m) const
+inline const Matrix Matrix::operator+(const Matrix& m) const
 {
     Matrix result(*this);
     result.add(m);
@@ -16,7 +16,7 @@ inline Matrix& Matrix::operator+=(const Matrix& m)
     return *this;
 }
 
-inline Matrix Matrix::operator-(const Matrix& m) const
+inline const Matrix Matrix::operator-(const Matrix& m) const
 {
     Matrix result(*this);
     result.subtract(m);
@@ -29,14 +29,14 @@ inline Matrix& Matrix::operator-=(const Matrix& m)
     return *this;
 }
 
-inline Matrix Matrix::operator-() const
+inline const Matrix Matrix::operator-() const
 {
     Matrix m(*this);
     m.negate();
     return m;
 }
 
-inline Matrix Matrix::operator*(const Matrix& m) const
+inline const Matrix Matrix::operator*(const Matrix& m) const
 {
     Matrix result(*this);
     result.multiply(m);
@@ -55,7 +55,7 @@ inline Vector3& operator*=(Vector3& v, const Matrix& m)
     return v;
 }
 
-inline Vector3 operator*(const Matrix& m, const Vector3& v)
+inline const Vector3 operator*(const Matrix& m, const Vector3& v)
 {
     Vector3 x;
     m.transformVector(v, &x);
@@ -68,7 +68,7 @@ inline Vector4& operator*=(Vector4& v, const Matrix& m)
     return v;
 }
 
-inline Vector4 operator*(const Matrix& m, const Vector4& v)
+inline const Vector4 operator*(const Matrix& m, const Vector4& v)
 {
     Vector4 x;
     m.transformVector(v, &x);

+ 1 - 1
gameplay/src/Plane.h

@@ -220,7 +220,7 @@ private:
  * @param plane The plane to transform.
  * @return The resulting transformed plane.
  */
-inline Plane operator*(const Matrix& matrix, const Plane& plane);
+inline const Plane operator*(const Matrix& matrix, const Plane& plane);
 
 }
 

+ 1 - 1
gameplay/src/Plane.inl

@@ -9,7 +9,7 @@ inline Plane& Plane::operator*=(const Matrix& matrix)
     return *this;
 }
 
-inline Plane operator*(const Matrix& matrix, const Plane& plane)
+inline const Plane operator*(const Matrix& matrix, const Plane& plane)
 {
     Plane p(plane);
     p.transform(matrix);

+ 1 - 1
gameplay/src/Quaternion.h

@@ -340,7 +340,7 @@ public:
      * @param q The quaternion to multiply.
      * @return The quaternion product.
      */
-    inline Quaternion operator*(const Quaternion& q) const;
+    inline const Quaternion operator*(const Quaternion& q) const;
 
     /**
      * Multiplies this quaternion with the given quaternion.

+ 1 - 1
gameplay/src/Quaternion.inl

@@ -3,7 +3,7 @@
 namespace gameplay
 {
 
-inline Quaternion Quaternion::operator*(const Quaternion& q) const
+inline const Quaternion Quaternion::operator*(const Quaternion& q) const
 {
     Quaternion result(*this);
     result.multiply(q);

+ 1 - 1
gameplay/src/Ray.h

@@ -167,7 +167,7 @@ private:
  * @param ray The ray to transform.
  * @return The resulting transformed ray.
  */
-inline Ray operator*(const Matrix& matrix, const Ray& ray);
+inline const Ray operator*(const Matrix& matrix, const Ray& ray);
 
 }
 

+ 1 - 1
gameplay/src/Ray.inl

@@ -9,7 +9,7 @@ inline Ray& Ray::operator*=(const Matrix& matrix)
     return *this;
 }
 
-inline Ray operator*(const Matrix& matrix, const Ray& ray)
+inline const Ray operator*(const Matrix& matrix, const Ray& ray)
 {
     Ray r(ray);
     r.transform(matrix);

+ 5 - 5
gameplay/src/Vector2.h

@@ -323,7 +323,7 @@ public:
      * @param v The vector to add.
      * @return The vector sum.
      */
-    inline Vector2 operator+(const Vector2& v) const;
+    inline const Vector2 operator+(const Vector2& v) const;
 
     /**
      * Adds the given vector to this vector.
@@ -341,7 +341,7 @@ public:
      * @param v The vector to add.
      * @return The vector sum.
      */
-    inline Vector2 operator-(const Vector2& v) const;
+    inline const Vector2 operator-(const Vector2& v) const;
 
     /**
      * Subtracts the given vector from this vector.
@@ -358,7 +358,7 @@ public:
      * 
      * @return The negation of this vector.
      */
-    inline Vector2 operator-() const;
+    inline const Vector2 operator-() const;
 
     /**
      * Calculates the scalar product of this vector with the given value.
@@ -368,7 +368,7 @@ public:
      * @param x The value to scale by.
      * @return The scaled vector.
      */
-    inline Vector2 operator*(float x) const;
+    inline const Vector2 operator*(float x) const;
 
     /**
      * Scales this vector by the given value.
@@ -404,7 +404,7 @@ public:
  * @param v The vector to scale.
  * @return The scaled vector.
  */
-inline Vector2 operator*(float x, const Vector2& v);
+inline const Vector2 operator*(float x, const Vector2& v);
 
 }
 

+ 5 - 5
gameplay/src/Vector2.inl

@@ -3,7 +3,7 @@
 namespace gameplay
 {
 
-inline Vector2 Vector2::operator+(const Vector2& v) const
+inline const Vector2 Vector2::operator+(const Vector2& v) const
 {
     Vector2 result(*this);
     result.add(v);
@@ -16,7 +16,7 @@ inline Vector2& Vector2::operator+=(const Vector2& v)
     return *this;
 }
 
-inline Vector2 Vector2::operator-(const Vector2& v) const
+inline const Vector2 Vector2::operator-(const Vector2& v) const
 {
     Vector2 result(*this);
     result.subtract(v);
@@ -29,14 +29,14 @@ inline Vector2& Vector2::operator-=(const Vector2& v)
     return *this;
 }
 
-inline Vector2 Vector2::operator-() const
+inline const Vector2 Vector2::operator-() const
 {
     Vector2 result(*this);
     result.negate();
     return result;
 }
 
-inline Vector2 Vector2::operator*(float x) const
+inline const Vector2 Vector2::operator*(float x) const
 {
     Vector2 result(*this);
     result.scale(x);
@@ -63,7 +63,7 @@ inline bool Vector2::operator==(const Vector2& v) const
     return x==v.x && y==v.y;
 }
 
-inline Vector2 operator*(float x, const Vector2& v)
+inline const Vector2 operator*(float x, const Vector2& v)
 {
     Vector2 result(v);
     result.scale(x);

+ 5 - 5
gameplay/src/Vector3.h

@@ -353,7 +353,7 @@ public:
      * @param v The vector to add.
      * @return The vector sum.
      */
-    inline Vector3 operator+(const Vector3& v) const;
+    inline const Vector3 operator+(const Vector3& v) const;
 
     /**
      * Adds the given vector to this vector.
@@ -371,7 +371,7 @@ public:
      * @param v The vector to add.
      * @return The vector sum.
      */
-    inline Vector3 operator-(const Vector3& v) const;
+    inline const Vector3 operator-(const Vector3& v) const;
 
     /**
      * Subtracts the given vector from this vector.
@@ -388,7 +388,7 @@ public:
      * 
      * @return The negation of this vector.
      */
-    inline Vector3 operator-() const;
+    inline const Vector3 operator-() const;
 
     /**
      * Calculates the scalar product of this vector with the given value.
@@ -398,7 +398,7 @@ public:
      * @param x The value to scale by.
      * @return The scaled vector.
      */
-    inline Vector3 operator*(float x) const;
+    inline const Vector3 operator*(float x) const;
 
     /**
      * Scales this vector by the given value.
@@ -434,7 +434,7 @@ public:
  * @param v The vector to scale.
  * @return The scaled vector.
  */
-inline Vector3 operator*(float x, const Vector3& v);
+inline const Vector3 operator*(float x, const Vector3& v);
 
 }
 

+ 5 - 5
gameplay/src/Vector3.inl

@@ -4,7 +4,7 @@
 namespace gameplay
 {
 
-inline Vector3 Vector3::operator+(const Vector3& v) const
+inline const Vector3 Vector3::operator+(const Vector3& v) const
 {
     Vector3 result(*this);
     result.add(v);
@@ -17,7 +17,7 @@ inline Vector3& Vector3::operator+=(const Vector3& v)
     return *this;
 }
 
-inline Vector3 Vector3::operator-(const Vector3& v) const
+inline const Vector3 Vector3::operator-(const Vector3& v) const
 {
     Vector3 result(*this);
     result.subtract(v);
@@ -30,14 +30,14 @@ inline Vector3& Vector3::operator-=(const Vector3& v)
     return *this;
 }
 
-inline Vector3 Vector3::operator-() const
+inline const Vector3 Vector3::operator-() const
 {
     Vector3 result(*this);
     result.negate();
     return result;
 }
 
-inline Vector3 Vector3::operator*(float x) const
+inline const Vector3 Vector3::operator*(float x) const
 {
     Vector3 result(*this);
     result.scale(x);
@@ -68,7 +68,7 @@ inline bool Vector3::operator==(const Vector3& v) const
     return x==v.x && y==v.y && z==v.z;
 }
 
-inline Vector3 operator*(float x, const Vector3& v)
+inline const Vector3 operator*(float x, const Vector3& v)
 {
     Vector3 result(v);
     result.scale(x);

+ 5 - 5
gameplay/src/Vector4.h

@@ -348,7 +348,7 @@ public:
      * @param v The vector to add.
      * @return The vector sum.
      */
-    inline Vector4 operator+(const Vector4& v) const;
+    inline const Vector4 operator+(const Vector4& v) const;
 
     /**
      * Adds the given vector to this vector.
@@ -366,7 +366,7 @@ public:
      * @param v The vector to add.
      * @return The vector sum.
      */
-    inline Vector4 operator-(const Vector4& v) const;
+    inline const Vector4 operator-(const Vector4& v) const;
 
     /**
      * Subtracts the given vector from this vector.
@@ -383,7 +383,7 @@ public:
      * 
      * @return The negation of this vector.
      */
-    inline Vector4 operator-() const;
+    inline const Vector4 operator-() const;
 
     /**
      * Calculates the scalar product of this vector with the given value.
@@ -393,7 +393,7 @@ public:
      * @param x The value to scale by.
      * @return The scaled vector.
      */
-    inline Vector4 operator*(float x) const;
+    inline const Vector4 operator*(float x) const;
 
     /**
      * Scales this vector by the given value.
@@ -429,7 +429,7 @@ public:
  * @param v The vector to scale.
  * @return The scaled vector.
  */
-inline Vector4 operator*(float x, const Vector4& v);
+inline const Vector4 operator*(float x, const Vector4& v);
 
 }
 

+ 5 - 5
gameplay/src/Vector4.inl

@@ -4,7 +4,7 @@
 namespace gameplay
 {
 
-inline Vector4 Vector4::operator+(const Vector4& v) const
+inline const Vector4 Vector4::operator+(const Vector4& v) const
 {
     Vector4 result(*this);
     result.add(v);
@@ -17,7 +17,7 @@ inline Vector4& Vector4::operator+=(const Vector4& v)
     return *this;
 }
 
-inline Vector4 Vector4::operator-(const Vector4& v) const
+inline const Vector4 Vector4::operator-(const Vector4& v) const
 {
     Vector4 result(*this);
     result.subtract(v);
@@ -30,14 +30,14 @@ inline Vector4& Vector4::operator-=(const Vector4& v)
     return *this;
 }
 
-inline Vector4 Vector4::operator-() const
+inline const Vector4 Vector4::operator-() const
 {
     Vector4 result(*this);
     result.negate();
     return result;
 }
 
-inline Vector4 Vector4::operator*(float x) const
+inline const Vector4 Vector4::operator*(float x) const
 {
     Vector4 result(*this);
     result.scale(x);
@@ -75,7 +75,7 @@ inline bool Vector4::operator==(const Vector4& v) const
     return x==v.x && y==v.y && z==v.z && w==v.w;
 }
 
-inline Vector4 operator*(float x, const Vector4& v)
+inline const Vector4 operator*(float x, const Vector4& v)
 {
     Vector4 result(v);
     result.scale(x);