Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Opcode::Triangle Class Reference

#include <Opcode.h>

Public Member Functions

inline_ Triangle ()
 Constructor. More...
 
inline_ Triangle (const Point &p0, const Point &p1, const Point &p2)
 Constructor. More...
 
inline_ Triangle (const Triangle &triangle)
 Copy constructor. More...
 
inline_ ~Triangle ()
 Destructor. More...
 
void Flip ()
 
float Area () const
 
float Perimeter () const
 
float Compacity () const
 
void Normal (Point &normal) const
 
void DenormalizedNormal (Point &normal) const
 
void Center (Point &center) const
 
inline_ Plane PlaneEquation () const
 
PartVal TestAgainstPlane (const Plane &plane, float epsilon) const
 
void ComputeMoment (Moment &m)
 
float MinEdgeLength () const
 
float MaxEdgeLength () const
 
void ComputePoint (float u, float v, Point &pt, udword *nearvtx=null) const
 
void Inflate (float fat_coeff, bool constant_border)
 

Public Attributes

Point mVerts [3]
 Vertices. More...
 

Detailed Description

Definition at line 31 of file Opcode.h.

Constructor & Destructor Documentation

inline_ Opcode::Triangle::Triangle ( )
inline

Constructor.

Definition at line 35 of file Opcode.h.

