NLMISC::CTriangle Class Reference

#include <triangle.h>

Inheritance diagram for NLMISC::CTriangle:

NLMISC::CTriangleColor NLMISC::CTriangleColorUV NLMISC::CTriangleUV NL3D::CTrianglePatch

Detailed Description

A simple triangles of 3 points.
Author:
Lionel Berenguier

Nevrax France

Date:
2000

Definition at line 48 of file triangle.h.

Public Member Functions

void computeGradient (float c0, float c1, float c2, CVector &grad) const
 CTriangle (const CVector &a, const CVector &b, const CVector &c)
 Constructor.

 CTriangle ()
 Constructor.

bool intersect (const CVector &p0, const CVector &p1, CVector &hit, const class NLMISC::CPlane &plane) const

Data Fields

CVector V0
CVector V1
CVector V2


Constructor & Destructor Documentation

NLMISC::CTriangle::CTriangle  )  [inline]
 

Constructor.

Definition at line 55 of file triangle.h.

00055 {}

NLMISC::CTriangle::CTriangle const CVector a,
const CVector b,
const CVector c
[inline]
 

Constructor.

Definition at line 57 of file triangle.h.

00057 : V0(a), V1(b), V2(c) {}


Member Function Documentation

void NLMISC::CTriangle::computeGradient float  c0,
float  c1,
float  c2,
CVector grad
const
 

3D Gradient computation. Given 3 values at the 3 corners 'ci' (gouraud, uv....), this method compute the gradients Grad. The formula to compute the interpolated value according to a 3d position 'v' in space is then simply:
c(v)= c0 + grad*(v-V0)

Definition at line 67 of file triangle.cpp.

References NLMISC::CVector::normalize(), NLMISC::CVector::set(), V0, V1, V2, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by NL3D::BuildTangentSpace(), NL3D::CLodCharacterShapeBuild::compile(), NL3D::CTessFace::computeTesselatedPos(), NL3D::CVisualCollisionEntity::computeUvForPos(), and RenderTriangle().

00068 {
00069         // Compute basis for 2D triangle.
00070         CVector         locI, locJ, locK;
00071         locI= V1-V0;
00072         locJ= V2-V0;
00073         locK= locI^locJ;
00074         locK.normalize();
00075         locI.normalize();
00076         locJ= locK^locI;
00077 
00078         // compute triangle in 2D.
00079         CTriangle       tri2D;
00080         tri2D.V0.set(0,0,0);
00081         tri2D.V1.x= (V1-V0)*locI;
00082         tri2D.V1.y= (V1-V0)*locJ;
00083         tri2D.V1.z= 0;
00084         tri2D.V2.x= (V2-V0)*locI;
00085         tri2D.V2.y= (V2-V0)*locJ;
00086         tri2D.V2.z= 0;
00087 
00088         // Compute 2 2D Gradients.
00089         float   dx01= tri2D.V0.x - tri2D.V2.x;
00090         float   dx02= tri2D.V1.x - tri2D.V2.x;
00091         float   dy01= tri2D.V0.y - tri2D.V2.y;
00092         float   dy02= tri2D.V1.y - tri2D.V2.y;
00093         float   dc01= c0 - c2;
00094         float   dc02= c1 - c2;
00095         float   gd= dx02*dy01 - dx01*dy02;
00096 
00097         float   OOgd;
00098         if(gd!=0)
00099                 OOgd= 1.0f/gd;
00100         else
00101                 OOgd= 1;        // for now, do not manage correctly this case.
00102         float   gx, gy;
00103         gx= (dc02*dy01 - dc01*dy02) * OOgd;
00104         gy= (dc01*dx02 - dc02*dx01) * OOgd;
00105 
00106         // transform in 3D.
00107         grad= locI*gx + locJ*gy;
00108 }

bool NLMISC::CTriangle::intersect const CVector p0,
const CVector p1,
CVector hit,
const class NLMISC::CPlane plane
const
 

Intersection detection with a segment. You must pass the normalized plane of the triangle as parameter.

Parameters:
p0 is the first point of the segment.
p1 is the second point of the segment.
hit will receive the coordinate of the intersection if the method returns true.
plane is the plane of the triangle. Build it like this:
CPlane plane; plane.make (triangle.V0, triangle.V1, triangle.V2);
Returns:
true if the segement [p0,p1] intersects the triangle else false.

Referenced by NL3D::CInstanceLighter::computeSunContribution(), NL3D::CZoneLighter::CPointLightRT::testRaytrace(), and NL3D::CInstanceLighter::CPointLightRT::testRaytrace().


Field Documentation

CVector NLMISC::CTriangle::V0
 

