II get point on plane
Vector3D point () const {
return (-dist) * n;
}
// classify point int classify ( const Vector3D& p ) const
{
float v = f ( p ) ;
if ( v > EPS )
return IN_FRONT; else
if ( v < -EPS )
return IN_BACK;
return IN_PLANE;
}
// mirror position (point), depends on plane posit, void reflectPos ( Vector3D& v ) const {
v -= (2.0f*((v & n) + dist)) * n;
}
// mirror direction, depends only on plane normal void reflectDir ( Vector3D& v ) const {
v -= (2.0f*(v & n)) * n;
}
void reflectPlane ( Plane& plane ) const {
Vector3D p (-plane.dist * plane.n); // point on plane
reflectDir ( plane.n ); reflectPos ( p );
plane.dist = -(p & plane.n);
plane.computeNearPointMaskAndMainAxis ();
}
void rotate ( const Matrix3D& rot ) {
Vector3D p ( - dist*n );
n = rot * n;
dist = - (p & n) ;
computeNearPointMaskAndMainAxis ();
}
void flip () {
n = -n ;
dist = -dist;
computeNearPointMaskAndMainAxis ();
}
float closestPoint ( const Vector3D& p,
Vector3D& res ) const
{
float distanceToPlane = - dist - (p & n); res = p + distanceToPlane * n; return distanceToPlane;
}
bool intersectByRay (const Vector3D& org,
const Vector3D& dir,floats t) const
{
float numer = - (dist + (org & n)); float denom = dir & n;
if ( fabs ( denom ) < EPS ) return false;
t = numer / denom;
return true;
}
bool intersectByRay ( const Ray& ray, floats t ) const {
float numer = - (dist + (ray.getOrigin () & n)); float denom = ray.getDir () & n;
if ( fabs ( denom ) < EPS ) return false;
Простейшие геометрические алгоритмы и структуры
t = numer / denom; return true;
}
Vector3D makeNearPoint(const Vector3D& minPoint,
const Vector3D& maxPoint) const
{
return Vector3D (
nearPointMask & 1 ? maxPoint.x : minPoint.x, nearPointMask & 2 ? maxPoint.у : minPoint.у, nearPointMask & 4 ? maxPoint.z : minPoint.z );