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/fml.h | 10 ++++++++++ include/fml/quat.h | 28 ++++++++++++++++++++++++++++ include/fml/vec2.h | 38 ++++++++++++++++++++++++++++++++++++++ include/fml/vec3.h | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 include/fml/fml.h create mode 100644 include/fml/quat.h create mode 100644 include/fml/vec2.h create mode 100644 include/fml/vec3.h (limited to 'include/fml') diff --git a/include/fml/fml.h b/include/fml/fml.h new file mode 100644 index 0000000..046db5a --- /dev/null +++ b/include/fml/fml.h @@ -0,0 +1,10 @@ +/* + * libfml: Frank's Math Library + * + * Copyright (C) 2019 Franklin Wei + */ + +typedef float scalar; + +#include "quat.h" +#include "vec3.h" diff --git a/include/fml/quat.h b/include/fml/quat.h new file mode 100644 index 0000000..14c966e --- /dev/null +++ b/include/fml/quat.h @@ -0,0 +1,28 @@ +#ifndef QUAT_H +#define QUAT_H + +#include "fml.h" +#include + +namespace fml { + class quat { + public: + scalar w, x, y, z; + public: + quat(scalar w, scalar x, scalar y, scalar z); + quat(scalar x, scalar y, scalar z); + quat(scalar w, vec3 vec); + quat(vec3 vec); + quat(); + + operator vec3(); + + quat conjugate() const; + + static quat from_angleaxis(scalar angle, vec3 axis); + }; + + quat operator*(const quat &, const quat &); + std::ostream &operator<<(std::ostream &os, const quat &); +} +#endif diff --git a/include/fml/vec2.h b/include/fml/vec2.h new file mode 100644 index 0000000..166b99c --- /dev/null +++ b/include/fml/vec2.h @@ -0,0 +1,38 @@ +#ifndef VEC2_H +#define VEC2_H +#include + +#include "fml.h" + +namespace fml { + class vec2 { + public: + scalar v[2]; + public: + vec2(); + vec2(scalar x); + vec2(scalar x, scalar y); + scalar &operator[](int index); + scalar operator[](int index) const; + vec2 operator*(scalar scale) const; + vec2 operator/(scalar scale) const; + vec2 operator+(const vec2 &other) const; + vec2 operator-(const vec2 &other) const; + vec2 operator-() const; + const vec2 &operator*=(scalar scale); + const vec2 &operator/=(scalar scale); + const vec2 &operator+=(const vec2 &other); + const vec2 &operator-=(const vec2 &other); + scalar magnitude() const; + scalar magnitudeSquared() const; + vec2 normalize() const; + scalar dot(const vec2 &other) const; + }; + + vec2 operator*(scalar scale, const vec2 &v); + + std::ostream &operator<<(std::ostream &output, const vec2 &v); + std::istream &operator>>(std::istream &input, vec3 &v); +} + +#endif 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