45 m_n = glm::cross( b, c );
47 if( glm::abs(
m_n.x ) > glm::abs(
m_n.y ) )
49 if( glm::abs(
m_n.x ) > glm::abs(
m_n.z ) )
56 if( glm::abs(
m_n.y ) > glm::abs(
m_n.z ) )
62 int u = (
m_k + 1 ) % 3;
63 int v = (
m_k + 2 ) % 3;
66 float krec = 1.0f /
m_n[
m_k];
73 float reci = 1.0f / ( b[u] * c[v] - b[v] * c[u] );
83 m_n = glm::normalize(
m_n );
149 | ( (
unsigned int) ( aColor.g * 255 ) << 16 )
150 | ( (
unsigned int) ( aColor.b * 255 ) << 8 ) | 0xFF;
159 | ( (
unsigned int) ( aVC0.g * 255 ) << 16 )
160 | ( (
unsigned int) ( aVC0.b * 255 ) << 8 ) | 0xFF;
162 | ( (
unsigned int) ( aVC1.g * 255 ) << 16 )
163 | ( (
unsigned int) ( aVC1.b * 255 ) << 8 ) | 0xFF;
165 | ( (
unsigned int) ( aVC2.g * 255 ) << 16 )
166 | ( (
unsigned int) ( aVC2.b * 255 ) << 8 ) | 0xFF;
179 unsigned int aVertex3ColorRGBA )
195static const unsigned int s_modulo[] = { 0, 1, 2, 0, 1 };
201#define ku s_modulo[m_k + 1]
202#define kv s_modulo[m_k + 2]
211 if( !( ( aHitInfo.
m_tHit > t ) && ( t > 0.0f ) ) )
214 const float hu = O[
ku] + t *
D[
ku] -
A[
ku];
215 const float hv = O[
kv] + t *
D[
kv] -
A[
kv];
226 const float v = gamma;
227 const float u = beta;
229 if( ( u + v ) > 1.0f )
232 if( glm::dot(
D,
m_n ) > 0.0f )
255#define ku s_modulo[m_k + 1]
256#define kv s_modulo[m_k + 2]
265 if( !( ( aMaxDistance > t ) && ( t > 0.0f ) ) )
268 const float hu = O[
ku] + t *
D[
ku] -
A[
ku];
269 const float hv = O[
kv] + t *
D[
kv] -
A[
kv];
280 const float v = gamma;
281 const float u = beta;
283 if( ( u + v ) > 1.0f )
286 if( glm::dot(
D,
m_n ) > 0.0f )
298 return m_bbox.Intersects( aBBox );
308 const SFVEC3F c1 =
SFVEC3F( (
float) ( ( rgbC1 >> 24 ) & 0xFF ) / 255.0f,
309 (
float) ( ( rgbC1 >> 16 ) & 0xFF ) / 255.0f,
310 (
float) ( ( rgbC1 >> 8 ) & 0xFF ) / 255.0f );
311 const SFVEC3F c2 =
SFVEC3F( (
float) ( ( rgbC2 >> 24 ) & 0xFF ) / 255.0f,
312 (
float) ( ( rgbC2 >> 16 ) & 0xFF ) / 255.0f,
313 (
float) ( ( rgbC2 >> 8 ) & 0xFF ) / 255.0f );
314 const SFVEC3F c3 =
SFVEC3F( (
float) ( ( rgbC3 >> 24 ) & 0xFF ) / 255.0f,
315 (
float) ( ( rgbC3 >> 16 ) & 0xFF ) / 255.0f,
316 (
float) ( ( rgbC3 >> 8 ) & 0xFF ) / 255.0f );
318 const float u = aHitInfo.
m_UV.x;
319 const float v = aHitInfo.
m_UV.y;
320 const float w = 1.0f - u - v;
322 return w * c1 + u * c2 + v * c3;
OBJECT_3D(OBJECT_3D_TYPE aObjType)
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.
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...