Convert over to standard glm functions for length, normalize, cross, and dot product

This commit is contained in:
ZappoMan 2013-04-21 22:57:01 -07:00
parent 358efb472d
commit 400ecf6b86

View file

@ -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 {