From 400ecf6b86c2b096c93bbea9dd093fdf5ca05011 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 21 Apr 2013 22:57:01 -0700 Subject: [PATCH] Convert over to standard glm functions for length, normalize, cross, and dot product --- libraries/voxels/src/Plane.cpp | 42 ++++++---------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/libraries/voxels/src/Plane.cpp b/libraries/voxels/src/Plane.cpp index 10d1e2fb6b..a5dc9a93bf 100755 --- a/libraries/voxels/src/Plane.cpp +++ b/libraries/voxels/src/Plane.cpp @@ -16,34 +16,6 @@ using voxels_lib::printLog; // These are some useful utilities that vec3 is missing -float length(const glm::vec3& v) { - return((float)sqrt(v.x * v.x + v.y * v.y + v.z * v.z)); -} - -void normalize(glm::vec3& v) { - float len; - len = length(v); - if (len) { - v.x /= len;; - v.y /= len; - v.z /= len; - } -} - -// cross product -glm::vec3 crossProduct(const glm::vec3& lhs, const glm::vec3& rhs) { - glm::vec3 result; - result.x = lhs.y * rhs.z - lhs.z * rhs.y; - result.y = lhs.z * rhs.x - lhs.x * rhs.z; - result.z = lhs.x * rhs.y - lhs.y * rhs.x; - return result; -} - - -float innerProduct(const glm::vec3& v1,const glm::vec3& v2) { - return (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z); -} - void printVec3(const char* name, const glm::vec3& v) { printf("%s x=%f y=%f z=%f\n", name, v.x, v.y, v.z); } @@ -55,23 +27,23 @@ void Plane::set3Points(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 linev1v3 = v3 - v1; // this will be perpendicular to both lines - _normal = crossProduct(linev1v2,linev1v3); - normalize(_normal); + _normal = glm::cross(linev1v2,linev1v3); + glm::normalize(_normal); // this is a point on the plane _point = v2; // the D coefficient from the form Ax+By+Cz=D - _dCoefficient = -(innerProduct(_normal,_point)); + _dCoefficient = -(glm::dot(_normal,_point)); } void Plane::setNormalAndPoint(const glm::vec3 &normal, const glm::vec3 &point) { _point = point; _normal = normal; - normalize(_normal); + glm::normalize(_normal); // the D coefficient from the form Ax+By+Cz=D - _dCoefficient = -(innerProduct(_normal,_point)); + _dCoefficient = -(glm::dot(_normal,_point)); } void Plane::setCoefficients(float a, float b, float c, float d) { @@ -79,7 +51,7 @@ void Plane::setCoefficients(float a, float b, float c, float d) { _normal = glm::vec3(a,b,c); //compute the lenght of the vector - float l = length(_normal); + float l = glm::length(_normal); // normalize the vector _normal = glm::vec3(a/l,b/l,c/l); @@ -89,7 +61,7 @@ void Plane::setCoefficients(float a, float b, float c, float d) { } float Plane::distance(const glm::vec3 &point) const { - return (_dCoefficient + innerProduct(_normal,point)); + return (_dCoefficient + glm::dot(_normal,point)); } void Plane::print() const {