49 m_n = glm::cross( b, c );
51 if( glm::abs(
m_n.x ) > glm::abs(
m_n.y ) )
53 if( glm::abs(
m_n.x ) > glm::abs(
m_n.z ) )
60 if( glm::abs(
m_n.y ) > glm::abs(
m_n.z ) )
66 int u = (
m_k + 1 ) % 3;
67 int v = (
m_k + 2 ) % 3;
70 float krec = 1.0f /
m_n[
m_k];
77 float reci = 1.0f / (b[u] * c[v] - b[v] * c[u]);
87 m_n = glm::normalize(
m_n );
153 | ( (
unsigned int) ( aColor.g * 255 ) << 16 )
154 | ( (
unsigned int) ( aColor.b * 255 ) << 8 ) | 0xFF;
163 | ( (
unsigned int) ( aVC0.g * 255 ) << 16 )
164 | ( (
unsigned int) ( aVC0.b * 255 ) << 8 ) | 0xFF;
166 | ( (
unsigned int) ( aVC1.g * 255 ) << 16 )
167 | ( (
unsigned int) ( aVC1.b * 255 ) << 8 ) | 0xFF;
169 | ( (
unsigned int) ( aVC2.g * 255 ) << 16 )
170 | ( (
unsigned int) ( aVC2.b * 255 ) << 8 ) | 0xFF;
183 unsigned int aVertex3ColorRGBA )
199static const unsigned int s_modulo[] = { 0, 1, 2, 0, 1 };
205#define ku s_modulo[m_k + 1]
206#define kv s_modulo[m_k + 2]
215 if( !( ( aHitInfo.
m_tHit > t ) && ( t > 0.0f ) ) )
218 const float hu = O[
ku] + t *
D[
ku] -
A[
ku];
219 const float hv = O[
kv] + t *
D[
kv] -
A[
kv];
230 const float v = gamma;
231 const float u = beta;
236 if( glm::dot(
D,
m_n ) > 0.0f )
259#define ku s_modulo[m_k + 1]
260#define kv s_modulo[m_k + 2]
269 if( !( ( aMaxDistance > t ) && ( t > 0.0f ) ) )
272 const float hu = O[
ku] + t *
D[
ku] -
A[
ku];
273 const float hv = O[
kv] + t *
D[
kv] -
A[
kv];
284 const float v = gamma;
285 const float u = beta;
290 if( glm::dot(
D,
m_n ) > 0.0f )
312 const SFVEC3F c1 =
SFVEC3F( (
float) ( ( rgbC1 >> 24 ) & 0xFF ) / 255.0f,
313 (
float) ( ( rgbC1 >> 16 ) & 0xFF ) / 255.0f,
314 (
float) ( ( rgbC1 >> 8 ) & 0xFF ) / 255.0f );
315 const SFVEC3F c2 =
SFVEC3F( (
float) ( ( rgbC2 >> 24 ) & 0xFF ) / 255.0f,
316 (
float) ( ( rgbC2 >> 16 ) & 0xFF ) / 255.0f,
317 (
float) ( ( rgbC2 >> 8 ) & 0xFF ) / 255.0f );
318 const SFVEC3F c3 =
SFVEC3F( (
float) ( ( rgbC3 >> 24 ) & 0xFF ) / 255.0f,
319 (
float) ( ( rgbC3 >> 16 ) & 0xFF ) / 255.0f,
320 (
float) ( ( rgbC3 >> 8 ) & 0xFF ) / 255.0f );
322 const float u = aHitInfo.
m_UV.x;
323 const float v = aHitInfo.
m_UV.y;
324 const float w = 1.0f - u - v;
326 return w * c1 + u * c2 + v * c3;
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
const MATERIAL * m_material
void SetUV(const SFVEC2F &aUV1, const SFVEC2F &aUV2, const SFVEC2F &aUV3)
TRIANGLE(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3)
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
bool Intersects(const BBOX_3D &aBBox) const override
unsigned int m_vertexColorRGBA[3]
void SetColor(const SFVEC3F &aColor)
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
Manage a bounding box defined by two SFVEC3F min max points.
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
void Union(const SFVEC3F &aPoint)
Recalculate the bounding box adding a point.
SFVEC3F GetCenter() const
Return the center point of the bounding box.
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Set bounding box with new parameters.
void Reset()
Reset the bounding box to zero and de-initialize it.
bool Intersects(const BBOX_3D &aBBox) const
Test if a bounding box intersects this box.
Stores the hit information of a ray with a point on the surface of a object.
float m_tHit
( 4) distance
const OBJECT_3D * pHitObject
( 4) Object that was hitted
SFVEC2F m_UV
( 8) 2-D texture coordinates
SFVEC3F m_HitNormal
(12) normal at the hit point
SFVEC3F m_HitPoint
(12) hit position
SFVEC3F at(float t) const
static const unsigned int s_modulo[]
Implement a triangle ray intersection based on article http://www.flipcode.com/archives/Raytracing_To...