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