diff options
Diffstat (limited to 'Vector.h')
-rw-r--r-- | Vector.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Vector.h b/Vector.h new file mode 100644 index 0000000..f884c49 --- /dev/null +++ b/Vector.h @@ -0,0 +1,43 @@ +#ifndef _VECTOR_H_ +#define _VECTOR_H_ + +#include "Vertex.h" + +class Vector : public Vertex { + public: + Vector(float x0 = 0, float y0 = 0, float z0 = 0) : Vertex(x0, y0, z0) {} + Vector(const Vertex &v) : Vertex(v) {} + + Vector operator+(const Vector &v) const { + return Vector(x+v.x, y+v.y, z+v.z); + } + + Vector operator*(float f) const { + return Vector(x*f, y*f, z*f); + } + + Vector operator/(float f) const { + return (*this)*(1/f); + } + + Vector operator-() const { + return Vector(-x, -y, -z); + } + + Vector cross(const Vector &v) const { + return Vector(y*v.z - z*v.y, + z*v.x - x*v.z, + x*v.y - y*v.x); + } + + float dot(const Vector &v) const { + return x*v.x + y*v.y + z*v.z; + } +}; + +static inline Vector operator-(const Vertex &v1, const Vertex &v2) { + return Vector(v1.getX()-v2.getX(), v1.getY()-v2.getY(), v1.getZ()-v2.getZ()); +} + +#endif /*_VECTOR_H_*/ + |