Public Member Functions | Public Attributes

gmtl::Tri< DATA_TYPE > Class Template Reference
[Abstract Data Types: Matrix, Vec, Quat, Coord, Sphere, Plane]

This class defines a triangle as a set of 3 points order in CCW fashion. More...

#include <Tri.h>

Collaboration diagram for gmtl::Tri< DATA_TYPE >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Tri ()
 Constructs a new triangle with all vertices at the origin.
 Tri (const Point< DATA_TYPE, 3 > &p1, const Point< DATA_TYPE, 3 > &p2, const Point< DATA_TYPE, 3 > &p3)
 Constructs a new triangle with the given points.
 Tri (const Tri< DATA_TYPE > &tri)
 Constructs a duplicate of the given triangle.
Vec< DATA_TYPE, 3 > edge (int idx) const
 Gets the nth edge of the triangle where edge0 corresponds to the vector from vertex 0 to 1, edge1 corresponds to the vector from vertex 1 to 2 and edge2 corresponsds to the vector from vertex 2 to vertex 0.
Vec< DATA_TYPE, 3 > edge (int idx, int idy) const
 get edge vec from two verts
void set (const Point< DATA_TYPE, 3 > &p1, const Point< DATA_TYPE, 3 > &p2, const Point< DATA_TYPE, 3 > &p3)
 Set the triangle with the given points.

Point< DATA_TYPE, 3 > & operator[] (const unsigned idx)
 Gets the nth vertex in the triangle.
const Point< DATA_TYPE, 3 > & operator[] (const unsigned idx) const

Public Attributes

Point< DATA_TYPE, 3 > mVerts [3]
 The vertices of the triangle.

Detailed Description

template<class DATA_TYPE>
class gmtl::Tri< DATA_TYPE >

This class defines a triangle as a set of 3 points order in CCW fashion.

Triangle points are tri(s,t) = b+s*e0+t*e1 where 0 <= s <= 1, 0 <= t <= 1, and 0 <= s+t <= 1.

Definition at line 23 of file Tri.h.


Constructor & Destructor Documentation

template<class DATA_TYPE>
gmtl::Tri< DATA_TYPE >::Tri (  )  [inline]

Constructs a new triangle with all vertices at the origin.

Definition at line 29 of file Tri.h.

{}

template<class DATA_TYPE>
gmtl::Tri< DATA_TYPE >::Tri ( const Point< DATA_TYPE, 3 > &  p1,
const Point< DATA_TYPE, 3 > &  p2,
const Point< DATA_TYPE, 3 > &  p3 
) [inline]

Constructs a new triangle with the given points.

The points must be passed in in CCW order.

Parameters:
p1 vertex0
p2 vertex1
p3 vertex2
Precondition:
p1, p2, p3 must be in CCW order

Definition at line 41 of file Tri.h.

   {
      mVerts[0] = p1;
      mVerts[1] = p2;
      mVerts[2] = p3;
   }

template<class DATA_TYPE>
gmtl::Tri< DATA_TYPE >::Tri ( const Tri< DATA_TYPE > &  tri  )  [inline]

Constructs a duplicate of the given triangle.

Parameters:
tri the triangle to copy

Definition at line 54 of file Tri.h.

   {
      mVerts[0] = tri[0];
      mVerts[1] = tri[1];
      mVerts[2] = tri[2];
   }


Member Function Documentation

template<class DATA_TYPE>
Vec<DATA_TYPE, 3> gmtl::Tri< DATA_TYPE >::edge ( int  idx  )  const [inline]

Gets the nth edge of the triangle where edge0 corresponds to the vector from vertex 0 to 1, edge1 corresponds to the vector from vertex 1 to 2 and edge2 corresponsds to the vector from vertex 2 to vertex 0.

Parameters:
idx the ordered edge index
Precondition:
0 <= idx <= 2
Returns:
a vector from vertex idx to vertex (idx+1)mod size

Definition at line 92 of file Tri.h.

   {
      gmtlASSERT( (0 <= idx) && (idx <= 2) );
      int idx2 = ( idx == 2 ) ? 0 : idx + 1;
      return (mVerts[idx2] - mVerts[idx]);
   }

template<class DATA_TYPE>
Vec<DATA_TYPE, 3> gmtl::Tri< DATA_TYPE >::edge ( int  idx,
int  idy 
) const [inline]

get edge vec from two verts

Parameters:
idx,idy the ordered vertex indicies
Precondition:
0 <= id <= 2
Returns:
a vector from vertex idx to vertex idy

Definition at line 106 of file Tri.h.

   {
      gmtlASSERT( (0 <= idx) && (idx <= 2) );
      gmtlASSERT( (0 <= idy) && (idy <= 2) );
      return (mVerts[idy] - mVerts[idx]);
   }

template<class DATA_TYPE>
const Point<DATA_TYPE, 3>& gmtl::Tri< DATA_TYPE >::operator[] ( const unsigned  idx  )  const [inline]

Definition at line 75 of file Tri.h.

   {
      gmtlASSERT( idx <= 2 );
      return mVerts[idx];
   }

template<class DATA_TYPE>
Point<DATA_TYPE, 3>& gmtl::Tri< DATA_TYPE >::operator[] ( const unsigned  idx  )  [inline]

Gets the nth vertex in the triangle.

Parameters:
idx the index to the vertex in the triangle
Precondition:
0 <= idx <= 2
Returns:
the nth vertex as a point

Definition at line 70 of file Tri.h.

   {
      gmtlASSERT( idx <= 2 );
      return mVerts[idx];
   }

template<class DATA_TYPE>
void gmtl::Tri< DATA_TYPE >::set ( const Point< DATA_TYPE, 3 > &  p1,
const Point< DATA_TYPE, 3 > &  p2,
const Point< DATA_TYPE, 3 > &  p3 
) [inline]

Set the triangle with the given points.

The points must be passed in in CCW order.

Parameters:
p1 vertex0
p2 vertex1
p3 vertex2
Precondition:
p1, p2, p3 must be in CCW order

Definition at line 125 of file Tri.h.

   {
      mVerts[0] = p1;
      mVerts[1] = p2;
      mVerts[2] = p3;
   }


Member Data Documentation

template<class DATA_TYPE>
Point<DATA_TYPE, 3> gmtl::Tri< DATA_TYPE >::mVerts[3]

The vertices of the triangle.

Definition at line 137 of file Tri.h.


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