Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added some vector operators

  • Loading branch information...
commit 7d2df3a38671f6e4b254576ced18d397828b8179 1 parent 7c300cc
oy oy authored
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/base/vmath.h
15 src/base/vmath.h
View
@@ -25,12 +25,18 @@ class vector2_base
vector2_base operator -(const vector2_base &v) const { return vector2_base(x-v.x, y-v.y); }
vector2_base operator +(const vector2_base &v) const { return vector2_base(x+v.x, y+v.y); }
vector2_base operator *(const T v) const { return vector2_base(x*v, y*v); }
+ vector2_base operator *(const vector2_base &v) const { return vector2_base(x*v.x, y*v.y); }
+ vector2_base operator /(const T v) const { return vector3_base(x/v, y/v); }
+ vector2_base operator /(const vector2_base &v) const { return vector2_base(x/v.x, y/v.y); }
const vector2_base &operator =(const vector2_base &v) { x = v.x; y = v.y; return *this; }
const vector2_base &operator +=(const vector2_base &v) { x += v.x; y += v.y; return *this; }
const vector2_base &operator -=(const vector2_base &v) { x -= v.x; y -= v.y; return *this; }
const vector2_base &operator *=(const T v) { x *= v; y *= v; return *this; }
+ const vector2_base &operator *=(const vector2_base &v) { x *= v.x; y *= v.y; return *this; }
+ const vector2_base &operator /=(const T v) { x /= v; y /= v; return *this; }
+ const vector2_base &operator /=(const vector2_base &v) { x /= v.x; y /= v.y; return *this; }
bool operator ==(const vector2_base &v) const { return x == v.x && y == v.y; } //TODO: do this with an eps instead
@@ -107,10 +113,14 @@ class vector3_base
vector3_base operator *(const T v) const { return vector3_base(x*v, y*v, z*v); }
vector3_base operator *(const vector3_base &v) const { return vector3_base(x*v.x, y*v.y, z*v.z); }
vector3_base operator /(const T v) const { return vector3_base(x/v, y/v, z/v); }
+ vector3_base operator /(const vector3_base &v) const { return vector3_base(x/v.x, y/v.y, z/v.z); }
const vector3_base &operator +=(const vector3_base &v) { x += v.x; y += v.y; z += v.z; return *this; }
const vector3_base &operator -=(const vector3_base &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
const vector3_base &operator *=(const T v) { x *= v; y *= v; z *= v; return *this; }
+ const vector3_base &operator *=(const vector3_base &v) { x *= v.x; y *= v.y; z *= v.z; return *this; }
+ const vector3_base &operator /=(const T v) { x /= v; y /= v; z /= v; return *this; }
+ const vector3_base &operator /=(const vector3_base &v) { x /= v.x; y /= v.y; z /= v.z; return *this; }
bool operator ==(const vector3_base &v) const { return x == v.x && y == v.y && z == v.z; } //TODO: do this with an eps instead
@@ -180,12 +190,17 @@ class vector4_base
vector4_base operator -() const { return vector4_base(-x, -y, -z, -w); }
vector4_base operator *(const vector4_base &v) const { return vector4_base(x*v.x, y*v.y, z*v.z, w*v.w); }
vector4_base operator *(const T v) const { return vector4_base(x*v, y*v, z*v, w*v); }
+ vector4_base operator /(const vector4_base &v) const { return vector4_base(x/v.x, y/v.y, z/v.z, w/v.w); }
+ vector4_base operator /(const T v) const { return vector4_base(x/v, y/v, z/v, w/v); }
const vector4_base &operator =(const vector4_base &v) { x = v.x; y = v.y; z = v.z; w = v.w; return *this; }
const vector4_base &operator +=(const vector4_base &v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; }
const vector4_base &operator -=(const vector4_base &v) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; }
const vector4_base &operator *=(const T v) { x *= v; y *= v; z *= v; w *= v; return *this; }
+ const vector4_base &operator *=(const vector4_base &v) { x *= v.x; y *= v.y; z *= v.z; w *= v.w; return *this; }
+ const vector4_base &operator /=(const T v) { x /= v; y /= v; z /= v; w /= v; return *this; }
+ const vector4_base &operator /=(const vector4_base &v) { x /= v.x; y /= v.y; z /= v.z; w /= v.w; return *this; }
bool operator ==(const vector4_base &v) const { return x == v.x && y == v.y && z == v.z && w == v.w; } //TODO: do this with an eps instead
Please sign in to comment.
Something went wrong with that request. Please try again.