GL Studio C++ Runtime API
vertex.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::Vertex class. A class for manipulating 3D vertices.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef _VERTEX_H
41 #define _VERTEX_H
42 
43 #include "display_types.h"
44 #include "disti_include.h"
45 #include "gls_color.h"
46 #include "unhide_globals.h"
47 
48 #include <iosfwd> //Forward references for the stream operators
49 #include <math.h>
50 
51 #ifndef M_PI
52 # define M_PI 3.14159265358979323846
53 #endif
54 
55 // DEG_TO_RAD Converts degrees to radians
56 #ifndef DEG_TO_RAD
57 # define DEG_TO_RAD ( M_PI / 180.0 )
58 #endif
59 
60 namespace disti
61 {
62 class Vertex;
63 class VertexNoColor;
64 
65 /** This typedef is a changed from pre 3.0 versions.
66  * Now Vector is different from Vertex. It now contains no color
67  * information
68  */
69 typedef VertexNoColor Vector;
70 
71 /** Rotation axis enumeration. Passed into rotation calls */
72 typedef enum
73 {
74  X_AXIS, /**< Rotate around the X Axis */
75  Y_AXIS, /**< Rotate around the Y Axis */
76  Z_AXIS /**< Rotate around the Z Axis */
77 } RotationAxis;
78 
79 /**
80  The Vertex class: Implements a 3D cartesian coordianate and operations
81  for manipulating them.
82 */
84 {
85 public:
86  float x, y, z;
87 
88  /** Simple constructor. Ensures all values are initialized */
89  inline VertexNoColor()
90  : x( 0.0f )
91  , y( 0.0f )
92  , z( 0.0f )
93  {}
94 
95  /** Position only constructor. Color values are set to defaults
96  \param _x The X value of the vertex, in logical units
97  \param _y The Y value of the vertex, in logical units
98  \param _z The Z value of the vertex, in logical units */
99  inline VertexNoColor( float _x, float _y, float _z )
100  : x( _x )
101  , y( _y )
102  , z( _z )
103  {}
104 
105  /** Compute the square of the cartesian distance between this point and
106  another one , in 3D
107  \param v The vertex to compute distance squared to
108  \return The square of the distance between the two points */
109  inline float Distance3Squared( const VertexNoColor& v ) const
110  {
111  return ( ( v.x - x ) * ( v.x - x ) ) + ( ( v.y - y ) * ( v.y - y ) ) + ( ( v.z - z ) * ( v.z - z ) );
112  }
113 
114  /** Returns the squared distance of this point from the line defined by start
115  and direction, in 3D
116  \param startx starting x coordinate of the line.
117  \param starty starting y coordinate of the line.
118  \param startz starting z coordinate of the line.
119  \param direction Normalized direction vector for the line.
120  \return the distance from this point. */
121  inline float DistanceFromLineSquared( const float startx, const float starty, const float startz, const VertexNoColor& direction ) const
122  {
123  // Distance from point to line
124  // Algorithm from Mgc::SqrDistance http://www.magic-software.com/License/free.pdf
125 
126  VertexNoColor kDiff( x, y, z );
127 
128  //kDiff = rkPoint - linePoint;
129  kDiff.x -= startx;
130  kDiff.y -= starty;
131  kDiff.z -= startz;
132 
133  float fSqrLen = direction.MagnitudeSquared();
134  float fT = kDiff.DotProduct( direction ) / fSqrLen;
135 
136  //kDiff.minusAssign(direction.multiply(fT));
137  kDiff.x -= direction.x * fT;
138  kDiff.y -= direction.y * fT;
139  kDiff.z -= direction.z * fT;
140 
141  float dist_squared = kDiff.MagnitudeSquared();
142 
143  return dist_squared;
144  }
145 
146  /** Compute cartesian distance between this point and another one , in 3D
147  \param v The vertex to compute distance to.
148  \return The distance between the two points */
149  inline float Distance3( const VertexNoColor& v ) const
150  {
151  return float( sqrt( ( ( v.x - x ) * ( v.x - x ) ) + ( ( v.y - y ) * ( v.y - y ) ) + ( ( v.z - z ) * ( v.z - z ) ) ) );
152  }
153 
154  /** Compute the square of the cartesian distance between this point and
155  another one , in 2D
156  \param v The vertex to compute distance squared to
157  \return The square of the distance between the two points */
158  inline float Distance2Squared( const VertexNoColor& v ) const
159  {
160  return ( ( v.x - x ) * ( v.x - x ) ) + ( ( v.y - y ) * ( v.y - y ) );
161  }
162 
163  /** Compute cartesian distance between this point and another one , in 2D
164  \param v The vertex to compute distance to
165  \return The distance between the two points */
166  inline float Distance2( const VertexNoColor& v ) const
167  {
168  return float( sqrt( ( ( v.x - x ) * ( v.x - x ) ) + ( ( v.y - y ) * ( v.y - y ) ) ) );
169  }
170 
171  /** Compute the result of adding this point to another one, in 3D
172  \param arg The vertex to add to this one
173  \return A new vertex V2 where V2 = this + v */
174  inline VertexNoColor operator+( const VertexNoColor& arg ) const
175  {
176  return VertexNoColor( x + arg.x, y + arg.y, z + arg.z );
177  }
178 
179  /** Negation operator */
180  inline VertexNoColor operator-() const
181  {
182  return VertexNoColor( -x, -y, -z );
183  }
184 
185  /** Compute the result of multiplying this point by a scalar
186  \param s The Scalar to multiply by
187  \return A new vertex V2 where V2 = this * s */
188  inline VertexNoColor operator*( const float s ) const
189  {
190  return VertexNoColor( x * s, y * s, z * s );
191  }
192 
193  /** Compute the result of multiplying this point by a scalar
194  \param s The Scalar to multiply by
195  \return V = V * s */
196  inline VertexNoColor& operator*=( const float s )
197  {
198  x *= s;
199  y *= s;
200  z *= s;
201  return *this;
202  }
203 
204  /** Compute the result of dividing this point by a scalar
205  \param s The Scalar to divide by
206  \return A new vertex V2 where V2 = this / s */
207  inline VertexNoColor operator/( const float s ) const
208  {
209  return VertexNoColor( x / s, y / s, z / s );
210  }
211 
212  /** Compute the result of dividing this point by a scalar
213  \param s The Scalar to divide by
214  \return V = V / s */
215  inline VertexNoColor& operator/=( const float s )
216  {
217  x /= s;
218  y /= s;
219  z /= s;
220  return *this;
221  }
222 
223  /** Compute the result of adding this point to another one, in 3D
224  \param arg The vertex to add to this one
225  \return V = V + arg */
226  inline VertexNoColor& operator+=( const VertexNoColor& arg )
227  {
228  x += arg.x;
229  y += arg.y;
230  z += arg.z;
231  return *this;
232  }
233 
234  /** Compute the result of subtracting this point from another one, in 3D
235  \param arg The vertex to subtract from this one
236  \return A new vertex V2 where V2 = this - v */
237  inline VertexNoColor operator-( const VertexNoColor& arg ) const
238  {
239  return VertexNoColor( x - arg.x, y - arg.y, z - arg.z );
240  }
241 
242  /** Compute the result of subtracting this point from another one, in 3D
243  \param arg The vertex to subtract from this one
244  \return V = V - arg */
245  inline VertexNoColor& operator-=( const VertexNoColor& arg )
246  {
247  x -= arg.x;
248  y -= arg.y;
249  z -= arg.z;
250  return *this;
251  }
252 
253  /** Determines if the vertex is identical to the supplied vertex, ignoring color
254  \param arg vertex to compare to
255  \return TRUE if equal, else FALSE
256  */
257  inline bool operator==( const VertexNoColor& arg ) const
258  {
259  return ( ( x == arg.x ) && ( y == arg.y ) && ( z == arg.z ) );
260  }
261 
262  /** Determines if the vertex is identical to the supplied vertex, ignoring color
263  \param arg vertex to compare to
264  \return TRUE if equal, else FALSE
265  */
266  inline bool operator!=( const VertexNoColor& arg ) const
267  {
268  return ( ( x != arg.x ) || ( y != arg.y ) || ( z != arg.z ) );
269  }
270 
271  /** Computes the result of muliplying this point to another one.
272  \param arg vertex to multiple with
273  \return resulting vertex
274  */
275  inline VertexNoColor operator*( const VertexNoColor& arg ) const
276  {
277  return VertexNoColor( x * arg.x, y * arg.y, z * arg.z );
278  }
279 
280  /** Rotate this point in 2D clockwise around the z axis.
281  \param angle The angle to rotate around, in degrees.
282  \return The rotated vertex */
283  DISTI_EXPORT VertexNoColor Rotate( const float angle ) const;
284 
285  /** Rotate this point around a different point in 2D counter-clockwise around the z axis.
286  \param orig The rotation origin to rotate around.
287  \param angle The angle to rotate around, in degrees.
288  \return The rotated vertex */
289  DISTI_EXPORT VertexNoColor Rotate( const VertexNoColor& orig, const float angle ) const;
290 
291  /** Rotate this point around a different point in 2D clockwise around the z axis.
292  \param orig The rotation origin to rotate around.
293  \param angle The angle to rotate around, in degrees.
294  \param axis The axis to rotate around. See RotationAxis enum.
295  \return The rotated vertex */
296  DISTI_EXPORT VertexNoColor Rotate( const VertexNoColor& orig, const float angle, const int axis ) const;
297 
298  /** Rotate this vertex by angle theta counter-clockwise around an arbitrary axis r.
299  \param orig The rotation origin to rotate around.
300  \param angle The angle to rotate around, in degrees.
301  \param r The axis to rotate around.
302  \return The rotated vertex
303  */
304  DISTI_EXPORT VertexNoColor Rotate( const VertexNoColor& orig, const float angle, const Vector& r ) const;
305 
306  /** Normalizes the vector into a unit vector */
307  inline void Normalize( void )
308  {
309  float length, inv_length;
310 
311  length = Magnitude();
312  if( length != 0.0f )
313  {
314  // Divide is slow so calculate 1/length and multiply to save time
315  inv_length = 1.0f / length;
316 
317  x = x * inv_length;
318  y = y * inv_length;
319  z = z * inv_length;
320  }
321  }
322 
323  /** Returns the magnitude of the vector
324  * \return The resulting scalar
325  */
326  inline float Magnitude() const
327  {
328  return float( sqrt( ( ( x ) * ( x ) ) + ( ( y ) * ( y ) ) + ( ( z ) * ( z ) ) ) );
329  }
330 
331  /** Returns the magnitude of the vector squared
332  * \return The resulting scalar
333  */
334  inline float MagnitudeSquared() const
335  {
336  return x * x + y * y + z * z;
337  }
338 
339  /** Returns the vector cross-product of this vector with the argument vector
340  * HS Algebra review: vector cross-product is the vector that is
341  * perpendicular to the two given vectors.
342  * \param w Second vector
343  * \return The resulting cross-product (vector)
344  */
345  inline VertexNoColor CrossProduct( const VertexNoColor& w ) const
346  {
347  return VertexNoColor( ( y * w.z ) - ( z * w.y ),
348  ( z * w.x ) - ( x * w.z ),
349  ( x * w.y ) - ( y * w.x ) );
350  }
351 
352  /** Returns the vector dot-product of this vector with the argument vector
353  * \param w Second vector
354  * \return The resulting dot-product (scalar)
355  */
356  inline float DotProduct( const VertexNoColor& w ) const
357  {
358  return ( ( x * w.x ) + ( y * w.y ) + ( z * w.z ) );
359  }
360 
361  /** Returns the angle (in radians) between this vector and the argument vect.
362  * \param arg Second vector
363  * \return The resulting angle (in radians)
364  */
365  DISTI_EXPORT float AngleToVector( const VertexNoColor& arg ) const;
366 
367  /** Returns true if this vertex is in the given triangle specified by abc
368  * \param a First triangle vertex
369  * \param b Second triangle vertex
370  * \param c Third triangle vertex
371  * \return true if this point is inside the triangle, false otherwise
372  */
373  inline bool PointInTriangle( const VertexNoColor& a, const VertexNoColor& b, const VertexNoColor& c ) const
374  {
375  float fAB, fBC, fCA;
376 
377  fAB = ( y - a.y ) * ( b.x - a.x ) - ( x - a.x ) * ( b.y - a.y );
378  fBC = ( y - b.y ) * ( c.x - b.x ) - ( x - b.x ) * ( c.y - b.y );
379  fCA = ( y - c.y ) * ( a.x - c.x ) - ( x - c.x ) * ( a.y - c.y );
380 
381  return ( ( ( fAB * fBC ) > 0 ) && ( ( fBC * fCA ) > 0 ) );
382  }
383 
384  /** Returns true if this vertex is within the radius specified by tolerance
385  * \param arg vertex to compare with
386  * \param tolerance the tolerance value
387  * \return true if this point within the tolerance
388  */
389  DISTI_EXPORT bool CloseTo( const VertexNoColor& arg, float tolerance = 0.0001f ) const;
390 
391  /** Returns the distance of this point from the line defined by start and direction
392  * \param start Starting point of the line
393  * \param direction Normalized direction vector for the line
394  */
395  DISTI_EXPORT float DistanceFromLine( const VertexNoColor& start, const VertexNoColor& direction ) const;
396 
397  /** Returns the projection of this point onto the line defined by origin and direction
398  * \param origin Starting point of the line
399  * \param direction Normalized direction vector for the line
400  */
401  DISTI_EXPORT VertexNoColor ProjectPointToLine( const VertexNoColor& origin, const VertexNoColor& direction ) const;
402 };
403 // Stream operators
404 GLS_EXPORT std::istream& operator>>( std::istream& instr, Vector& vert );
405 GLS_EXPORT std::ostream& operator<<( std::ostream& outstr, const Vector& vert );
406 
407 /** A 3D coordinate in space with an RGBA color value */
408 class Vertex : public VertexNoColor
409 {
410 public:
411  GlsColor color;
412 
413  /** Simple constructor. Ensures all values are initialized */
415  : VertexNoColor()
416  {
417  color.RGBA( DEF_FILL_RCOLOR, DEF_FILL_GCOLOR, DEF_FILL_BCOLOR, DEF_FILL_ALPHA );
418  }
419 
420  /** Just add the default color constructor */
421  Vertex( const VertexNoColor& noColor )
422  : VertexNoColor( noColor )
423  {
424  color.RGBA( DEF_FILL_RCOLOR, DEF_FILL_GCOLOR, DEF_FILL_BCOLOR, DEF_FILL_ALPHA );
425  }
426 
427  /** Just add the color constructor */
428  Vertex( const VertexNoColor& noColor, const GlsColor& _color )
429  : VertexNoColor( noColor )
430  , color( _color )
431  {
432  }
433 
434  /** Position only constructor. Color values are set to defaults
435  \param _x The X value of the vertex, in logical units
436  \param _y The Y value of the vertex, in logical units
437  \param _z The Z value of the vertex, in logical units */
438  Vertex( float _x, float _y, float _z )
439  : VertexNoColor( _x, _y, _z )
440  {
441  color.RGBA( DEF_FILL_RCOLOR, DEF_FILL_GCOLOR, DEF_FILL_BCOLOR, DEF_FILL_ALPHA );
442  }
443 
444  /** Position only constructor. Color values are set to defaults
445  \param _x The X value of the vertex, in logical units
446  \param _y The Y value of the vertex, in logical units
447  \param _z The Z value of the vertex, in logical units
448  \param _r The R value of the color of the vertex 0-255
449  \param _g The G value of the color of the vertex 0-255
450  \param _b The B value of the color of the vertex 0-255
451  \param _a The A value of the color of the vertex 0-255
452  */
453  Vertex( float _x, float _y, float _z,
454  unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a )
455  : VertexNoColor( _x, _y, _z )
456  {
457  color.RGBA( _r, _g, _b, _a );
458  }
459 
460  /** Position only constructor. Color values are set to defaults
461  \param _x The X value of the vertex, in logical units
462  \param _y The Y value of the vertex, in logical units
463  \param _z The Z value of the vertex, in logical units
464  \param _color The value of the color of the vertex
465  */
466  Vertex( float _x, float _y, float _z, const GlsColor& _color )
467  : VertexNoColor( _x, _y, _z )
468  {
469  color = _color;
470  }
471 
472  /** Compute the result of adding this point to another one, in 3D
473  \param arg The vertex to add to this one
474  \return A new vertex V2 where V2 = this + v */
475  inline Vertex operator+( const VertexNoColor& arg ) const
476  {
477  return Vertex( x + arg.x, y + arg.y, z + arg.z, color );
478  }
479 
480  /** Compute the result of multiplying this point by a scalar
481  \param s The Scalar to multiply by
482  \return A new vertex V2 where V2 = this * s */
483  inline Vertex operator*( const float s ) const
484  {
485  return Vertex( x * s, y * s, z * s, color );
486  }
487 
488  /** Rotate this point in 2D around the z axis
489  \param angle The angle to rotate around, in degrees.
490  \return The rotated vertex */
491  DISTI_EXPORT Vertex Rotate( const float angle ) const;
492 
493  /** Rotate this point around a different point in 2D around the z axis
494  \param orig The rotation origin to rotate around.
495  \param angle The angle to rotate around, in degrees.
496  \return The rotated vertex */
497  DISTI_EXPORT Vertex Rotate( const VertexNoColor& orig, const float angle ) const;
498 
499  /** Rotate this point around a different point in 2D around the z axis
500  \param orig The rotation origin to rotate around.
501  \param angle The angle to rotate around, in degrees.
502  \param axis The axis to rotate 180 degrees around. x = 1, y = 2, z = 3.
503  \return The rotated vertex */
504  DISTI_EXPORT Vertex Rotate( const VertexNoColor& orig, const float angle, const int axis ) const;
505 
506  /** Rotate this vertex by angle theta around an arbitrary axis r
507  Return the rotated point.
508  Positive angles are anticlockwise looking down the axis
509  towards the origin. */
510  DISTI_EXPORT Vertex Rotate( const VertexNoColor& orig, const float theta, const Vector& r ) const;
511 
512  /** Compute the result of subtracting this point from another one, in 3D
513  \param arg The vertex to subtract from this one
514  \return A new vertex V2 where V2 = this - v */
515  inline Vertex operator-( const VertexNoColor& arg ) const
516  {
517  return Vertex( x - arg.x, y - arg.y, z - arg.z, color );
518  }
519 
520  /** Negation operator */
521  inline Vertex operator-() const
522  {
523  return Vertex( -x, -y, -z, color );
524  }
525 
526  /** Computes the result of muliplying this point to another one.
527  \param arg vertex to multiple with
528  \return resulting vertex
529  */
530  inline Vertex operator*( const VertexNoColor& arg ) const
531  {
532  return Vertex( x * arg.x, y * arg.y, z * arg.z, color );
533  }
534 
535  /** Returns the vector cross-product of this vector with the argument vector
536  * HS Algebra review: vector cross-product is the vector that is
537  * perpendicular to the two given vectors.
538  * \param w Second vector
539  * \return The resulting cross-product (vector)
540  */
541  inline Vertex CrossProduct( const VertexNoColor& w ) const
542  {
543  return Vertex( VertexNoColor::CrossProduct( w ), color );
544  }
545 };
546 
547 /**
548  The PlaneClass class: Implements a 3D plane
549 */
551 {
552 public:
553  float a, b, c, d; /** Coefficients to describe a 3D plane: aX + bY + cZ + d = 0 */
554 
555  PlaneClass( void )
556  {
557  a = 0.0f;
558  b = 0.0f;
559  c = 0.0f;
560  d = 0.0f;
561  }
562 
563  PlaneClass( float A, float B, float C, float D )
564  {
565  a = A;
566  b = B;
567  c = C;
568  d = D;
569  }
570 };
571 
572 // Stream operators
573 DISTI_EXPORT std::istream& operator>>( std::istream& instr, Vertex& vert );
574 DISTI_EXPORT std::ostream& operator<<( std::ostream& outstr, const Vertex& vert );
575 
576 /** Computes whether or not a vector intersects a plane.
577  * \param point Returned parameter, contains intersection point on success
578  * \param lineVector Direction of the vector
579  * \param linePoint Origin point of the vector
580  * \param planeNormal Surface normal of the plane
581  * \param planePoint A point on the plane
582  * \return Non-zero if the vector intersects the plane
583  */
584 DISTI_EXPORT int IntersectionVectorAndPlane( VertexNoColor& point, const Vector& lineVector, const VertexNoColor& linePoint, const Vector& planeNormal, const Vector& planePoint );
585 
586 /** Finds the point that (1) lies along the plane passing through p3
587  * and perpendicular to the vector p1-p2 and (2) lies along the line defined by
588  * p1 and p2
589  *
590  * Method: We have 3 unknowns (x,y,z) and 3 equations:
591  * The first known equation is the equation of the plane where
592  * vA is the vector p2 - p1
593  * eq 1: (x - p3.x)vA.x + (y - p3.y)vA.y + (z - p3.z)vA.z = 0
594  * The second and third equations are the projection form of the
595  * line defined by the points p1 and p2.
596  * eq 2: (x - p1.x) / (p2.x - p1.x) = (y - p1.y) / (p2.y - p1.y)
597  * eq 3: (x - p1.x) / (p2.x - p1.x) = (z - p1.z) / (p2.z - p1.z)
598  *
599  * \param p1 First point in the vector
600  * \param p2 Second point in the vector
601  * \param p3 A point in the plane p1,p2,p3
602  * \return The point of intersection
603  */
604 DISTI_EXPORT VertexNoColor ProjectedIntersectingPoint( const VertexNoColor& p1, const VertexNoColor& p2, const VertexNoColor& p3 );
605 
606 /** Determines if a line intersects a triangle, and optionally where.
607  * \param origin The origin of the line to test
608  * \param direction The direction vector of the line
609  * \param v0 The first triangle point
610  * \param v1 The second triangle point
611  * \param v2 The third triangle point
612  * \param collisionPoint Returns where the triangle was hit (only set if the triangle was actually hit)
613  * \return True if the triangle is hit
614  * \note This function does what TriangleHit() and DoesLineIntersectTriangle() used to do, namely checking the intersection of a line with a triangle.
615  * Most users should use RayHitsTriangle() instead because using a line may return a collision in the opposite direction to the direction vector,
616  * which could result in a pick behind the viewer, for instance.
617  */
618 DISTI_EXPORT bool LineHitsTriangle( const Vector& origin, const Vector& direction, const Vector& v0, const Vector& v1, const Vector& v2, Vector* collisionPoint = 0 );
619 
620 /** Determines if a ray intersects a triangle, and optionally where.
621  * \param origin The origin of the ray to test
622  * \param direction The direction vector of the ray
623  * \param v0 The first triangle point
624  * \param v1 The second triangle point
625  * \param v2 The third triangle point
626  * \param collisionPoint Returns where the triangle was hit (only set if the triangle was actually hit)
627  * \return True if the triangle is hit
628  * \note See note on LineHitsTriangle().
629  */
630 DISTI_EXPORT bool RayHitsTriangle( const Vector& origin, const Vector& direction, const Vector& v0, const Vector& v1, const Vector& v2, Vector* collisionPoint = 0 );
631 
632 /** Find the point at which a line intersects a plane. Helper/preparer function for
633  * IntersectionVectorAndPlane.
634  * /param point Origin of the line
635  * /param vert1 First point defining the plane
636  * /param vert2 Second point defining the plane
637  * /param vert3 Third point defining the plane
638  * /param collisionPoint This will be set to the intersection point
639  * /param directionVector Vector to which the line is parallel
640  */
641 DISTI_EXPORT void FindCollision( const Vector& origin, const Vector& vert1, const Vector& vert2, const Vector& vert3, VertexNoColor* collisionPoint, const Vector& directionVector );
642 
643 /** Computes the Normal vector for the plane formed from the three given points.
644  * \param p1 First point
645  * \param p2 Second point
646  * \param p3 Third point
647  * \return The "normal" vector to the plane formed by p2,p2,p3
648  */
649 DISTI_EXPORT VertexNoColor Normal( const VertexNoColor& p1, const VertexNoColor& p2, const VertexNoColor& p3 );
650 
651 } // namespace disti
652 
653 #endif
The DistiUnhideGlobalsDummyClass class.
Vertex operator+(const VertexNoColor &arg) const
Definition: vertex.h:475
Vertex(const VertexNoColor &noColor)
Definition: vertex.h:421
Definition: vertex.h:550
Definition: vertex.h:408
VertexNoColor(float _x, float _y, float _z)
Definition: vertex.h:99
RotationAxis
Definition: vertex.h:72
Vertex(float _x, float _y, float _z, unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a)
Definition: vertex.h:453
VertexNoColor operator/(const float s) const
Definition: vertex.h:207
float MagnitudeSquared() const
Definition: vertex.h:334
Vertex()
Definition: vertex.h:414
VertexNoColor operator+(const VertexNoColor &arg) const
Definition: vertex.h:174
VertexNoColor ProjectedIntersectingPoint(const VertexNoColor &p1, const VertexNoColor &p2, const VertexNoColor &p3)
void Normalize(void)
Definition: vertex.h:307
float DotProduct(const VertexNoColor &w) const
Definition: vertex.h:356
bool CloseTo(const VertexNoColor &arg, float tolerance=0.0001f) const
bool LineHitsTriangle(const Vector &origin, const Vector &direction, const Vector &v0, const Vector &v1, const Vector &v2, Vector *collisionPoint=0)
Vertex(float _x, float _y, float _z)
Definition: vertex.h:438
The Color class: Implements a 4 component RGBA color.
A file for all GL Studio files to include.
VertexNoColor()
Definition: vertex.h:89
bool PointInTriangle(const VertexNoColor &a, const VertexNoColor &b, const VertexNoColor &c) const
Definition: vertex.h:373
void FindCollision(const Vector &origin, const Vector &vert1, const Vector &vert2, const Vector &vert3, VertexNoColor *collisionPoint, const Vector &directionVector)
VertexNoColor & operator/=(const float s)
Definition: vertex.h:215
VertexNoColor & operator+=(const VertexNoColor &arg)
Definition: vertex.h:226
VertexNoColor operator-() const
Definition: vertex.h:180
Vertex CrossProduct(const VertexNoColor &w) const
Definition: vertex.h:541
Definition: vertex.h:74
bool operator==(const VertexNoColor &arg) const
Definition: vertex.h:257
VertexNoColor operator*(const float s) const
Definition: vertex.h:188
float Distance2Squared(const VertexNoColor &v) const
Definition: vertex.h:158
VertexNoColor Vector
Definition: gls_font_base.h:66
Vertex operator*(const VertexNoColor &arg) const
Definition: vertex.h:530
GL Studio Enumerations and constants.
Vertex(const VertexNoColor &noColor, const GlsColor &_color)
Definition: vertex.h:428
Vertex Rotate(const float angle) const
VertexNoColor CrossProduct(const VertexNoColor &w) const
Definition: vertex.h:345
Vertex operator-() const
Definition: vertex.h:521
PlaneClass(void)
Definition: vertex.h:555
Definition: gls_color.h:53
int IntersectionVectorAndPlane(VertexNoColor &point, const Vector &lineVector, const VertexNoColor &linePoint, const Vector &planeNormal, const Vector &planePoint)
VertexNoColor operator*(const VertexNoColor &arg) const
Definition: vertex.h:275
VertexNoColor Rotate(const float angle) const
float Distance2(const VertexNoColor &v) const
Definition: vertex.h:166
VertexNoColor Normal(const VertexNoColor &p1, const VertexNoColor &p2, const VertexNoColor &p3)
float DistanceFromLine(const VertexNoColor &start, const VertexNoColor &direction) const
Vertex operator*(const float s) const
Definition: vertex.h:483
Definition: vertex.h:83
float Magnitude() const
Definition: vertex.h:326
float Distance3Squared(const VertexNoColor &v) const
Definition: vertex.h:109
VertexNoColor & operator*=(const float s)
Definition: vertex.h:196
Definition: vertex.h:76
bool operator!=(const VertexNoColor &arg) const
Definition: vertex.h:266
float Distance3(const VertexNoColor &v) const
Definition: vertex.h:149
VertexNoColor operator-(const VertexNoColor &arg) const
Definition: vertex.h:237
float AngleToVector(const VertexNoColor &arg) const
Vertex(float _x, float _y, float _z, const GlsColor &_color)
Definition: vertex.h:466
Definition: vertex.h:75
VertexNoColor ProjectPointToLine(const VertexNoColor &origin, const VertexNoColor &direction) const
float DistanceFromLineSquared(const float startx, const float starty, const float startz, const VertexNoColor &direction) const
Definition: vertex.h:121
Definition: bmpimage.h:46
VertexNoColor & operator-=(const VertexNoColor &arg)
Definition: vertex.h:245
bool RayHitsTriangle(const Vector &origin, const Vector &direction, const Vector &v0, const Vector &v1, const Vector &v2, Vector *collisionPoint=0)
Vertex operator-(const VertexNoColor &arg) const
Definition: vertex.h:515
void RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
Definition: gls_color.h:168