| 86 | } |
| 87 | |
| 88 | bool PrimitiveEvaluator::signedDistance( const Imath::V3f &p, float &distance, Result *result ) const |
| 89 | { |
| 90 | distance = 0.0f; |
| 91 | |
| 92 | bool success = closestPoint( p, result ); |
| 93 | if ( !success ) |
| 94 | { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | float planeConstant = result->normal().dot( result->point() ); |
| 99 | float sign = result->normal().dot( p ) - planeConstant; |
| 100 | |
| 101 | distance = (result->point() - p ).length() * (sign < std::numeric_limits<float>::epsilon() ? -1.0 : 1.0 ); |
| 102 | |
| 103 | return true; |
| 104 | } |