summaryrefslogtreecommitdiffstats
path: root/src/MathUtil.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/MathUtil.h')
-rw-r--r--src/MathUtil.h42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/MathUtil.h b/src/MathUtil.h
index 892d5dc..3f7ba90 100644
--- a/src/MathUtil.h
+++ b/src/MathUtil.h
@@ -30,6 +30,24 @@ class MathUtil {
public:
static const float EPSILON;
+ class Ray {
+ public:
+ Ray() : vertex(vmml::vec3f::ZERO), dir(vmml::vec3f::ZERO) {}
+ Ray(const vmml::vec3f &v, const vmml::vec3f &d) : vertex(v), dir(d) {}
+
+ const vmml::vec3f& getVertex() const {
+ return vertex;
+ }
+
+ const vmml::vec3f& getDirection() const {
+ return dir;
+ }
+
+ private:
+ vmml::vec3f vertex;
+ vmml::vec3f dir;
+ };
+
class Plane {
public:
Plane(const vmml::vec3f &n = vmml::vec3f::ZERO, float d0 = 0) : normal(n), d(d0) {}
@@ -76,35 +94,21 @@ class MathUtil {
}
+ float distance(const vmml::vec3f &v) {
+ return (normal.dot(v) - d);
+ }
+
const vmml::vec3f& getNormal() const {
return normal;
}
- vmml::vec3f intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const;
+ vmml::vec3f intersection(const Ray &ray) const;
private:
vmml::vec3f normal;
float d;
};
- class Ray {
- public:
- Ray() : vertex(vmml::vec3f::ZERO), dir(vmml::vec3f::ZERO) {}
- Ray(const vmml::vec3f &v, const vmml::vec3f &d) : vertex(v), dir(d) {}
-
- const vmml::vec3f& getVertex() const {
- return vertex;
- }
-
- const vmml::vec3f& getDirection() const {
- return dir;
- }
-
- private:
- vmml::vec3f vertex;
- vmml::vec3f dir;
- };
-
static vmml::mat4f perspective(float fovy, float aspect, float zNear);
private: