#163820 - 3dfx - Sun Oct 12, 2008 11:28 pm
Hey guys I'm using the ray plane collision test based on http://www.flipcode.com/archives/Point-Plane_Collision.shtml .
And I'm having a rough time getting it working properly.
It seems to only work when the normal is 0, 4096, 0.
I checked it(made it print out stuff) and seems like distToIntersection doesnt give me the right result. Any ideas why?
And I'm having a rough time getting it working properly.
Code: |
typedef struct { int32 x, y, z; }VECTOR32; typedef struct { VECTOR32 points[4]; VECTOR32 normal; int d; }Plane; void calcPlaneD(Plane *plane){ plane->d = dotProd(&plane->points[0], &plane->normal); } void calcPlaneNormal(Plane *plane){ VECTOR32 points[2]; points[0].x = plane->points[1].x - plane->points[0].x; points[0].y = plane->points[1].y - plane->points[0].y; points[0].z = plane->points[1].z - plane->points[0].z; points[1].x = plane->points[2].x - plane->points[1].x; points[1].y = plane->points[2].y - plane->points[1].y; points[1].z = plane->points[2].z - plane->points[1].z; plane->normal.x = mulf32(points[0].y, points[1].z) - mulf32(points[1].y, points[0].z); plane->normal.y = mulf32(points[0].z, points[1].x) - mulf32(points[1].z, points[0].x); plane->normal.z = mulf32(points[0].x, points[1].y) - mulf32(points[1].x, points[0].y); normalizeVector(&plane->normal); } int32 dotProd(VECTOR32 *one, VECTOR32 *two) { return mulf32(one->x, two->x) + mulf32(one->y, two->y) + mulf32(one->z, two->z); } void normalizeVector(VECTOR32 *vec) { // magnitude = sqrt ( Ax^2 + Ay^2 + Az^2 ) int32 magnitude = sqrtf32( mulf32(vec->x, vec->x) + mulf32(vec->y, vec->y) + mulf32(vec->z, vec->z) ); vec->x = divf32(vec->x, magnitude); vec->y = divf32(vec->y, magnitude); vec->z = divf32(vec->z, magnitude); } int distToIntersection(Plane *plane, VECTOR32 *startingPt, VECTOR32 *dir){ // int32 denom = dotProd(&plane->normal, dir); if(absV(denom == 0)){ return -1; } int numer = dotProd(&plane->normal, startingPt) + plane->d; return (-div32(numer, denom)); } |
It seems to only work when the normal is 0, 4096, 0.
I checked it(made it print out stuff) and seems like distToIntersection doesnt give me the right result. Any ideas why?