소스 검색

Merge pull request #27 from blackberry-gaming/next-operators

Operator Support for Math Classes
Steve Grenier 14 년 전
부모
커밋
d8f313a424

+ 10 - 1
gameplay/gameplay.vcxproj

@@ -149,6 +149,15 @@
     <None Include="res\shaders\textured.fsh" />
     <None Include="res\shaders\textured.vsh" />
     <None Include="src\gameplay-main-macosx.mm" />
+    <None Include="src\BoundingBox.inl" />
+    <None Include="src\BoundingSphere.inl" />
+    <None Include="src\Matrix.inl" />
+    <None Include="src\Plane.inl" />
+    <None Include="src\Quaternion.inl" />
+    <None Include="src\Ray.inl" />
+    <None Include="src\Vector2.inl" />
+    <None Include="src\Vector3.inl" />
+    <None Include="src\Vector4.inl" />
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{1032BA4B-57EB-4348-9E03-29DD63E80E4A}</ProjectGuid>
@@ -259,4 +268,4 @@
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>

+ 28 - 1
gameplay/gameplay.vcxproj.filters

@@ -406,5 +406,32 @@
     <None Include="src\gameplay-main-macosx.mm">
       <Filter>src</Filter>
     </None>
+    <None Include="src\BoundingBox.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\BoundingSphere.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Matrix.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Plane.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Quaternion.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Ray.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Vector2.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Vector3.inl">
+      <Filter>src</Filter>
+    </None>
+    <None Include="src\Vector4.inl">
+      <Filter>src</Filter>
+    </None>
   </ItemGroup>
-</Project>
+</Project>

+ 19 - 0
gameplay/src/BoundingBox.h

@@ -178,8 +178,27 @@ public:
      * @param matrix The transformation matrix to transform by.
      */
     void transform(const Matrix& matrix);
+
+    /**
+     * Transforms this bounding box by the given matrix.
+     * 
+     * @param matrix The matrix to transform by.
+     * @return This bounding box, after the transformation occurs.
+     */
+    inline BoundingBox& operator*=(const Matrix& matrix);
 };
 
+/**
+ * Transforms the given bounding box by the given matrix.
+ * 
+ * @param matrix The matrix to transform by.
+ * @param box The bounding box to transform.
+ * @return The resulting transformed bounding box.
+ */
+inline BoundingBox operator*(const Matrix& matrix, const BoundingBox& box);
+
 }
 
+#include "BoundingBox.inl"
+
 #endif

+ 23 - 0
gameplay/src/BoundingBox.inl

@@ -0,0 +1,23 @@
+/** 
+ * BoundingBox.inl
+ */
+
+#include "BoundingBox.h"
+
+namespace gameplay
+{
+
+inline BoundingBox& BoundingBox::operator*=(const Matrix& matrix)
+{
+    transform(matrix);
+    return *this;
+}
+
+inline BoundingBox operator*(const Matrix& matrix, const BoundingBox& box)
+{
+    BoundingBox b(box);
+    b.transform(matrix);
+    return b;
+}
+
+}

+ 19 - 0
gameplay/src/BoundingSphere.h

@@ -165,6 +165,14 @@ public:
      */
     void transform(const Matrix& matrix);
 
+    /**
+     * Transforms this bounding sphere by the given matrix.
+     * 
+     * @param matrix The matrix to transform by.
+     * @return This bounding sphere, after the transformation occurs.
+     */
+    inline BoundingSphere& operator*=(const Matrix& matrix);
+
 private:
 
     float distance(const BoundingSphere& sphere, const Vector3&);
@@ -172,6 +180,17 @@ private:
     bool contains(const BoundingSphere& sphere, Vector3* points, unsigned int count);
 };
 
+/**
+ * Transforms the given bounding sphere by the given matrix.
+ * 
+ * @param matrix The matrix to transform by.
+ * @param sphere The bounding sphere to transform.
+ * @return The resulting transformed bounding sphere.
+ */
+inline BoundingSphere operator*(const Matrix& matrix, const BoundingSphere& sphere);
+
 }
 
