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