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 Member Functions

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

 Triangle (const Vertex &v1, const Vector &n1, const Vertex &v2, const Vector &n2, const Vertex &v3, const Vector &n3, const Model &model)
 Initialize the Triangle using the given vertices and normals.

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

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

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

const VectorgetNormal () const
 Retrieve the Triangle normal.

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 Member Functions

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

Triangleoperator= (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.


Member Function Documentation

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.


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, listed in increasing order. For example, say this Triangle has Vertex indices 0xA3, 0x17 and 0xF8. The first edge is made of Vertices (0x17, 0xA3), the second edge (0x17, 0xF8) and the third edge (0xA3, 0xF8). The edge index of the first edge is 0x17A3, the second edge is 0x17F8 and the third edge is 0xA3F8. Each edge index is therefore guaranteed to be shared between two Triangles if they share the corresponding Vertices.

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 Mon Aug 25 23:40:58 2003 for Shadow by doxygen 1.3.2