From 31539f3af0c7beea865b29fdda0840c79f14710e Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Thu, 7 Mar 2019 19:14:35 -0500 Subject: Import from fieldviz --- include/fml/vec3.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 include/fml/vec3.h (limited to 'include/fml/vec3.h') diff --git a/include/fml/vec3.h b/include/fml/vec3.h new file mode 100644 index 0000000..3460c56 --- /dev/null +++ b/include/fml/vec3.h @@ -0,0 +1,39 @@ +#ifndef VEC3_H +#define VEC3_H +#include + +#include "fml.h" + +namespace fml { + class vec3 { + public: + scalar v[3]; + public: + vec3(); + vec3(scalar x); + vec3(scalar x, scalar y, scalar z); + scalar &operator[](int index); + scalar operator[](int index) const; + vec3 operator*(scalar scale) const; + vec3 operator/(scalar scale) const; + vec3 operator+(const vec3 &other) const; + vec3 operator-(const vec3 &other) const; + vec3 operator-() const; + const vec3 &operator*=(scalar scale); + const vec3 &operator/=(scalar scale); + const vec3 &operator+=(const vec3 &other); + const vec3 &operator-=(const vec3 &other); + scalar magnitude() const; + scalar magnitudeSquared() const; + vec3 normalize() const; + scalar dot(const vec3 &other) const; + vec3 cross(const vec3 &other) const; + }; + + vec3 operator*(scalar scale, const vec3 &v); + + std::ostream &operator<<(std::ostream &output, const vec3 &v); + std::istream &operator>>(std::istream &input, vec3 &v); +} + +#endif -- cgit v1.1