瀏覽代碼

Added '/' operator for vector3 and float.

It divides the components of the vector by the float, and returns a new vector.
Rachel Brindle 13 年之前
父節點
當前提交
a4a12dba2e
共有 2 個文件被更改,包括 15 次插入0 次删除
  1. 10 0
      gameplay/src/Vector3.h
  2. 5 0
      gameplay/src/Vector3.inl

+ 10 - 0
gameplay/src/Vector3.h

@@ -424,6 +424,16 @@ public:
      * @return The scaled vector.
      * @return The scaled vector.
      */
      */
     inline const Vector3 operator*(float x) const;
     inline const Vector3 operator*(float x) const;
+    
+    /**
+     * 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;
 
 
     /**
     /**
      * Scales this vector by the given value.
      * Scales this vector by the given value.

+ 5 - 0
gameplay/src/Vector3.inl

@@ -57,6 +57,11 @@ inline Vector3& Vector3::operator*=(float x)
     return *this;
     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
 inline bool Vector3::operator<(const Vector3& v) const
 {
 {
     if (x == v.x)
     if (x == v.x)