Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Triangle Class Reference

Defines a Triangle used in a Milkshape3D Model. More...

#include <Triangle.h>

List of all members.

Public Methods

 Triangle (const MS3DTriangle *const triangle, const Model &model)
 Initialize the Triangle using data from the corresponding Milkshape triangle.

const VertexgetVertex (unsigned int which) const
 Retrieve the given Vertex for this Triangle.

const VectorgetNormal () const
 Retrieve the normal of the Triangle.

const VectorgetNormal (unsigned int which) const
 Retrieve the normal for the given Vertex of this Triangle.

const VectorgetTextureCoordinates (unsigned int which) const
 Retrieve the texture coordinates at the given Vertex for this Triangle.

const MatrixgetObjectToTangentSpaceMatrix (unsigned int which) const
 Retrieve the matrix which converts from object to tangent space at the given Vertex for this Triangle.

int getEdgeIndex (unsigned int which) const
 Retrieve the edge index for the given edge for this Triangle.

bool isFacing (const Vector &point) const
 Is this Triangle facing the light?


Protected Attributes

std::vector< const Vertex * > m_vertices
 The Vertex objects which define this Triangle.

Vector m_normal
 The Triangle normal.

std::vector< Vectorm_vertexNormals
 The normals at each Vertex.

std::vector< Vectorm_textureCoordinates
 The texture coordinates at each Vertex.

std::vector< int > m_edgeIndices
 The edge indices for this Triangle.

std::vector< Matrixm_objectToTangentSpace
 Per vertex transform from object to tangent space.

const Modelm_model
 The Model to which this Triangle belongs.


Private Methods

 Triangle (const Triangle &copy)
 Do not allow this Triangle to be copied.

Triangle & operator= (const Triangle &rhs)
 Do not allow this Triangle to be copied.


Friends

std::ostream & operator<< (std::ostream &out, const Triangle &triangle)
 Insertion operator for this Triangle into an output stream.


Detailed Description

Defines a Triangle used in a Milkshape3D Model.


Constructor & Destructor Documentation

Triangle::Triangle const MS3DTriangle *const    triangle,
const Model   model
 

Initialize the Triangle using data from the corresponding Milkshape triangle.


Member Function Documentation

const Vector & Triangle::getTextureCoordinates unsigned int    which const
 

Retrieve the texture coordinates at the given Vertex for this Triangle.

const Matrix & Triangle::getObjectToTangentSpaceMatrix unsigned int    which const
 

Retrieve the matrix which converts from object to tangent space at the given Vertex for this Triangle.

int Triangle::getEdgeIndex unsigned int    which const
 

Retrieve the edge index for the given edge for this Triangle.

bool Triangle::isFacing const Vector   point const
 

Is this Triangle facing the light?

The determination is made by computing the angle between the Triangle's Normal and the direction from the light to one of the Triangle's Vertices. If this angle is between 180 and 360, it is facing away otherwise it is facing towards.


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &    out,
const Triangle &    triangle
[friend]
 

Insertion operator for this Triangle into an output stream.


Member Data Documentation

std::vector<int> Triangle::m_edgeIndices [protected]
 

The edge indices for this Triangle.

The edge index is defined as the combination of the two Vertex indices for the two ends of that edge. For example, say this Triangle has Vertex indices 0xA3, 0x17 and 0xF8. The first edge is made of Vertices (0xA3, 0x17), the second edge (0x17, 0xF8) and the third edge (0xF8, 0xA3). The edge index of the first edge is 0xA317, the second edge is 0x17F8 and the third edge is 0xF8A3.

Each edge index is therefore guaranteed to be shared between two Triangles if they share the corresponding Vertices. Furthermore, since we know that all Triangles vertices are listed in counter-clockwise order, the edge indices will always be created in the appropriate order.

std::vector<Matrix> Triangle::m_objectToTangentSpace [protected]
 

Per vertex transform from object to tangent space.

This matrix is used to bring the light Vector from object space into tangent space.

"Tangent space" is the vector space defined by the s-, t- and (s- cross t-) texture directions. The (s- cross t-) direction "corresponds" to the triangle normal (in "object space").

Given a point P inside the face (with texture coordinates s_P and t_P), and a vertex E belonging to the face (with texture coordinates s_E and t_E) we would like for the following to hold:

        P - E = (s_P - s_E) * T + (t_P - t_E) * B
        
where (T, B) represent the s- and, respectively, t- directions in texture space.

Let V1V0 and V2V0 be two edges of the face; using the relationship above:

        V1V0 = (s_V1 - s_V0) * T + (t_V1 - t_V0) * B
        V2V0 = (s_V2 - s_V0) * T + (t_V2 - t_V0) * B
        

Let s1 = s_V1 - s_V0, t1 = t_V1 - t_V0, s2 = s_V2 - s_V0, t2 = t_V2 - t_V0

Solving for T, B in the system of equations above, we get:

        |T| = 1 / (s1 * t2 - s2 * t2) |t2 -t1| |V1V0|
        |B|                           |-s2 s1| |V2V0|
        

The matrix which transforms from texture space to object space has as columns the vectors T, B and N = T cross B. This can be verified immediately: the matrix takes the the X axis (1,0,0) in texture space to T in object space.

To transform from object space to texture space, we need to invert the matrix. This will take the normal in object space to the Z axis (0, 0, 1) in texture space.


The documentation for this class was generated from the following files:
Generated on Sat Mar 22 15:12:08 2003 for Bumpmap by doxygen1.3-rc2