+#include "BoundingSphere.inl"
+
 #endif

+ 23 - 0
gameplay/src/BoundingSphere.inl

@@ -0,0 +1,23 @@
+/** 
+ * BoundingSphere.inl
+ */
+
+#include "BoundingSphere.h"
+
+namespace gameplay
+{
+
+inline BoundingSphere& BoundingSphere::operator*=(const Matrix& matrix)
+{
+    transform(matrix);
+    return *this;
+}
+
+inline BoundingSphere operator*(const Matrix& matrix, const BoundingSphere& sphere)
+{
+    BoundingSphere s(sphere);
+    s.transform(matrix);
+    return s;
+}
+
+}

+ 13 - 8
gameplay/src/Matrix.cpp

@@ -904,24 +904,24 @@ void Matrix::subtract(const Matrix& m1, const Matrix& m2, Matrix* dst)
     dst->m[15] = m1.m[15] - m2.m[15];
 }
 
-void Matrix::transformVector(Vector3* vector) const
+void Matrix::transformPoint(Vector3* point) const
 {
-    transformVector(vector->x, vector->y, vector->z, 0.0f, vector);
+    transformVector(point->x, point->y, point->z, 1.0f, point);
 }
 
-void Matrix::transformVector(const Vector3& vector, Vector3* dst) const
+void Matrix::transformPoint(const Vector3& point, Vector3* dst) const
 {
-    transformVector(vector.x, vector.y, vector.z, 0.0f, dst);
+    transformVector(point.x, point.y, point.z, 1.0f, dst);
 }
 
-void Matrix::transformPoint(Vector3* point) const
+void Matrix::transformVector(Vector3* vector) const
 {
-    transformVector(point->x, point->y, point->z, 1.0f, point);
+    transformVector(vector->x, vector->y, vector->z, 0.0f, vector);
 }
 
-void Matrix::transformPoint(const Vector3& point, Vector3* dst) const
+void Matrix::transformVector(const Vector3& vector, Vector3* dst) const
 {
-    transformVector(point.x, point.y, point.z, 1.0f, dst);
+    transformVector(vector.x, vector.y, vector.z, 0.0f, dst);
 }
 
 void Matrix::transformVector(float x, float y, float z, float w, Vector3* dst) const
@@ -934,6 +934,11 @@ void Matrix::transformVector(float x, float y, float z, float w, Vector3* dst) c
         x * m[2] + y * m[6] + z * m[10] + w * m[14] );
 }
 