Definition at line 51 of file triangle.h.

Referenced by NL3D::CMiniCol::addFaces(), NL3D::CPatch::addTileTrianglesInBBox(), NL3D::CShadowPolyReceiver::addTriangle(), NL3D::CLandscape::appendToShadowPolyReceiver(), NL3D::CLandscape::buildCollideFaces(), NL3D::BuildTangentSpace(), NL3D::CPatchQuadBlock::buildTileTriangles(), NL3D::BuildTriFromMB(), NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CLodCharacterShapeBuild::compile(), NL3D::CZoneLighter::compilePointLightRT(), computeGradient(), NL3D::CTessFace::computeTesselatedPos(), NL3D::CVisualCollisionEntity::computeUvForPos(), NLMISC::CPolygon2D::CPolygon2D(), NL3D::CDriverUser::drawTriangle(), NL3D::CMiniCol::getFaces(), NL3D::CMiniCol::getGroundNormal(), NL3D::CCubeGrid< TCell >::insert(), NL3D::CBSPTree< T >::CBSPNode::insert(), NL3D::CZoneLighter::light(), NL3D::CInstanceLighter::light(), NL3D::CCubeGrid< TCell >::project(), RenderTriangle(), NL3D::CVisualCollisionEntity::snapToGround(), NL3D::CMiniCol::snapToGround(), NL3D::CVisualCollisionEntity::triangleIntersect(), NL3D::CVisualCollisionEntity::triangleIntersect2DCeil(), and NL3D::CVisualCollisionEntity::triangleIntersect2DGround().

CVector NLMISC::CTriangle::V1
 

Definition at line 51 of file triangle.h.

Referenced by NL3D::CMiniCol::addFaces(), NL3D::CPatch::addTileTrianglesInBBox(), NL3D::CShadowPolyReceiver::addTriangle(), NL3D::CLandscape::appendToShadowPolyReceiver(), NL3D::CLandscape::buildCollideFaces(), NL3D::BuildTangentSpace(), NL3D::CPatchQuadBlock::buildTileTriangles(), NL3D::BuildTriFromMB(), NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CLodCharacterShapeBuild::compile(), NL3D::CZoneLighter::compilePointLightRT(), computeGradient(), NL3D::CTessFace::computeTesselatedPos(), NLMISC::CPolygon2D::CPolygon2D(), NL3D::CDriverUser::drawTriangle(), NL3D::CMiniCol::getFaces(), NL3D::CMiniCol::getGroundNormal(), NL3D::CCubeGrid< TCell >::insert(), NL3D::CBSPTree< T >::CBSPNode::insert(), NL3D::CZoneLighter::light(), NL3D::CInstanceLighter::light(), NL3D::CCubeGrid< TCell >::project(), NL3D::CVisualCollisionEntity::snapToGround(), NL3D::CMiniCol::snapToGround(), NL3D::CVisualCollisionEntity::triangleIntersect(), NL3D::CVisualCollisionEntity::triangleIntersect2DCeil(), and NL3D::CVisualCollisionEntity::triangleIntersect2DGround().

CVector NLMISC::CTriangle::V2
 

Definition at line 51 of file triangle.h.

Referenced by NL3D::CMiniCol::addFaces(), NL3D::CPatch::addTileTrianglesInBBox(), NL3D::CShadowPolyReceiver::addTriangle(), NL3D::CLandscape::appendToShadowPolyReceiver(), NL3D::CLandscape::buildCollideFaces(), NL3D::BuildTangentSpace(), NL3D::CPatchQuadBlock::buildTileTriangles(), NL3D::BuildTriFromMB(), NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CLodCharacterShapeBuild::compile(), NL3D::CZoneLighter::compilePointLightRT(), computeGradient(), NL3D::CTessFace::computeTesselatedPos(), NLMISC::CPolygon2D::CPolygon2D(), NL3D::CDriverUser::drawTriangle(), NL3D::CMiniCol::getFaces(), NL3D::CMiniCol::getGroundNormal(), NL3D::CCubeGrid< TCell >::insert(), NL3D::CBSPTree< T >::CBSPNode::insert(), NL3D::CZoneLighter::light(), NL3D::CInstanceLighter::light(), NL3D::CCubeGrid< TCell >::project(), NL3D::CVisualCollisionEntity::snapToGround(), NL3D::CMiniCol::snapToGround(), NL3D::CVisualCollisionEntity::triangleIntersect(), NL3D::CVisualCollisionEntity::triangleIntersect2DCeil(), and NL3D::CVisualCollisionEntity::triangleIntersect2DGround().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:38:47 2004 for NeL by doxygen 1.3.6