[Plib-users] <<Code review>> ssgEntity::isectTest ( sgSphere *s, sgMat4 m, int testNeeded )
Brought to you by:
sjbaker
From: Rahul C. <rah...@ya...> - 2000-02-29 04:13:18
|
I was just going through the code of SSG and saw something interesting in the following: ssgCullResult ssgEntity::isectTest ( sgSphere *s, sgMat4 m, int testNeeded ) In the above member function you are finding out the delta distances (in x, y and z direction) between the centers of two spheres and trying to see whether delta distance in any direction is greater than the sum of the radii. The code currently looks like: sgVec3 center_vec ; float sum_radii = s->getRadius() + tmp.getRadius() ; sgSubVec3 ( center_vec, s->getCenter(), tmp.getCenter() ) ; if ( center_vec[0] > sum_radii || center_vec[1] > sum_radii || center_vec[2] > sum_radii ) { return SSG_OUTSIDE ; } I think the last line should be modified to take absolute values of center_vec[0], center_vec[1] and center_vec[2] Next thing ssg code does is taking squares of each of the radius, adding them and compares them with the square of the distances between the centers Or in other words, it says if d^2 >= radiousOne^2 + radiousTwo^2 then the given sphere lies outside the entity. (here d is the distance between the two centers of spheres, radiousOne is the radius of the entity sphere and radiousTwo is the radius of second sphere). In stead I think we should say if d^2 >= (radiousOne + radiousTwo)^2 or d >= (radiousOne + radiousTwo) then the given sphere lies outside the entity. In other words the distance between the center of two spheres should be more than or equal to the summation of radii of two spheres for the sphere to be disjoint. Please let me know your thoughts on this. -- Rahul __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com |