+void Matrix::transformVector(Vector4* vector) const
+{
+    transformVector(*vector, vector);
+}
+
 void Matrix::transformVector(const Vector4& vector, Vector4* dst) const
 {
     assert(dst);

+ 136 - 19
gameplay/src/Matrix.h

@@ -5,7 +5,6 @@
 #ifndef MATRIX_H_
 #define MATRIX_H_
 
-#include "Vector2.h"
 #include "Vector3.h"
 #include "Vector4.h"
 
@@ -712,6 +711,24 @@ public:
      */
     static void subtract(const Matrix& m1, const Matrix& m2, Matrix* dst);
 
+    /**
+     * Transforms the specified point by this matrix.
+     *
+     * The result of the transformation is stored directly into point.
+     *
+     * @param point The point to transform and also a vector to hold the result in.
+     */
+    void transformPoint(Vector3* point) const;
+
+    /**
+     * Transforms the specified point by this matrix, and stores
+     * the result in dst.
+     *
+     * @param point The point to transform.
+     * @param dst A vector to store the transformed point in.
+     */
+    void transformPoint(const Vector3& point, Vector3* dst) const;
+
     /**
      * Transforms the specified vector by this matrix by
      * treating the fourth (w) coordinate as zero.
@@ -732,24 +749,6 @@ public:
      */
     void transformVector(const Vector3& vector, Vector3* dst) const;
 
-    /**
-     * Transforms the specified point by this matrix.
-     *
-     * The result of the transformation is stored directly into point.
-     *
-     * @param point The point to transform and also a vector to hold the result in.
-     */
-    void transformPoint(Vector3* point) const;
-
-    /**
-     * Transforms the specified point by this matrix, and stores
-     * the result in dst.
-     *
-     * @param point The point to transform.
-     * @param dst A vector to store the transformed point in.
-     */
-    void transformPoint(const Vector3& point, Vector3* dst) const;
-
     /**
      * Transforms the specified vector by this matrix.
      *
@@ -761,6 +760,15 @@ public:
      */
     void transformVector(float x, float y, float z, float w, Vector3* dst) const;
 
+    /**
+     * Transforms the specified vector by this matrix.
+     *
+     * The result of the transformation is stored directly into vector.
+     *
+     * @param vector The vector to transform.
+     */
+    void transformVector(Vector4* vector) const;
+
     /**
      * Transforms the specified vector by this matrix.
      *
@@ -818,8 +826,117 @@ public:
      * @param dst A matrix to store the result in.
      */
     void transpose(Matrix* dst) const;
+
+    /**
+     * Calculates the sum of this matrix with the given matrix.
+     * 
+     * Note: this does not modify this matrix.
+     * 
+     * @param m The matrix to add.
+     * @return The matrix sum.
+     */
+    inline Matrix operator+(const Matrix& m);
+    
+    /**
+     * Adds the given matrix to this matrix.
+     * 
+     * @param m The matrix to add.
+     * @return This matrix, after the addition occurs.
+     */
+    inline Matrix& operator+=(const Matrix& m);
+
+    /**
+     * Calculates the sum of this matrix with the given matrix.
+     * 
+     * Note: this does not modify this matrix.
+     * 
+     * @param m The matrix to add.
+     * @return The matrix sum.
+     */
+    inline Matrix operator-(const Matrix& m);
+
+    /**
+     * Subtracts the given matrix from this matrix.
+     * 
+     * @param m The matrix to subtract.
+     * @return This matrix, after the subtraction occurs.
+     */
+    inline Matrix& operator-=(const Matrix& m);
+
+    /**
+     * Calculates the negation of this matrix.
+     * 
+     * Note: this does not modify this matrix.
+     * 
+     * @return The negation of this matrix.
+     */
+    inline Matrix operator-();
+
+    /**
+     * Calculates the matrix product of this matrix with the given matrix.
+     * 
+     * Note: this does not modify this matrix.
+     * 
+     * @param m The matrix to multiply by.
+     * @return The matrix product.
+     */
+    inline Matrix operator*(const Matrix& m);
+
+    /**
+     * Right-multiplies this matrix by the given matrix.
+     * 
+     * @param m The matrix to multiply by.
+     * @return This matrix, after the multiplication occurs.
+     */
+    inline Matrix& operator*=(const Matrix& m);
 };
 
+/**
+ * Transforms the given vector by the given matrix.
+ * 
+ * Note: this treats the given vector as a vector and not as a point.
+ * 
+ * @param v The vector to transform.
+ * @param m The matrix to transform by.
+ * @return This vector, after the transformation occurs.
+ */
+inline Vector3& operator*=(Vector3& v, const Matrix& m);
+
+/**
+ * Transforms the given vector by the given matrix.
+ * 
+ * Note: this treats the given vector as a vector and not as a point.
+ * 
+ * @param m The matrix to transform by.
+ * @param v The vector to transform.
+ * @return The resulting transformed vector.
+ */
+inline Vector3 operator*(const Matrix& m, const Vector3& v);
+
+/**
+ * Transforms the given vector by the given matrix.
+ * 
+ * Note: this treats the given vector as a vector and not as a point.
+ * 
+ * @param v The vector to transform.
+ * @param m The matrix to transform by.
+ * @return This vector, after the transformation occurs.
+ */
+inline Vector4& operator*=(Vector4& v, const Matrix& m);
+
+/**
+ * Transforms the given vector by the given matrix.
+ * 
+ * Note: this treats the given vector as a vector and not as a point.
+ * 
+ * @param m The matrix to transform by.
+ * @param v The vector to transform.
+ * @return The resulting transformed vector.
+ */
+inline Vector4 operator*(const Matrix& m, const Vector4& v);
+
 }
 
