- Main Page
- Classes
- Files
- Directories

- Class List
- Class Hierarchy
- Class Members

# cTriangle Struct Reference

cTriangle defines a triangle, typically bound to a mesh for graphic rendering. More...

`#include <CTriangle.h>`

List of all members.

## Public Member Functions
| cTriangle (cMesh *a_parent, const unsigned int a_indexVertex0, const unsigned int a_indexVertex1, const unsigned int a_indexVertex2)
| cTriangle ()
| ~cTriangle ()
void | setVertices (const unsigned int a_indexVertex0, const unsigned int a_indexVertex1, const unsigned int a_indexVertex2)
cVertex * | getVertex0 () const
cVertex * | getVertex1 () const
cVertex * | getVertex2 () const
cVertex * | getVertex (int vi) const
unsigned int | getVertexIndex (int vi) const
unsigned int | getIndexVertex0 () const
unsigned int | getIndexVertex1 () const
unsigned int | getIndexVertex2 () const
unsigned int | getIndex () const
cMesh * | getParent () const
void | setParent (cMesh *parent)
bool | allocated () const
bool | computeCollision (const cVector3d &a_rayOrigin, const cVector3d &a_rayDir, cGenericObject *&a_colObject, cTriangle *&a_colTriangle, cVector3d &a_colPoint, double &a_colSquareDistance) const
double | compute_area ()
## Public Attributes
int | m_tag
| For custom use. No specific purpose.
std::vector< cTriangle * > * | m_neighbors
| A mesh can be organized into a network of neighboring triangles, which are stored here...
unsigned int | m_indexVertex0
| Index number of vertex 0 (defines a location in my owning mesh's vertex array).
unsigned int | m_indexVertex1
| Index number of vertex 1 (defines a location in my owning mesh's vertex array).
unsigned int | m_indexVertex2
| Index number of vertex 2 (defines a location in my owning mesh's vertex array).
unsigned int | m_index
| Index number of this triangle (defines a location in my owning mesh's triangle array).
cMesh * | m_parent
| The mesh that owns me.
bool | m_allocated
| Is this triangle still active?

## Detailed Description

cTriangle defines a triangle, typically bound to a mesh for graphic rendering.

## Constructor & Destructor Documentation

cTriangle::cTriangle | ( | cMesh * | a_parent,
|  | const unsigned int | a_indexVertex0,
|  | const unsigned int | a_indexVertex1,
|  | const unsigned int | a_indexVertex2 |
| ) |  |  | `[inline]`

Constructor of cTriangle.

Parameters:

  | a_parent | Parent mesh.
  | a_indexVertex0 | index position of vertex 0.
  | a_indexVertex1 | index position of vertex 1.
  | a_indexVertex2 | index position of vertex 2.

cTriangle::cTriangle | ( |  | ) | `[inline]`

Default constructor of cTriangle.

cTriangle::~cTriangle | ( |  | ) | `[inline]`

Destructor of cTriangle.

## Member Function Documentation

void cTriangle::setVertices | ( | const unsigned int | a_indexVertex0,
|  | const unsigned int | a_indexVertex1,
|  | const unsigned int | a_indexVertex2 |
| ) |  |  | `[inline]`

Set the vertices of the triangle by passing the index numbers of the corresponding vertices.

Parameters:

  | a_indexVertex0 | index position of vertex 0.
  | a_indexVertex1 | index position of vertex 1.
  | a_indexVertex2 | index position of vertex 2.

cVertex* cTriangle::getVertex0 | ( |  | ) | const`[inline]`

Read pointer to vertex 0 of triangle

Returns:
  Return pointer to vertex 0.

cVertex* cTriangle::getVertex1 | ( |  | ) | const`[inline]`

Read pointer to vertex 1 of triangle

Returns:
  Return pointer to vertex 1.

cVertex* cTriangle::getVertex2 | ( |  | ) | const`[inline]`

Read pointer to vertex 2 of triangle

Returns:
  Return pointer to vertex 2.

cVertex* cTriangle::getVertex | ( | int | vi | ) | const`[inline]`

Access a pointer to the specified vertex of this triangle

Parameters:

  | vi | The triangle (0, 1, or 2) to access

Returns:
  Returns a pointer to the requested triangle, or 0 for an illegal index

unsigned int cTriangle::getVertexIndex | ( | int | vi | ) | const`[inline]`

Access the index of the specified vertex of this triangle

Parameters:

  | vi | The triangle (0, 1, or 2) to access

Returns:
  Returns the index of the specified triangle

unsigned int cTriangle::getIndexVertex0 | ( |  | ) | const`[inline]`

Read index number of vertex 0 (defines a location in my owning mesh's vertex array)

Returns:
  Return index number.

unsigned int cTriangle::getIndexVertex1 | ( |  | ) | const`[inline]`

Read index number of vertex 1 (defines a location in my owning mesh's vertex array)

Returns:
  Return index number.

unsigned int cTriangle::getIndexVertex2 | ( |  | ) | const`[inline]`

Read index number of vertex 2 (defines a location in my owning mesh's vertex array)

Returns:
  Return index number.

unsigned int cTriangle::getIndex | ( |  | ) | const`[inline]`

Read the index of this triangle (defines a location in my owning mesh's triangle array)

Returns:
  Return index number.

cMesh* cTriangle::getParent | ( |  | ) | const`[inline]`

Retrieve a pointer to the mesh that owns this triangle

Returns:
  Return pointer to parent mesh.

void cTriangle::setParent | ( | cMesh * | parent | ) | `[inline]`

Set pointer to mesh parent of triangle.

bool cTriangle::allocated | ( |  | ) | const`[inline]`

Is this triangle allocated to an existing mesh?

Returns:
  Return true if triangle is allocated to an existing mesh, otherwise return false.

bool cTriangle::computeCollision | ( | const cVector3d & | a_rayOrigin,
|  | const cVector3d & | a_rayDir,
|  | cGenericObject *& | a_colObject,
|  | cTriangle *& | a_colTriangle,
|  | cVector3d & | a_colPoint,
|  | double & | a_colSquareDistance |
| ) |  |  | const`[inline]`

Check if a ray intersects this triangle. The ray is described by its origin (/e a_origin) and its direction (/e a_direction).

If a collision occurs, the square distance between the ray origin and the collision point in measured and compared to any previous collision information stored in parameters a_colObject, a_colTriangle, a_colPoint, and a_colSquareDistance.

If the new collision is located nearer to the ray origin than the previous collision point, it is stored in the corresponding parameters a_colObject, a_colTriangle, a_colPoint, and a_colSquareDistance.

Parameters:

  | a_rayOrigin | Point from where collision ray starts (in local frame).
  | a_rayDir | Direction vector of collision ray (in local frame).
  | a_colObject | Pointer to nearest collided object.
  | a_colTriangle | Pointer to nearest collided triangle.
  | a_colPoint | Position of nearest collision.
  | a_colSquareDistance | Distance between ray origin and nearest collision point.

Code adapted from: http://www.cs.lth.se/home/Tomas_Akenine_Moller/raytri/raytri.c

This is one of the most performance-critical routines in CHAI, so we have code here for a couple different approaches that may become useful in different scenarios.

double cTriangle::compute_area | ( |  | ) | `[inline]`

Compute and return the area of this triangle

Returns:
  Returns the area of this triangle

The documentation for this struct was generated from the following file:

- chai3d/src/graphics/CTriangle.h