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