+//#include "Matrix.inl"
+
 #endif

+ 82 - 0
gameplay/src/Matrix.inl

@@ -0,0 +1,82 @@
+/** 
+ * Matrix.inl
+ */
+
+#include "Matrix.h"
+
+namespace gameplay
+{
+
+inline Matrix Matrix::operator+(const Matrix& m)
+{
+    Matrix result(*this);
+    result.add(m);
+    return result;
+}
+
+inline Matrix& Matrix::operator+=(const Matrix& m)
+{
+    add(m);
+    return *this;
+}
+
+inline Matrix Matrix::operator-(const Matrix& m)
+{
+    Matrix result(*this);
+    result.subtract(m);
+    return result;
+}
+
+inline Matrix& Matrix::operator-=(const Matrix& m)
+{
+    subtract(m);
+    return *this;
+}
+
+inline Matrix Matrix::operator-()
+{
+    Matrix m(*this);
+    m.negate();
+    return m;
+}
+
+inline Matrix Matrix::operator*(const Matrix& m)
+{
+    Matrix result(*this);
+    result.multiply(m);
+    return result;
+}
+
+inline Matrix& Matrix::operator*=(const Matrix& m)
+{
+    multiply(m);
+    return *this;
+}
+
+inline Vector3& operator*=(Vector3& v, const Matrix& m)
+{
+    m.transformVector(&v);
+    return v;
+}
+
+inline Vector3 operator*(const Matrix& m, const Vector3& v)
+{
+    Vector3 x;
+    m.transformVector(v, &x);
+    return x;
+}
+
+inline Vector4& operator*=(Vector4& v, const Matrix& m)
+{
+    m.transformVector(&v);
+    return v;
+}
+
+inline Vector4 operator*(const Matrix& m, const Vector4& v)
+{
+    Vector4 x;
+    m.transformVector(v, &x);
+    return x;
+}
+
+}

+ 1 - 1
gameplay/src/Plane.cpp

@@ -245,7 +245,7 @@ void Plane::set(const Plane& plane)
     _distance = plane._distance;
 }
 
-void Plane::transform(Matrix& matrix)
+void Plane::transform(const Matrix& matrix)
 {
     Matrix inverted;
     if (matrix.invert(&inverted))

+ 20 - 1
gameplay/src/Plane.h

@@ -196,7 +196,15 @@ public:
      *
      * @param matrix The transformation matrix to transform by.
      */
-    void transform(Matrix& matrix);
+    void transform(const Matrix& matrix);
+
+    /**
+     * Transforms this plane by the given matrix.
+     * 
+     * @param matrix The matrix to transform by.
+     * @return This plane, after the transformation occurs.
+     */
+    inline Plane& operator*=(const Matrix& matrix);
 
 private:
 
@@ -209,6 +217,17 @@ private:
     float _distance;    // The distance of the Plane along its normal from the origin.
 };
 
+/**
+ * Transforms the given plane by the given matrix.
+ * 
+ * @param matrix The matrix to transform by.
+ * @param plane The plane to transform.
+ * @return The resulting transformed plane.
+ */
+inline Plane operator*(const Matrix& matrix, const Plane& plane);
+
 }
 
+#include "Plane.inl"
+
 #endif

+ 23 - 0
gameplay/src/Plane.inl

