Chapter 2. Detecting Ray-Surface Intersections

Prepare


    #include <r3freng.h>

    /* create rendering engine */
    rend = R3New(R3CLID_FRENGINE, R3TAG_END);

    /* pass scene to the renderer */
    R3DoA(rend, R3FRM_BEGINWORLD, NULL);
    R3DoA(root, R3PRIMM_RENDER,
          R3PRIMA_RenderEngine, rend,
          R3PRIMA_RenderAlways, TRUE,
          R3TAG_END);
    R3DoA(dreng, R3FRM_ENDWORLD, NULL);

If you need to cast several rays, you should used optimized ray-surface intersection


    R3DoA(rend, R3FRM_OPTIMIZEHIT, NULL);

And then you are ready to shoot rays:


    for(...) {
        fromp = ..;
        dir = ..;
        hitfound = R3DoA3(rend, R3FRM_FINDHIT, &fromp, &dir, &intersectp);
        if(hitfound) {
            R3DoA(rend, R3FRM_EVALHITGEOMETRY, &normal);
            ...