예제 #1
0
Geometry::HitResult<double> Section::
intersectPlane(const Geometry::Ray<double,3>& ray, bool cullBackFace) const
{
    Geometry::Vector<double,3> rayOrig(ray.getOrigin()[0],ray.getOrigin()[1],ray.getOrigin()[2]);
    const Geometry::Vector<double,3>& rayDir = ray.getDirection();

    /* the ray intersects the plane at poing t for which (ray(t)-PlaneOrigin) is
       orthogonal to the normal. See http://softsurfer.com/Archive/algorithm_0104/algorithm_0104B.htm#Line-Plane Intersection
       for nice description */
    double nDotDir = normal * rayDir;

    //exit on back-facing planes if so desired
    if (cullBackFace && nDotDir>0.0)
        return Geometry::HitResult<double>();

    //handle the parallel case
    if (nDotDir>-EPSILON && nDotDir<EPSILON)
    {
        Geometry::Vector<double,3> toOrig    = rayOrig - start;
        double nDotToOrig = normal * toOrig;
        //coincident
        if (nDotToOrig>-EPSILON && nDotToOrig<EPSILON)
            return Geometry::HitResult<double>(0.0);
        //disjoint
        else
            return Geometry::HitResult<double>();
    }

    //compute the intersection parameter
    return Geometry::HitResult<double>((normal * (start - rayOrig)) / nDotDir);
}
예제 #2
0
Geometry::HitResult<double> Section::
intersectRay(const Geometry::Ray<double,3>& ray) const
{
    /* based on "Fast, Minimum Storage Ray/Triangle Intersection" by Tomas
       Moeller and Ben Trumbore */
    Geometry::Vector<double,3> rayOrig(ray.getOrigin()[0],ray.getOrigin()[1],ray.getOrigin()[2]);
    const Geometry::Vector<double,3>& rayDir = ray.getDirection();

    /* begin calculating determinant - also used to calculate U parameter */
    Geometry::Vector<double,3> pvec = Geometry::cross(rayDir, end);
    /* if determinant is near zero, ray lies in plane of triangle */
    Scalar det = start * pvec;

    if (det>-EPSILON && det<EPSILON)
        return Geometry::HitResult<double>();

    Scalar invDet = Scalar(1) / det;

    /* calculate U parameter and test bounds */
    Scalar u = (rayOrig*pvec) * invDet;
    if (u < Scalar(0))
        return Geometry::HitResult<double>();

    /* prepare to test V parameter */
    Geometry::Vector<double,3> qvec = Geometry::cross(rayOrig, start);
    /* calculate V parameter and test bounds */
    Scalar v = (rayDir*qvec) * invDet;
    if (v < Scalar(0))
        return Geometry::HitResult<double>();

    /* calculate t, ray intersects triangle */
    Scalar t = (end*qvec) * invDet;
    return Geometry::HitResult<double>(t);
}
예제 #3
0
bool QtwaylandSurfaceNode::computeLocalSurfaceIntersection(const Geometry::Ray &localRay, QPointF &localIntersection, float &t) const
{
    Geometry::Plane surfacePlane = Geometry::Plane(glm::vec3(0.0f), glm::vec3(0.0f,0.0f,1.0f));
    if(glm::dot(localRay.d, surfacePlane.n) == 0) return false;

    Geometry::Ray transformedRay = localRay.transform(glm::inverse(surfaceTransform()));

    t = surfacePlane.intersect(transformedRay);
    glm::vec3 intersection = transformedRay.solve(t);

    glm::vec3 coords= intersection * glm::vec3(m_surface->size().width(), m_surface->size().height(), 0);
    localIntersection =  QPointF(coords.x, coords.y);

    return true;
}
예제 #4
0
bool WaylandSurfaceNode::computeLocalSurfaceIntersection(const Geometry::Ray &localRay, glm::vec2 &localIntersection, float &t)
{
    Geometry::Plane surfacePlane = Geometry::Plane(glm::vec3(0), glm::vec3(0,0,1));
    if(glm::dot(localRay.d, surfacePlane.n) == 0) return false;

    Geometry::Ray transformedRay = localRay.transform(glm::inverse(surfaceTransform()));

    //transformedRay.print();

    t = surfacePlane.intersect(transformedRay);
    //std::cout << "t = " << t << std::endl;
    glm::vec3 intersection = transformedRay.solve(t);

    //Geometry::printVector(glm::vec3(intersection));

    //transformedRay.print();
    //transformedRay.draw(this, glm::vec3(0,0,1),  surfaceTransform());

    glm::vec3 coords= intersection * glm::vec3(m_surface->size().x, m_surface->size().y, 0);
    localIntersection =  glm::vec2(coords);

    return t >= 0;
}