@@ -0,0 +1,23 @@
+/** 
+ * Plane.inl
+ */
+
+#include "Plane.h"
+
+namespace gameplay
+{
+
+inline Plane& Plane::operator*=(const Matrix& matrix)
+{
+    transform(matrix);
+    return *this;
+}
+
+inline Plane operator*(const Matrix& matrix, const Plane& plane)
+{
+    Plane p(plane);
+    p.transform(matrix);
+    return p;
+}
+
+}

+ 1 - 0
gameplay/src/Properties.h

@@ -7,6 +7,7 @@
 
 #include "Base.h"
 #include "Matrix.h"
+#include "Vector2.h"
 
 namespace gameplay
 {

+ 15 - 7
gameplay/src/Quaternion.cpp

@@ -23,6 +23,15 @@ Quaternion::Quaternion(float* array)
     set(array);
 }
 
+Quaternion::Quaternion(const Matrix& m)
+{
+    set(m);
+}
+
+Quaternion::Quaternion(const Vector3& axis, float angle)
+{
+    set(axis, angle);
+}
 
 Quaternion::Quaternion(const Quaternion& copy)
 {
@@ -192,15 +201,14 @@ void Quaternion::set(float* array)
     w = array[3];
 }
 
-void Quaternion::set(const Vector3& axis, float angle)
+void Quaternion::set(const Matrix& m)
 {
-    Quaternion rotationQuat;
-    Quaternion::createFromAxisAngle(axis, angle, &rotationQuat);
+    Quaternion::createFromRotationMatrix(m, this);
+}
 
-    this->x = rotationQuat.x;
-    this->y = rotationQuat.y;
-    this->z = rotationQuat.z;
-    this->w = rotationQuat.w;
+void Quaternion::set(const Vector3& axis, float angle)
+{
+    Quaternion::createFromAxisAngle(axis, angle, this);
 }
 
 void Quaternion::set(const Quaternion& q)

+ 42 - 0
gameplay/src/Quaternion.h

@@ -85,6 +85,21 @@ public:
      */
     Quaternion(float* array);
 
+    /**
+     * Constructs a quaternion equal to the rotational part of the specified matrix.
+     *
+     * @param m The matrix.
+     */
+    Quaternion(const Matrix& m);
+
+    /**
+     * Constructs a quaternion equal to the rotation from the specified axis and angle.
+     *
+     * @param axis A vector describing the axis of rotation.
+     * @param angle The angle of rotation (in radians).
+     */
+    Quaternion(const Vector3& axis, float angle);
+
     /**
      * Constructs a new quaternion that is a copy of the specified one.
      *
@@ -234,6 +249,13 @@ public:
      */
     void set(float* array);
 
+    /**
+     * Sets the quaternion equal to the rotational part of the specified matrix.
+     *
+     * @param m The matrix.
+     */
+    void set(const Matrix& m);
+
     /**
      * Sets the quaternion equal to the rotation from the specified axis and angle.
      * 
@@ -312,6 +334,24 @@ public:
      */
     static void squad(const Quaternion& q1, const Quaternion& q2, const Quaternion& s1, const Quaternion& s2, float t, Quaternion* dst);
 
+    /**
+     * Calculates the quaternion product of this quaternion with the given quaternion.
+     * 
+     * Note: this does not modify this quaternion.
+     * 
+     * @param q The quaternion to multiply.
+     * @return The quaternion product.
+     */
+    inline Quaternion operator*(const Quaternion& q);
+
+    /**
+     * Multiplies this quaternion with the given quaternion.
+     * 
+     * @param q The quaternion to multiply.
+     * @return This quaternion, after the multiplication occurs.
+     */
+    inline Quaternion& operator*=(const Quaternion& q);
+
 private:
 
     static void slerpForSquad(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst);
@@ -319,4 +359,6 @@ private:
 
 }
 
+#include "Quaternion.inl"
+
 #endif

+ 23 - 0
gameplay/src/Quaternion.inl