39 {
inline_ Opcode::Triangle::Triangle ( const Point p0,
const Point p1,
const Point p2 
)
inline

Constructor.

Definition at line 37 of file Opcode.h.

39 {
inline_ Opcode::Triangle::Triangle ( const Triangle triangle)
inline

Copy constructor.

Definition at line 39 of file Opcode.h.

39  {
40 
41 
42 
43 
44  #include "Ice/IceAxes.h"
inline_ Opcode::Triangle::~Triangle ( )
inline

Destructor.

Definition at line 46 of file Opcode.h.

Member Function Documentation

float Triangle::Area ( ) const

Computes the triangle area.

Returns
the area

Definition at line 57 of file IceTriangle.cpp.

58 {
59  const Point& p0 = mVerts[0];
60  const Point& p1 = mVerts[1];
61  const Point& p2 = mVerts[2];
62  return ((p0 - p1)^(p0 - p2)).Magnitude() * 0.5f;
63 }
void Triangle::Center ( Point center) const

Computes the triangle center.

Parameters
center[out] the computed center

Definition at line 128 of file IceTriangle.cpp.

Referenced by Inflate().

129 {
130  const Point& p0 = mVerts[0];
131  const Point& p1 = mVerts[1];
132  const Point& p2 = mVerts[2];
133  center = (p0 + p1 + p2)*INV3;
134 }
float Triangle::Compacity ( ) const

Computes the triangle compacity.

Returns
the compacity

Definition at line 87 of file IceTriangle.cpp.

88 {
89  float P = Perimeter();
90  if(P==0.0f) return 0.0f;
91  return (4.0f*PI*Area()/(P*P));
92 }
void Opcode::Triangle::ComputeMoment ( Moment &  m)
void Triangle::ComputePoint ( float  u,
float  v,
Point pt,
udword nearvtx = null 
) const

Computes a point on the triangle according to the stabbing information.

Parameters
u,v[in] point's barycentric coordinates
pt[out] point on triangle
nearvtx[out] index of nearest vertex

Definition at line 252 of file IceTriangle.cpp.

253 {
254  // Compute point coordinates
255  pt = (1.0f - u - v)*mVerts[0] + u*mVerts[1] + v*mVerts[2];
256 
257  // Compute nearest vertex if needed
258  if(nearvtx)
259  {
260  // Compute distance vector
261  Point d(mVerts[0].SquareDistance(pt), // Distance^2 from vertex 0 to point on the face
262  mVerts[1].SquareDistance(pt), // Distance^2 from vertex 1 to point on the face
263  mVerts[2].SquareDistance(pt)); // Distance^2 from vertex 2 to point on the face
264 
265  // Get smallest distance
266  *nearvtx = d.SmallestAxis();
267  }
268 }
void Triangle::DenormalizedNormal ( Point normal) const

Computes the triangle denormalized normal.

Parameters
normal[out] the computed normal

Definition at line 114 of file IceTriangle.cpp.

115 {
116  const Point& p0 = mVerts[0];
117  const Point& p1 = mVerts[1];
118  const Point& p2 = mVerts[2];
119  normal = ((p0 - p1)^(p0 - p2));
120 }
void Triangle::Flip ( )

Flips the winding order.

Definition at line 44 of file IceTriangle.cpp.

45 {
46  Point Tmp = mVerts[1];
47  mVerts[1] = mVerts[2];
48  mVerts[2] = Tmp;
49 }
void Triangle::Inflate ( float  fat_coeff,
bool  constant_border 
)

Definition at line 270 of file IceTriangle.cpp.

References Center(), i, mVerts, and Opcode::Point::Normalize().

271 {
272  // Compute triangle center
273  Point TriangleCenter;
274  Center(TriangleCenter);
275 
276  // Don't normalize?
277  // Normalize => add a constant border, regardless of triangle size
278  // Don't => add more to big triangles
279  for(udword i=0;i<3;i++)
280  {
281  Point v = mVerts[i] - TriangleCenter;
282 
283  if(constant_border) v.Normalize();
284 
285  mVerts[i] += v * fat_coeff;
286  }
287 }
float Triangle::MaxEdgeLength ( ) const

Computes the triangle's largest edge length.

Returns
the largest edge length

Definition at line 232 of file IceTriangle.cpp.

233 {
234  float Max = MIN_FLOAT;
235  float Length01 = mVerts[0].Distance(mVerts[1]);
236  float Length02 = mVerts[0].Distance(mVerts[2]);
237  float Length12 = mVerts[1].Distance(mVerts[2]);
238  if(Length01 > Max) Max = Length01;
239  if(Length02 > Max) Max = Length02;
240  if(Length12 > Max) Max = Length12;
241  return Max;
242 }
float Triangle::MinEdgeLength ( ) const

Computes the triangle moment.

Parameters
m[out] the moment Computes the triangle's smallest edge length.
Returns
the smallest edge length

Definition at line 214 of file IceTriangle.cpp.

215 {
216  float Min = MAX_FLOAT;
217  float Length01 = mVerts[0].Distance(mVerts[1]);
218  float Length02 = mVerts[0].Distance(mVerts[2]);
219  float Length12 = mVerts[1].Distance(mVerts[2]);
220  if(Length01 < Min) Min = Length01;
221  if(Length02 < Min) Min = Length02;
222  if(Length12 < Min) Min = Length12;
223  return Min;
224 }
void Triangle::Normal ( Point normal) const

Computes the triangle normal.

Parameters
normal[out] the computed normal

Definition at line 100 of file IceTriangle.cpp.

101 {
102  const Point& p0 = mVerts[0];
103  const Point& p1 = mVerts[1];
104  const Point& p2 = mVerts[2];
105  normal = ((p0 - p1)^(p0 - p2)).Normalize();
106 }
float Triangle::Perimeter ( ) const

Computes the triangle perimeter.

Returns
the perimeter

Definition at line 71 of file IceTriangle.cpp.

72 {
73  const Point& p0 = mVerts[0];
74  const Point& p1 = mVerts[1];
75  const Point& p2 = mVerts[2];
76  return p0.Distance(p1)
77  + p0.Distance(p2)
78  + p1.Distance(p2);
79 }
inline_ Plane Opcode::Triangle::PlaneEquation ( ) const
inline

Definition at line 58 of file Opcode.h.

PartVal Triangle::TestAgainstPlane ( const Plane plane,
float  epsilon 
) const

Definition at line 136 of file IceTriangle.cpp.

References i, mVerts, Opcode::TRI_FORCEDWORD, Opcode::TRI_INTERSECT, Opcode::TRI_MINUS_SPACE, Opcode::TRI_ON_PLANE, Opcode::TRI_PLUS_SPACE, and VPlaneSideEps().

137 {
138  bool Pos = false, Neg = false;
139 
140  // Loop through all vertices
141  for(udword i=0;i<3;i++)
142  {
143  // Compute side:
144  sdword Side = VPlaneSideEps(mVerts[i], plane, epsilon);
145 
146  if (Side < 0) Neg = true;
147  else if (Side > 0) Pos = true;
148  }
149 
150  if (!Pos && !Neg) return TRI_ON_PLANE;
151  else if (Pos && Neg) return TRI_INTERSECT;
152  else if (Pos && !Neg) return TRI_PLUS_SPACE;
153  else if (!Pos && Neg) return TRI_MINUS_SPACE;
154 
155  // What?!
156  return TRI_FORCEDWORD;
157 }

Member Data Documentation

Point Opcode::Triangle::mVerts[3]

Vertices.

Definition at line 48 of file Opcode.h.

Referenced by Inflate(), and TestAgainstPlane().


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