Skip to content

Commit

Permalink
Check for d and use kmScalars
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Mar 2, 2014
1 parent d6af627 commit b03c1f5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions kazmath/ray3.c
Expand Up @@ -21,12 +21,19 @@ kmRay3* kmRay3FromPointAndDirection(kmRay3* ray, const kmVec3* point, const kmVe

kmBool kmRay3IntersectPlane(kmVec3* pOut, const kmRay3* ray, const kmPlane* plane) {
//t = - (A*org.x + B*org.y + C*org.z + D) / (A*dir.x + B*dir.y + C*dir.z )
double t = -(plane->a * ray->start.x +
plane->b * ray->start.y +
plane->c * ray->start.z + plane->d) / (
plane->a * ray->dir.x +
plane->b * ray->dir.y +
plane->c * ray->dir.z);

kmScalar d = (plane->a * ray->dir.x +
plane->b * ray->dir.y +
plane->c * ray->dir.z);

if(d == 0)
{
return KM_FALSE;
}

kmScalar t = -(plane->a * ray->start.x +
plane->b * ray->start.y +
plane->c * ray->start.z + plane->d) / d;

if(t < 0)
{
Expand Down

0 comments on commit b03c1f5

Please sign in to comment.