Commit 3e670ae3 authored by axel's avatar axel

mise en forme de code

parent c8e17f5f
......@@ -18,17 +18,12 @@
#include "config.h"
#endif
#include <stdlib.h>
#include "LrSceneRayTracing.h"
#include "LrOptic.h"
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
/*---------------------------------------------------------------------------*
* Constructeurs et destructeurs *
*---------------------------------------------------------------------------*/
// ############################################################################
LrSceneRayTracing::LrSceneRayTracing()
:
......@@ -39,6 +34,8 @@ LrSceneRayTracing::LrSceneRayTracing()
{
}
// ############################################################################
LrSceneRayTracing::LrSceneRayTracing(const LrSceneRayTracing &source)
:
LrScene(source),
......@@ -49,11 +46,8 @@ LrSceneRayTracing::LrSceneRayTracing(const LrSceneRayTracing &source)
{
}
LrSceneRayTracing* LrSceneRayTracing::clone() const
{
return new LrSceneRayTracing(*this);
}
// ############################################################################
LrSceneRayTracing::LrSceneRayTracing(const LrEntityList &entities,
const LrEntityList &lights,
LrBinder *binder,
......@@ -70,13 +64,13 @@ LrSceneRayTracing::LrSceneRayTracing(const LrEntityList &entities,
{
}
// ############################################################################
LrSceneRayTracing::~LrSceneRayTracing()
{
}
/*---------------------------------------------------------------------------*
* Operateur(s) d'assignement *
*---------------------------------------------------------------------------*/
// ############################################################################
LrSceneRayTracing&
LrSceneRayTracing::operator = (const LrSceneRayTracing &source)
......@@ -93,9 +87,8 @@ LrSceneRayTracing&
return *this;
}
/*---------------------------------------------------------------------------*
* Méthodes *
*---------------------------------------------------------------------------*/
// ############################################################################
void LrSceneRayTracing::initialize()
{
LrEntityList::const_iterator itObjs;
......@@ -107,9 +100,12 @@ void LrSceneRayTracing::initialize()
}
}
// ############################################################################
void LrSceneRayTracing::generateImagePart(int lOffset, int lNb)
{
int nbRayPerPixel = (m_antialiasing->getCoeffAA()*m_antialiasing->getCoeffAA());
int coeffAA = m_antialiasing->getCoeffAA();
int nbRayPerPixel = (coeffAA*coeffAA);
srand(time(NULL));
......@@ -119,32 +115,24 @@ void LrSceneRayTracing::generateImagePart(int lOffset, int lNb)
{
for (int c = 0; c < m_image->getWidth(); c++)
{
// if(l == 300 && c == 300)
// {
// int a = 0;
// }
LrColor pixel = LrColor::BLACK;
for (int i = 0; i < nbRayPerPixel; i++)
{
float u, v;
LrRay ray;
LrColor color;
// tirer u et v dans le pixel (l, c)
m_antialiasing->getCoordUV(m_antialiasing->getCoeffAA(),i,&u,&v);
// cout<<"U avant : "<<u<<" V avant : "<<v<<endl;
u = ((c + u) / m_image->getWidth()) * 2 -1;
v = ((l + v) / m_image->getHeight()) * 2 -1;
// cout<<"U : "<<u<<" V : "<<v<<endl;
float u, v;
LrRay ray;
LrColor color;
// tirer u et v dans le pixel (l, c)
m_antialiasing->getCoordUV(coeffAA,i,&u,&v);
u = ((c + u) / m_image->getWidth()) * 2 -1;
v = ((l + v) / m_image->getHeight()) * 2 -1;
ray = m_camera->getRay(u, v);
ray = m_camera->getRay(u, v);
color = computeImageRay(ray, m_nbRebonds);
color = computeImageRay(ray, m_nbRebonds);
pixel += color;
pixel += color;
}
......@@ -160,6 +148,8 @@ void LrSceneRayTracing::generateImagePart(int lOffset, int lNb)
}
}
// ############################################################################
LrColor LrSceneRayTracing::computeImageRay(const LrRay &ray, int nbRebonds)
{
LrColor colorResult = LrColor::BLACK;
......@@ -177,15 +167,15 @@ LrColor LrSceneRayTracing::computeImageRay(const LrRay &ray, int nbRebonds)
coefSpecular = (hit.optic)->getSpecular(hit.u,hit.v);
if (coefSpecular > 0 && nbRebonds > 0)
{
LrRay newRay;
//calcul du rayon miroir du rayon lancé au niveau du point d'impact
//d' = d - 2(d.N).N
Real k = ray.getDirection()*hit.normal;
LrVector v_reflect = ray.getDirection()-(2*(k)*hit.normal);
LrPoint tmpOrig = LrPoint::translate(hit.point, EPSILON * hit.normal);
newRay = LrRay(v_reflect,tmpOrig);
colorReflected += computeImageRay(newRay, --nbRebonds);
colorReflected = colorReflected * coefSpecular;
LrRay newRay;
//calcul du rayon miroir du rayon lancé au niveau du point d'impact
//d' = d - 2(d.N).N
Real k = ray.getDirection()*hit.normal;
LrVector v_reflect = ray.getDirection()-(2*(k)*hit.normal);
LrPoint tmpOrig = LrPoint::translate(hit.point, EPSILON * hit.normal);
newRay = LrRay(v_reflect,tmpOrig);
colorReflected += computeImageRay(newRay, --nbRebonds);
colorReflected = colorReflected * coefSpecular;
}
//On recupere la couleur du rayon réfracté
......@@ -209,40 +199,46 @@ LrColor LrSceneRayTracing::computeImageRay(const LrRay &ray, int nbRebonds)
return colorResult;
}
// ############################################################################
LrColor LrSceneRayTracing::computeFromSource(const LrRay &ray, LrHit &hit)
{
LrColor colorResult;
colorResult = LrColor::BLACK;
LrColor colorResult;
colorResult = LrColor::BLACK;
LrEntityList::const_iterator itObjs;
LrEntityList::const_iterator itObjs;
//on parcours la liste des lumieres
for(itObjs = m_lights.begin(); itObjs != m_lights.end(); itObjs++)
{
LrPoint tmpOrig = LrPoint::translate(hit.point, EPSILON * hit.normal);
//on parcours la liste des lumieres
for(itObjs = m_lights.begin(); itObjs != m_lights.end(); itObjs++)
{
LrPoint tmpOrig = LrPoint::translate(hit.point, EPSILON * hit.normal);
int nbRayOnLight=((LrEntityLight*)(*itObjs))->getNbRay();
for(int i=0;i<nbRayOnLight;i++)
int nbRayOnLight=((LrEntityLight*)(*itObjs))->getNbRay();
for(int i=0;i<nbRayOnLight;i++)
{
//vecteur du point d'impact vers la lumiere
LrVector vectorLight(tmpOrig, ((LrEntityLight*)(*itObjs))->getPos());
Real dist = vectorLight.getNorme();
LrColor colorTmp = LrColor::BLACK;
vectorLight.normalize();
if ((vectorLight*hit.normal) > 0.0f)
{
//vecteur du point d'impact vers la lumiere
LrVector vectorLight(tmpOrig, ((LrEntityLight*)(*itObjs))->getPos());
Real dist = vectorLight.getNorme();
LrColor colorTmp = LrColor::BLACK;
vectorLight.normalize();
if ((vectorLight*hit.normal) > 0.0f)
{
LrRay rayLight(vectorLight, tmpOrig);
LrRay rayLight(vectorLight, tmpOrig);
if (m_binder->getIntersection(rayLight, NULL, 0.0f, dist) == false)
{
colorTmp += (((LrEntityLight*)(*itObjs))->getColor())*hit.optic->compute(rayLight,-ray.getDirection(),hit.normal,hit.tangent,hit.u,hit.v);
}
if (m_binder->getIntersection(rayLight, NULL, 0.0f, dist) == false)
{
colorTmp += (((LrEntityLight*)(*itObjs))->getColor())*
hit.optic->compute(rayLight,-ray.getDirection(),
hit.normal,hit.tangent,
hit.u,hit.v);
}
colorResult += colorTmp/nbRayOnLight;
}
}
return colorResult /*/ m_lights.size()*/;
colorResult += colorTmp/nbRayOnLight;
}
}
return colorResult;
}
// ############################################################################
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