# cTriangle Struct Reference
[Graphics]

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 (cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings) const
double | computeArea ()
## Public Attributes
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?
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...

## 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

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.

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

Compute and return the area of this triangle.

Returns:
  Returns the area of this triangle.

bool cTriangle::computeCollision | ( | cVector3d & | a_segmentPointA,
|  | cVector3d & | a_segmentPointB,
|  | cCollisionRecorder & | a_recorder,
|  | cCollisionSettings & | a_settings |
| ) |  |  | const`[inline]`

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

If a collision occurs, this information is stored in the collision recorder a_recorder.

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.

Parameters:

  | a_segmentPointA | Point from where collision ray starts (in local frame).
  | a_segmentPointB | Direction vector of collision ray (in local frame).
  | a_recorder | Stores collision events
  | a_settings | Settings related to collision detection process.

Returns:
  Returns true if a collision occured, otherwise false.

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.

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.

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

Retrieve a pointer to the mesh that owns this triangle.

Returns:
  Return pointer to parent mesh.

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

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.

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.

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

Set pointer to mesh parent of triangle.

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.

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

- D:/CHAI3D/build-2-0-0/2.0.0/win32/src/graphics/CTriangle.h

CHAI3D 2.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2009 - CHAI 3D
All Rights Reserved.