summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/vector.cpp60
-rw-r--r--engine/vector.h11
2 files changed, 71 insertions, 0 deletions
diff --git a/engine/vector.cpp b/engine/vector.cpp
index c23466e..6c71991 100644
--- a/engine/vector.cpp
+++ b/engine/vector.cpp
@@ -26,6 +26,20 @@ Vector2& Vector2::operator+=(const Vector2& v) {
return *this;
}
+Vector2& Vector2::operator+(const Vector2& v) {
+ return Vector2(*this) += v;
+}
+
+Vector2& Vector2::operator-=(const Vector2& v) {
+ x -= v.x;
+ y -= v.y;
+ return *this;
+}
+
+Vector2& Vector2::operator-(const Vector2& v) {
+ return Vector2(*this) -= v;
+}
+
Vector3::Vector3() : Vector2() {
z = 0;
}
@@ -49,6 +63,28 @@ Vector3& Vector3::operator=(const Vector3& v) {
return *this;
}
+Vector3& Vector3::operator+=(const Vector3& v) {
+ x += v.x;
+ y += v.y;
+ z += v.z;
+ return *this;
+}
+
+Vector3& Vector3::operator+(const Vector3& v) {
+ return Vector3(*this) += v;
+}
+
+Vector3& Vector3::operator-=(const Vector3& v) {
+ x -= v.x;
+ y -= v.y;
+ z -= v.z;
+ return *this;
+}
+
+Vector3& Vector3::operator-(const Vector3& v) {
+ return Vector3(*this) -= v;
+}
+
Vector4::Vector4() : Vector3() {
w = 0;
}
@@ -71,3 +107,27 @@ Vector4& Vector4::operator=(const Vector4& v) {
w = v.w;
return *this;
}
+
+Vector4& Vector4::operator+=(const Vector4& v) {
+ x += v.x;
+ y += v.y;
+ z += v.z;
+ w += v.w;
+ return *this;
+}
+
+Vector4& Vector4::operator+(const Vector4& v) {
+ return Vector4(*this) += v;
+}
+
+Vector4& Vector4::operator-=(const Vector4& v) {
+ x -= v.x;
+ y -= v.y;
+ z -= v.z;
+ w -= v.w;
+ return *this;
+}
+
+Vector4& Vector4::operator-(const Vector4& v) {
+ return Vector4(*this) -= v;
+}
diff --git a/engine/vector.h b/engine/vector.h
index 127ca81..8d85684 100644
--- a/engine/vector.h
+++ b/engine/vector.h
@@ -16,6 +16,9 @@ class Vector2 {
Vector2& operator=(const Vector2& v);
Vector2& operator+=(const Vector2& v);
+ Vector2& operator+(const Vector2& v);
+ Vector2& operator-=(const Vector2& v);
+ Vector2& operator-(const Vector2& v);
};
class Vector3 : public Vector2 {
@@ -29,6 +32,10 @@ class Vector3 : public Vector2 {
Vector3(const Vector3& v);
Vector3& operator=(const Vector3& v);
+ Vector3& operator+=(const Vector3& v);
+ Vector3& operator+(const Vector3& v);
+ Vector3& operator-=(const Vector3& v);
+ Vector3& operator-(const Vector3& v);
};
class Vector4 : public Vector3 {
@@ -42,6 +49,10 @@ class Vector4 : public Vector3 {
Vector4(const Vector4& v);
Vector4& operator=(const Vector4& v);
+ Vector4& operator+=(const Vector4& v);
+ Vector4& operator+(const Vector4& v);
+ Vector4& operator-=(const Vector4& v);
+ Vector4& operator-(const Vector4& v);
};
#endif