@@ -0,0 +1,23 @@
+/** 
+ * Quaternion.inl
+ */
+
+#include "Quaternion.h"
+
+namespace gameplay
+{
+
+inline Quaternion Quaternion::operator*(const Quaternion& q)
+{
+    Quaternion result(*this);
+    result.multiply(q);
+    return result;
+}
+
+inline Quaternion& Quaternion::operator*=(const Quaternion& q)
+{
+    multiply(q);
+    return *this;
+}
+
+}

+ 19 - 0
gameplay/src/Ray.h

@@ -145,6 +145,14 @@ public:
      */
     void transform(const Matrix& matrix);
 
+    /**
+     * Transforms this ray by the given matrix.
+     * 
+     * @param matrix The matrix to transform by.
+     * @return This ray, after the transformation occurs.
+     */
+    inline Ray& operator*=(const Matrix& matrix);
+
 private:
 
     /**
@@ -156,6 +164,17 @@ private:
     Vector3 _direction;     // The ray direction vector.
 };
 
+/**
+ * Transforms the given ray by the given matrix.
+ * 
+ * @param matrix The matrix to transform by.
+ * @param ray The ray to transform.
+ * @return The resulting transformed ray.
+ */
+inline Ray operator*(const Matrix& matrix, const Ray& ray);
+
 }
 
+#include "Ray.inl"
+
 #endif

+ 23 - 0
gameplay/src/Ray.inl

@@ -0,0 +1,23 @@
+/** 
+ * Ray.inl
+ */
+
+#include "Ray.h"
+
+namespace gameplay
+{
+
+inline Ray& Ray::operator*=(const Matrix& matrix)
+{
+    transform(matrix);
+    return *this;
+}
+
+inline Ray operator*(const Matrix& matrix, const Ray& ray)
+{
+    Ray r(ray);
+    r.transform(matrix);
+    return r;
+}
+
+}

+ 74 - 0
gameplay/src/Vector2.h

@@ -318,8 +318,82 @@ public:
      * @param dst The destination vector.
      */
     static void subtract(const Vector2& v1, const Vector2& v2, Vector2* dst);
+
+    /**
+     * Calculates the sum of this vector with the given vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param v The vector to add.
+     * @return The vector sum.
+     */
+    inline Vector2 operator+(const Vector2& v);
+
+    /**
+     * Adds the given vector to this vector.
+     * 
+     * @param v The vector to add.
+     * @return This vector, after the addition occurs.
+     */
+    inline Vector2& operator+=(const Vector2& v);
+
+    /**
+     * Calculates the sum of this vector with the given vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param v The vector to add.
+     * @return The vector sum.
+     */
+    inline Vector2 operator-(const Vector2& v);
+
+    /**
+     * Subtracts the given vector from this vector.
+     * 
+     * @param v The vector to subtract.
+     * @return This vector, after the subtraction occurs.
+     */
+    inline Vector2& operator-=(const Vector2& v);
+
+    /**
+     * Calculates the negation of this vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @return The negation of this vector.
+     */
+    inline Vector2 operator-();
+
+    /**
+     * Calculates the scalar product of this vector with the given value.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param x The value to scale by.
+     * @return The scaled vector.
+     */
+    inline Vector2 operator*(float x);
+
+    /**
+     * Scales this vector by the given value.
+     * 
+     * @param x The value to scale by.
+     * @return This vector, after the scale occurs.
+     */
+    inline Vector2& operator*=(float x);
 };
 
+/**
+ * Calculates the scalar product of the given vector with the given value.
+ * 
+ * @param x The value to scale by.
+ * @param v The vector to scale.
+ * @return The scaled vector.
+ */
+inline Vector2 operator*(float x, const Vector2& v);
+
 }
 
+#include "Vector2.inl"
+
 #endif

+ 63 - 0
gameplay/src/Vector2.inl

@@ -0,0 +1,63 @@
+/** 
+ * Vector2.inl
+ */
+
+#include "Vector2.h"
+
+namespace gameplay
+{
+
+inline Vector2 Vector2::operator+(const Vector2& v)
+{
+    Vector2 result(*this);
+    result.add(v);
+    return result;
+}
+
+inline Vector2& Vector2::operator+=(const Vector2& v)
+{
+    add(v);
+    return *this;
+}
+
+inline Vector2 Vector2::operator-(const Vector2& v)
+{
+    Vector2 result(*this);
+    result.subtract(v);
+    return result;
+}
+
+inline Vector2& Vector2::operator-=(const Vector2& v)
+{
+    subtract(v);
+    return *this;
+}
+
+inline Vector2 Vector2::operator-()
+{
+    Vector2 result(*this);
+    result.negate();
+    return result;
+}
+
+inline Vector2 Vector2::operator*(float x)
+{
+    Vector2 result(*this);
+    result.scale(x);
+    return result;
+}
+
+inline Vector2& Vector2::operator*=(float x)
+{
+    scale(x);
+    return *this;
+}
+
+inline Vector2 operator*(float x, const Vector2& v)
+{
+    Vector2 result(v);
+    result.scale(x);
+    return result;
+}
+
+}

+ 74 - 0
gameplay/src/Vector3.h

@@ -348,8 +348,82 @@ public:
      * @param dst The destination vector.
      */
     static void subtract(const Vector3& v1, const Vector3& v2, Vector3* dst);
+
+    /**
+     * Calculates the sum of this vector with the given vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param v The vector to add.
+     * @return The vector sum.
+     */
+    inline Vector3 operator+(const Vector3& v);
+
+    /**
+     * Adds the given vector to this vector.
+     * 
+     * @param v The vector to add.
+     * @return This vector, after the addition occurs.
+     */
+    inline Vector3& operator+=(const Vector3& v);
+
+    /**
+     * Calculates the sum of this vector with the given vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param v The vector to add.
+     * @return The vector sum.
+     */
+    inline Vector3 operator-(const Vector3& v);
+
+    /**
+     * Subtracts the given vector from this vector.
+     * 
+     * @param v The vector to subtract.
+     * @return This vector, after the subtraction occurs.
+     */
+    inline Vector3& operator-=(const Vector3& v);
+
+    /**
+     * Calculates the negation of this vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @return The negation of this vector.
+     */
+    inline Vector3 operator-();
+
+    /**
+     * Calculates the scalar product of this vector with the given value.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param x The value to scale by.
+     * @return The scaled vector.
+     */
+    inline Vector3 operator*(float x);
+
+    /**
+     * Scales this vector by the given value.
+     * 
+     * @param x The value to scale by.
+     * @return This vector, after the scale occurs.
+     */
+    inline Vector3& operator*=(float x);
 };
 
+/**
+ * Calculates the scalar product of the given vector with the given value.
+ * 
+ * @param x The value to scale by.
+ * @param v The vector to scale.
+ * @return The scaled vector.
+ */
+inline Vector3 operator*(float x, const Vector3& v);
+
 }
 
+#include "Vector3.inl"
+
 #endif

+ 64 - 0
gameplay/src/Vector3.inl

@@ -0,0 +1,64 @@
+/** 
+ * Vector3.inl
+ */
+
+#include "Vector3.h"
+#include "Matrix.h"
+
+namespace gameplay
+{
+
+inline Vector3 Vector3::operator+(const Vector3& v)
+{
+    Vector3 result(*this);
+    result.add(v);
+    return result;
+}
+
+inline Vector3& Vector3::operator+=(const Vector3& v)
+{
+    add(v);
+    return *this;
+}
+
+inline Vector3 Vector3::operator-(const Vector3& v)
+{
+    Vector3 result(*this);
+    result.subtract(v);
+    return result;
+}
+
+inline Vector3& Vector3::operator-=(const Vector3& v)
+{
+    subtract(v);
+    return *this;
+}
+
+inline Vector3 Vector3::operator-()
+{
+    Vector3 result(*this);
+    result.negate();
+    return result;
+}
+
+inline Vector3 Vector3::operator*(float x)
+{
+    Vector3 result(*this);
+    result.scale(x);
+    return result;
+}
+
+inline Vector3& Vector3::operator*=(float x)
+{
+    scale(x);
+    return *this;
+}
+
+inline Vector3 operator*(float x, const Vector3& v)
+{
+    Vector3 result(v);
+    result.scale(x);
+    return result;
+}
+
+}

