Commit 1c5389e2 authored by maesius's avatar maesius

Grille reguliere : ok, mais plante encore.

parent 8e27f324
......@@ -17,8 +17,12 @@
#include <iostream>
#include "LrBinderRegularGrid.h"
#include "LrGeometry.h"
#include "LrGeometry.h"
#include "LrEntity.h"
#define NEXT_X 1
#define NEXT_Y 2
#define NEXT_Z 3
using namespace std;
......@@ -51,7 +55,14 @@ m_nbVoxelZ(nbVoxelZ),
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;
......@@ -124,6 +134,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 &&
......@@ -194,10 +211,10 @@ bool LrBinderRegularGrid::getIntersection(const LrRay &ray, LrHit *hit, Real min
}
}
else
}
else
{
if ((orig.x < min.x) || (orig.x > max.x))
if ((orig.x < min.x) || (orig.x > max.x))
{
return false;
}
......@@ -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;
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 {
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;
/*
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)
maxbound = hit->distance;
else
break;
}
}
}
return false;
*/
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment