diff options
Diffstat (limited to 'src/MathUtil.cpp')
-rw-r--r-- | src/MathUtil.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/MathUtil.cpp b/src/MathUtil.cpp index 3905450..8ea3599 100644 --- a/src/MathUtil.cpp +++ b/src/MathUtil.cpp @@ -22,14 +22,23 @@ namespace Zoom { +const float MathUtil::EPSILON = 1E-6; + +vmml::vec3f MathUtil::Plane::intersection(const vmml::vec3f &p, const vmml::vec3f &dir) const { + float r = (d - p.dot(normal))/dir.dot(normal); + + return p + r*dir; +} + + vmml::mat4f MathUtil::perspective(float fovy, float aspect, float zNear) { float f = 1/std::tan(fovy*M_PI/360); vmml::mat4f ret(vmml::mat4f::ZERO); ret[0][0] = f/aspect; ret[1][1] = f; - ret[2][2] = -1; - ret[2][3] = -2*zNear; + ret[2][2] = EPSILON-1; + ret[2][3] = (EPSILON-2)*zNear; ret[3][2] = -1; return ret; |