Explorar el Código

Merge pull request #836 from younata/next

Scalar division with the '/' operator on vectors.
Ken Whatmough hace 13 años
padre
commit
74473658ac

+ 10 - 0
gameplay/src/Vector2.h

@@ -392,6 +392,16 @@ public:
      * @return This vector, after the scale occurs.
      */
     inline Vector2& operator*=(float x);
+    
+    /**
+     * Returns the components of this vector divided by the given constant
+     *
+     * Note: this does not modify this vector.
+     *
+     * @param x the constant to divide this vector with
+     * @return a smaller vector
+     */
+    inline const Vector2 operator/(float x) const;
 
     /**
      * Determines if this vector is less than the given vector.

+ 5 - 0
gameplay/src/Vector2.inl

@@ -49,6 +49,11 @@ inline Vector2& Vector2::operator*=(float x)
     return *this;
 }
 
+inline const Vector2 Vector2::operator/(const float x) const
+{
+    return Vector2(this->x / x, this->y / x);
+}
+
 inline bool Vector2::operator<(const Vector2& v) const
 {
     if (x == v.x)

+ 10 - 0
gameplay/src/Vector3.h

@@ -422,6 +422,16 @@ public:
      * @return This vector, after the scale occurs.
      */
     inline Vector3& operator*=(float x);
+    
+    /**
+     * Returns the components of this vector divided by the given constant
+     *
+     * Note: this does not modify this vector.
+     *
+     * @param x the constant to divide this vector with
+     * @return a smaller vector
+     */
+    inline const Vector3 operator/(float x) const;
 
     /**
      * Determines if this vector is less than the given vector.

+ 5 - 0
gameplay/src/Vector3.inl

@@ -50,6 +50,11 @@ inline Vector3& Vector3::operator*=(float x)
     return *this;
 }
 
+inline const Vector3 Vector3::operator/(const float x) const
+{
+    return Vector3(this->x / x, this->y / x, this->z / x);
+}
+
 inline bool Vector3::operator<(const Vector3& v) const
 {
     if (x == v.x)

+ 10 - 0
gameplay/src/Vector4.h

@@ -404,6 +404,16 @@ public:
      * @return This vector, after the scale occurs.
      */
     inline Vector4& operator*=(float x);
+    
+    /**
+     * Returns the components of this vector divided by the given constant
+     *
+     * Note: this does not modify this vector.
+     *
+     * @param x the constant to divide this vector with
+     * @return a smaller vector
+     */
+    inline const Vector4 operator/(float x) const;
 
     /**
      * Determines if this vector is less than the given vector.

+ 5 - 0
gameplay/src/Vector4.inl

@@ -50,6 +50,11 @@ inline Vector4& Vector4::operator*=(float x)
     return *this;
 }
 
+inline const Vector4 Vector4::operator/(const float x) const
+{
+    return Vector4(this->x / x, this->y / x, this->z / x, this->w / x);
+}
+
 inline bool Vector4::operator<(const Vector4& v) const
 {
     if (x == v.x)