+ 74 - 0
gameplay/src/Vector4.h

@@ -343,8 +343,82 @@ public:
      * @param dst The destination vector.
      */
     static void subtract(const Vector4& v1, const Vector4& v2, Vector4* dst);
+
+    /**
+     * Calculates the sum of this vector with the given vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param v The vector to add.
+     * @return The vector sum.
+     */
+    inline Vector4 operator+(const Vector4& v);
+
+    /**
+     * Adds the given vector to this vector.
+     * 
+     * @param v The vector to add.
+     * @return This vector, after the addition occurs.
+     */
+    inline Vector4& operator+=(const Vector4& v);
+
+    /**
+     * Calculates the sum of this vector with the given vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param v The vector to add.
+     * @return The vector sum.
+     */
+    inline Vector4 operator-(const Vector4& v);
+
+    /**
+     * Subtracts the given vector from this vector.
+     * 
+     * @param v The vector to subtract.
+     * @return This vector, after the subtraction occurs.
+     */
+    inline Vector4& operator-=(const Vector4& v);
+
+    /**
+     * Calculates the negation of this vector.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @return The negation of this vector.
+     */
+    inline Vector4 operator-();
+
+    /**
+     * Calculates the scalar product of this vector with the given value.
+     * 
+     * Note: this does not modify this vector.
+     * 
+     * @param x The value to scale by.
+     * @return The scaled vector.
+     */
+    inline Vector4 operator*(float x);
+
+    /**
+     * Scales this vector by the given value.
+     * 
+     * @param x The value to scale by.
+     * @return This vector, after the scale occurs.
+     */
+    inline Vector4& operator*=(float x);
 };
 
+/**
+ * Calculates the scalar product of the given vector with the given value.
+ * 
+ * @param x The value to scale by.
+ * @param v The vector to scale.
+ * @return The scaled vector.
+ */
+inline Vector4 operator*(float x, const Vector4& v);
+
 }
 
+#include "Vector4.inl"
+
 #endif

+ 64 - 0
gameplay/src/Vector4.inl

@@ -0,0 +1,64 @@
+/** 
+ * Vector4.inl
+ */
+
+#include "Matrix.h"
+#include "Vector4.h"
+
+namespace gameplay
+{
+
+inline Vector4 Vector4::operator+(const Vector4& v)
+{
+    Vector4 result(*this);
+    result.add(v);
+    return result;
+}
+
+inline Vector4& Vector4::operator+=(const Vector4& v)
+{
+    add(v);
+    return *this;
+}
+
+inline Vector4 Vector4::operator-(const Vector4& v)
+{
+    Vector4 result(*this);
+    result.subtract(v);
+    return result;
+}
+
+inline Vector4& Vector4::operator-=(const Vector4& v)
+{
+    subtract(v);
+    return *this;
+}
+
+inline Vector4 Vector4::operator-()
+{
+    Vector4 result(*this);
+    result.negate();
+    return result;
+}
+
+inline Vector4 Vector4::operator*(float x)
+{
+    Vector4 result(*this);
+    result.scale(x);
+    return result;
+}
+
+inline Vector4& Vector4::operator*=(float x)
+{
+    scale(x);
+    return *this;
+}
+
+inline Vector4 operator*(float x, const Vector4& v)
+{
+    Vector4 result(v);
+    result.scale(x);
+    return result;
+}
+
+}