Commit 1c5389e2 authored by maesius's avatar maesius
Browse files

Grille reguliere : ok, mais plante encore.

parent 8e27f324
Loading
Loading
Loading
Loading
+172 −33
Original line number Diff line number Diff line
@@ -18,7 +18,11 @@
#include <iostream>
#include "LrBinderRegularGrid.h"
#include "LrGeometry.h"
#include "LrEntity.h"

#define NEXT_X 1
#define NEXT_Y 2
#define NEXT_Z 3

using namespace std;

@@ -52,6 +56,13 @@ m_lenBinder(),
m_lenVoxel(),
m_tabVoxel(nbVoxelX*nbVoxelY*nbVoxelZ)
{

    for(unsigned int i = 0; i < m_tabVoxel.size(); i++) {

        m_tabVoxel[i] = std::vector<LrInfoVoxel>();

    }

    initBinder();
}

@@ -67,7 +78,6 @@ void LrBinderRegularGrid::initBinder()
    Real lenVoxelX, lenVoxelY, lenVoxelZ;
    LrPoint minTMP, maxTMP;
    int nbFragments;
    int numVoxelMin, numVoxelMax;
    int minVoxelI, minVoxelJ, minVoxelK;
    int maxVoxelI, maxVoxelJ, maxVoxelK;
    LrInfoVoxel infoVoxel;
@@ -125,6 +135,8 @@ void LrBinderRegularGrid::initBinder()
                        int numCase = (i + m_nbVoxelX * (j + k * m_nbVoxelY));
                        m_tabVoxel[numCase].push_back(infoVoxel);



                    }
                }
            }
@@ -143,7 +155,12 @@ bool LrBinderRegularGrid::getIntersection(const LrRay &ray, LrHit *hit, Real min
    LrVector dir = ray.getDirection();
    LrPoint pointEntry;
    int curVoxelX, curVoxelY, curVoxelZ;

    int vX, vY, vZ;
    int incVoxelX, incVoxelY, incVoxelZ;
    Real dx, dy, dz, Dx, Dy, Dz;
    int curLineVoxel;
    bool fin, intersection, impact;
    int next;

    if (orig.x>min.x && orig.x<max.x &&
        orig.y>min.y && orig.y<max.y &&
@@ -319,31 +336,153 @@ bool LrBinderRegularGrid::getIntersection(const LrRay &ray, LrHit *hit, Real min



    // Initialisation de la progression
    // ## Initialisation de la progression en X
    if (dir.x > EPSILON) {

            vX = 1;
            incVoxelX = 1;

            dx = m_lenVoxel.x / dir.x;
            Dx = (min.x + m_lenVoxel.x * (curVoxelX+1) - orig.x) / dir.x;

    } else if (dir.x < EPSILON) {

            vX = -1;
            incVoxelX = -1;

            dx = m_lenVoxel.x / dir.x;
            Dx = (min.x + m_lenVoxel.x * (curVoxelX) - orig.x) / dir.x;

    } else {

            Dx = INFINITY;

    }

        // ## Initialisation de la progression en Y
    if (dir.y > EPSILON) {

            vY = 1;
            incVoxelY = m_nbVoxelX;

            dy = m_lenVoxel.y / dir.y;
            Dy = (min.y + m_lenVoxel.y * (curVoxelY+1) - orig.y) / dir.y;

    } else if (dir.y < EPSILON) {

            vY = -1;
            incVoxelY = -m_nbVoxelX;

            dy = m_lenVoxel.y / dir.y;
            Dy = (min.y + m_lenVoxel.y * (curVoxelY) - orig.y) / dir.y;

    } else {

            Dy = INFINITY;

    }


    // ## Initialisation de la progression en Z
    if (dir.z > EPSILON) {

            vZ = 1;
            incVoxelZ = m_nbVoxelX * m_nbVoxelY;

            dz = m_lenVoxel.z / dir.z;
            Dz = (min.z + m_lenVoxel.z * (curVoxelZ+1) - orig.z) / dir.z;

    } else if (dir.z < EPSILON) {

            vZ = -1;
            incVoxelZ = -(m_nbVoxelX * m_nbVoxelY);

            dz = m_lenVoxel.z / dir.z;
            Dz = (min.z + m_lenVoxel.z * (curVoxelZ) - orig.z) / dir.z;

    } else {

            Dz = INFINITY;

    }

    // Progression
    curLineVoxel = curVoxelX + m_nbVoxelX * (curVoxelY  + m_nbVoxelY * curVoxelZ);
    fin = false;

/*
    do {

        minbound = maxbound;

        bool intersection, oneintersect = false;
        for(LrEntityList::const_iterator itObjs = m_liste_objets.begin(); itObjs != m_liste_objets.end(); itObjs++)
        {
            intersection = (*itObjs)->getIntersection(ray, hit, minbound, maxbound);
            if(intersection)
            {
                oneintersect=true;
                if(hit != NULL)
        if (Dx < Dy && Dx < Dz) {
            maxbound = Dx;
            next = NEXT_X;
        } else if (Dy <Dz) {
            maxbound = Dy;
            next = NEXT_Y;
        } else {
            maxbound = Dz;
            next = NEXT_Z;
        }

        intersection = false;
        for (unsigned int i = 0; i < m_tabVoxel[curLineVoxel].size(); i++) {

            LrEntity* entity = m_tabVoxel[curLineVoxel][i].m_entite;
            int numFrag = m_tabVoxel[curLineVoxel][i].m_numFragment;

            impact = entity->getIntersection(ray, hit, numFrag, minbound-EPSILON, maxbound+EPSILON);
            intersection = intersection || impact;


            if(hit != NULL) {
                maxbound = hit->distance;
                else
            } else {
                break;
            }

        }

    if (intersection) {
        return true;
    }

    switch(next) {

     case NEXT_X :
            curVoxelX += vX;
            if ((curVoxelX == -1) || (curVoxelX>=m_nbVoxelX)) {
                fin = false;
            }
            curLineVoxel += incVoxelX;
            Dx += dx;
            break;

    case NEXT_Y :
            curVoxelY += vY;
            if ((curVoxelY == -1) || (curVoxelY>=m_nbVoxelY)) {
                fin = false;
            }
            curLineVoxel += incVoxelY;
            Dy += dy;
            break;

    case NEXT_Z :
            curVoxelZ += vZ;
            if ((curVoxelZ == -1) || (curVoxelZ>=m_nbVoxelZ)) {
                fin = false;
            }
            curLineVoxel += incVoxelZ;
            Dz += dz;
            break;

    default : break;

    }

    } while (!fin);


    return false;

    */
}