Commit d5473b22 authored by paps's avatar paps

--no commit message

--no commit message
parent f91956e4
......@@ -20,17 +20,22 @@
#include "LrGeometrySphere.h"
LrGeometrySphere::LrGeometrySphere()
:
LrGeometry()
: LrGeometry(),
m_inside(false)
{
}
LrGeometrySphere::LrGeometrySphere(const LrGeometrySphere& src)
:
LrGeometry(src)
: LrGeometry(src),
m_inside(src.m_inside)
{
}
// ###########################################################################
LrGeometrySphere::LrGeometrySphere(bool inside)
: LrGeometry(),
m_inside(inside)
{
}
LrGeometrySphere::~LrGeometrySphere()
{
}
......@@ -40,12 +45,13 @@ LrGeometrySphere& LrGeometrySphere::operator = (const LrGeometrySphere& src)
if(this==&src)
return *this;
LrGeometry::operator = (src);
m_inside = src.m_inside;
return *this;
}
bool operator == (const LrGeometrySphere& rhs, const LrGeometrySphere& lhs)
{
return (const LrGeometry&)rhs == (const LrGeometry&)lhs
return (const LrGeometry&)rhs == (const LrGeometry&)lhs && rhs.m_inside == lhs.m_inside;
/* and [...] */;
}
......@@ -67,21 +73,38 @@ bool LrGeometrySphere::getIntersection(const LrRay &ray, LrHit *hit, int fragmen
LrVector OC(ray.getOrigin(), LrPoint::ZERO);
Real k = OC * ray.getDirection();
Real h2 = n2 * OC * OC - k*k;
// if (h2 > m_radius * m_radius) si rayon n'est pas 1
if (h2 > n2)
return false;
return false;
// Real delta = sqrt(m_radius * m_radius - h2); si rayon != 1
Real delta = sqrt(n2 - h2);
Real dist = (k - delta)/n2;
Real dist = 0.0;
// si le premier point n'est pas bon, voir avec le second
if ((dist < minBound) || (dist > maxBound))
/*if ((dist < minBound) || (dist > maxBound))
{
dist = k + delta;
if ((dist < minBound) || (dist > maxBound))
return false;
return false;
}*/
if(m_inside)
{
dist = (k + delta)/n2;
if (dist > maxBound)
{
if (dist > maxBound)
return false;
}
}
else
{
dist = (k - delta)/n2;
if ((dist < minBound) || (dist > maxBound))
{
if ((dist < minBound) || (dist > maxBound))
return false;
}
}
if (hit != NULL)
......@@ -100,6 +123,7 @@ bool LrGeometrySphere::getIntersection(const LrRay &ray, LrHit *hit, int fragmen
//uv2xyz(u, v, NULL, &normal, &tangent);
//hit->normal = normal;
hit->normal = LrVector(LrPoint::ZERO,hit->point);
if(m_inside) hit->normal = -hit->normal;
hit->normal.normalize();
hit->tangent = tangent;
}
......
......@@ -34,6 +34,12 @@ public:
* @param src Référence d'un objet LrGeometrySphere.
*/
LrGeometrySphere(const LrGeometrySphere& src);
/**
* @brief Constructeur personnel
* @param inside indique la sphere est vue de l'interieur ou de pas.
*/
LrGeometrySphere(bool inside);
/**
* @brief Destructeur.
......@@ -115,6 +121,7 @@ protected:
LrVector *normal, LrVector *tangent) const;
private:
bool m_inside;
};
#endif
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