aboutsummaryrefslogtreecommitdiff
path: root/include/fml
diff options
context:
space:
mode:
authorFranklin Wei <me@fwei.tk>2019-03-07 19:14:35 -0500
committerFranklin Wei <me@fwei.tk>2019-03-07 19:14:35 -0500
commit31539f3af0c7beea865b29fdda0840c79f14710e (patch)
tree7bea014a44a938f71ea21b3a8ba457b3576348d9 /include/fml
downloadlibfml-31539f3af0c7beea865b29fdda0840c79f14710e.zip
libfml-31539f3af0c7beea865b29fdda0840c79f14710e.tar.gz
libfml-31539f3af0c7beea865b29fdda0840c79f14710e.tar.bz2
libfml-31539f3af0c7beea865b29fdda0840c79f14710e.tar.xz
Import from fieldviz
Diffstat (limited to 'include/fml')
-rw-r--r--include/fml/fml.h10
-rw-r--r--include/fml/quat.h28
-rw-r--r--include/fml/vec2.h38
-rw-r--r--include/fml/vec3.h39
4 files changed, 115 insertions, 0 deletions
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 <iostream>
+
+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 <iostream>
+
+#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 <iostream>
+
+#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