summaryrefslogtreecommitdiffstats
path: root/src/MathUtil.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/MathUtil.h')
-rw-r--r--src/MathUtil.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/MathUtil.h b/src/MathUtil.h
index 2376c2d..9e6efc7 100644
--- a/src/MathUtil.h
+++ b/src/MathUtil.h
@@ -20,12 +20,73 @@
#ifndef ZOOM_MATHUTIL_H_
#define ZOOM_MATHUTIL_H_
+#include "Triangle.h"
+
#include <vmmlib/matrix.hpp>
namespace Zoom {
class MathUtil {
public:
+ static const float EPSILON;
+
+ class Plane {
+ public:
+ Plane(const vmml::vec3f &n = vmml::vec3f::ZERO, float d0 = 0) : normal(n), d(d0) {}
+ Plane(const Triangle &t) : normal(t.computeNormal()), d(t.getVertex(0).dot(normal)) {}
+
+ bool contains(const vmml::vec3f &v) const {
+ return (fabsf(normal.dot(v) - d) < EPSILON);
+ }
+
+ bool isBehind(const vmml::vec3f &v) const {
+ return (normal.dot(v) - d) < 0;
+ }
+
+ bool isInFront(const vmml::vec3f &v) const {
+ return (normal.dot(v) - d) > 0;
+ }
+
+
+ bool contains(const Triangle &t) const {
+ for(int i = 0; i < 3; ++i) {
+ if(!contains(t.getVertex(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+ bool isBehind(const Triangle &t) const {
+ for(int i = 0; i < 3; ++i) {
+ if(!isBehind(t.getVertex(i)) && !contains(t.getVertex(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+ bool isInFront(const Triangle &t) const {
+ for(int i = 0; i < 3; ++i) {
+ if(!isInFront(t.getVertex(i)) && !contains(t.getVertex(i)))
+ return false;
+ }
+
+ return true;
+ }
+
+
+ const vmml::vec3f& getNormal() const {
+ return normal;
+ }
+
+ vmml::vec3f intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const;
+
+ private:
+ vmml::vec3f normal;
+ float d;
+ };
+
static vmml::mat4f perspective(float fovy, float aspect, float zNear);
private: