GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


ray plane intersection by SUNSTAR
1
 
bool distRayPlane(vec3 vRayOrigin, vec3 vRayVector, vec3 vPlaneNormal, float fPlaneDist, vec3 vIntersection)
{
    float fCosAlpha;
    float fDeltaDist;
    float fRayDist;

    fCosAlpha = DotProduct(vRayVector ,  vPlaneNormal);

    if (fCosAlpha==0) return false; //ray is parallel to the plane

    fDeltaDist = fPlaneDist - DotProduct(vRayOrigin,vPlaneNormal);
    fRayDist = fDeltaDist/fCosAlpha;

    vIntersection = vRayOrigin + ScalarProduct(vRayVector, fRayDist);
    return true;
}