예제 #1
0
optional<Vector3> Plane::intersectLine( const Line3& line, Vector3& target ) {

  auto direction = line.delta();
  auto denominator = normal.dot( direction );

  if ( denominator == 0 ) {
    // line is coplanar, return origin
    if( distanceToPoint( line.start ) == 0 ) {

      target.copy( line.start );
      return target;

    }

    // Unsure if this is the correct method to handle this case.
    return nullptr;

  }

  auto t = - ( line.start.dot( normal ) + constant ) / denominator;

  if( t < 0 || t > 1 ) {

    return nullptr;

  }

  return target.copy( direction ).multiplyScalar( t ).add( line.start );
}
예제 #2
0
파일: Plane.cpp 프로젝트: UIKit0/resinlib
bool Plane::intersectLine(const Line3& line, Vector3* result) const
{
    const Vector3 direction = line.delta();

    float denominator = normal().dot( direction );

    if ( denominator == 0 ) {
        // line is coplanar, return origin
        if ( distanceToPoint( line.start() ) == 0 ) {
            if (result) {
                result->copy( line.start() );
            }
            return true;
        }

        // Unsure if this is the correct method to handle this case.
        return false;
    }

    float t = - ( line.start().dot( normal() ) + constant() ) / denominator;

    if( (t < 0 || t > 1) ) {
        return false;
    }

    if (result)
        result->copy( direction ).multiplyScalar( t ).add( line.start() );

    return true;
}