# mPoint3.h

Engine/source/math/mPoint3.h

More...

class
class
class

3D integer point

## Public Typedefs

```Point3F
```
```EulerF
```
```Point3F
```
```VectorF
```

## Public Functions

```Point3D
```
```mCross(const Point3D & a, const Point3D & b)
```
```void
```
```mCross(const Point3D & a, const Point3D & b, Point3D * res)
```
```Point3F
```
```mCross(const Point3F & a, const Point3F & b)
```
```void
```
```mCross(const Point3F & a, const Point3F & b, Point3F * res)
```
```F64
```
```mDot(const Point3D & p1, const Point3D & p2)
```
```F32
```
```mDot(const Point3F & p1, const Point3F & p2)
```
```bool
```
```mIsNaN(const Point3F & p)
```

Returns true if the point is NaN.

```Point3F
```
```mNormalize(const Point3F & vec)
```

Returns the vector normalized.

```Point3F
```
```mPerp(const Point3F & normal)
```

Returns a perpendicular vector to the unit length input vector.

```Point3F
```
```mReflect(const Point3F & v, const Point3F & n)
```

Returns a copy of the vector reflected by a normal.

```Point3F
```
```operator*(F32 mul, const Point3F & multiplicand)
```
```Point3D
```
```operator*(F64 mul, const Point3D & multiplicand)
```
```Point3I
```
```operator*(S32 mul, const Point3I & multiplicand)
```

## Public Typedefs

```typedef Point3F EulerF
```
```typedef Point3F VectorF
```

## Public Functions

```mCross(const Point3D & a, const Point3D & b)
```

```mCross(const Point3D & a, const Point3D & b, Point3D * res)
```

```mCross(const Point3F & a, const Point3F & b)
```

```mCross(const Point3F & a, const Point3F & b, Point3F * res)
```

```mDot(const Point3D & p1, const Point3D & p2)
```

```mDot(const Point3F & p1, const Point3F & p2)
```

```mIsNaN(const Point3F & p)
```

Returns true if the point is NaN.

```mNormalize(const Point3F & vec)
```

Returns the vector normalized.

```mPerp(const Point3F & normal)
```

Returns a perpendicular vector to the unit length input vector.

```mReflect(const Point3F & v, const Point3F & n)
```

Returns a copy of the vector reflected by a normal.

```operator*(F32 mul, const Point3F & multiplicand)
```

```operator*(F64 mul, const Point3D & multiplicand)
```

```operator*(S32 mul, const Point3I & multiplicand)
```

```   1
2//-----------------------------------------------------------------------------
3// Copyright (c) 2012 GarageGames, LLC
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to
7// deal in the Software without restriction, including without limitation the
8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _MPOINT3_H_
25#define _MPOINT3_H_
26
27#ifndef _MMATHFN_H_
28#include "math/mMathFn.h"
29#endif
30#ifndef _MPOINT2_H_
31#include "math/mPoint2.h"
32#endif
33
34//------------------------------------------------------------------------------
35/// 3D integer point
36///
37/// Uses S32 internally.
38class Point3I
39{
40   //-------------------------------------- Public data
41  public:
42   S32 x;                                                   ///< X co-ordinate
43   S32 y;                                                   ///< Y co-ordinate
44   S32 z;                                                   ///< Z co-ordinate
45
46   //-------------------------------------- Public interface
47  public:
48   Point3I();               ///< Create an uninitialized point.
49   Point3I(const Point3I&); ///< Copy constructor.
50   explicit Point3I(S32 xyz);        ///< Initializes all elements to the same value.
51   Point3I(S32 in_x, S32 in_y, S32 in_z); ///< Create a point from co-ordinates.
52
53   //-------------------------------------- Non-math mutators and misc functions
54   void set(S32 xyz);           ///< Initializes all elements to the same value.
55   void set(S32 in_x, S32 in_y, S32 in_z); ///< Set co-ordinates.
56   void setMin(const Point3I&); ///< Store lesser co-ordinates in this point.
57   void setMax(const Point3I&); ///< Store greater co-ordinates in this point.
58   void zero();                 ///< Zero all values
59
60   //-------------------------------------- Math mutators
61   void neg();                      ///< Invert co-ordinate's signs.
62   void convolve(const Point3I&);   ///< Convolve by parameter.
63
64   //-------------------------------------- Queries
65   bool isZero() const;             ///< Check for point at origin. (No epsilon.)
66   F32  len() const;                ///< Get length.
67
69  public:
70   operator S32*() { return &x; }
71   operator const S32*() const { return &x; }
72
73   // Comparison operators
74   bool operator==(const Point3I&) const;
75   bool operator!=(const Point3I&) const;
76
77   // Arithmetic w/ other points
78   Point3I  operator+(const Point3I&) const;
79   Point3I  operator-(const Point3I&) const;
80   Point3I& operator+=(const Point3I&);
81   Point3I& operator-=(const Point3I&);
82
83   // Arithmetic w/ scalars
84   Point3I  operator*(S32) const;
85   Point3I& operator*=(S32);
86   Point3I  operator/(S32) const;
87   Point3I& operator/=(S32);
88
89   // Unary operators
90   Point3I operator-() const;
91
92   //-------------------------------------- Public static constants
93public:
94   const static Point3I One;
95   const static Point3I Zero;
96};
97
98class Point3D;
99
100//------------------------------------------------------------------------------
101class Point3F
102{
103   //-------------------------------------- Public data
104  public:
105   F32 x;
106   F32 y;
107   F32 z;
108
109  public:
110   Point3F();
111   Point3F(const Point3F&);
112   Point3F(F32 _x, F32 _y, F32 _z);
113   explicit Point3F(F32 xyz);
114
115   //-------------------------------------- Non-math mutators and misc functions
116  public:
117   void set(F32 xyz);
118   void set(F32 _x, F32 _y, F32 _z);
119   void set(const Point3F&);
120
121   void setMin(const Point3F&);
122   void setMax(const Point3F&);
123
124   void interpolate(const Point3F&, const Point3F&, F32);
125   void zero();
126
127   /// Returns the smallest absolute value.
128   F32 least() const;
129
130   /// Returns the greatest absolute value.
131   F32 most() const;
132
133   operator F32*() { return &x; }
134   operator const F32*() const { return &x; }
135
136   /// Returns the x and y coords as a Point2F.
137   Point2F asPoint2F() const { return Point2F( x, y ); }
138
139   //-------------------------------------- Queries
140  public:
141   bool  isZero() const;
142   bool  isUnitLength() const;
143   F32   len()    const;
144   F32   lenSquared() const;
145   F32   magnitudeSafe() const;
146   bool  equal( const Point3F &compare, F32 epsilon = POINT_EPSILON ) const;
147   U32   getLeastComponentIndex() const;
148   U32   getGreatestComponentIndex() const;
149
150   //-------------------------------------- Mathematical mutators
151  public:
152   void neg();
153   void normalize();
154   void normalizeSafe();
155   void normalize(F32 val);
156   void convolve(const Point3F&);
157   void convolveInverse(const Point3F&);
158
160  public:
161   // Comparison operators
162   bool operator==(const Point3F&) const;
163   bool operator!=(const Point3F&) const;
164
165   // Arithmetic w/ other points
166   Point3F  operator+(const Point3F&) const;
167   Point3F  operator-(const Point3F&) const;
168   Point3F& operator+=(const Point3F&);
169   Point3F& operator-=(const Point3F&);
170
171   // Arithmetic w/ scalars
172   Point3F  operator*(F32) const;
173   Point3F  operator/(F32) const;
174   Point3F& operator*=(F32);
175   Point3F& operator/=(F32);
176
177   Point3F  operator*(const Point3F&) const;
178   Point3F& operator*=(const Point3F&);
179   Point3F  operator/(const Point3F&) const;
180   Point3F& operator/=(const Point3F&);
181
182   // Unary operators
183   Point3F operator-() const;
184
185   Point3F& operator=(const Point3D&);
186
187   //-------------------------------------- Public static constants
188public:
189   const static Point3F One;
190   const static Point3F Zero;
191   const static Point3F Max;
192   const static Point3F Min;
193   const static Point3F UnitX;
194   const static Point3F UnitY;
195   const static Point3F UnitZ;
196};
197
198typedef Point3F VectorF;
199typedef Point3F EulerF;
200
201
202//------------------------------------------------------------------------------
203class Point3D
204{
205   //-------------------------------------- Public data
206  public:
207   F64 x;
208   F64 y;
209   F64 z;
210
211  public:
212   Point3D();
213   Point3D(const Point3D&);
214   Point3D(const Point3F&);
215   explicit Point3D(F64 xyz);
216   Point3D(F64 _x, F64 _y, F64 _z);
217
218   //-------------------------------------- Non-math mutators and misc functions
219  public:
220   void set(F64 xyz);
221   void set(F64 _x, F64 _y, F64 _z);
222
223   void setMin(const Point3D&);
224   void setMax(const Point3D&);
225
226   void interpolate(const Point3D&, const Point3D&, F64);
227   void zero();
228
229   operator F64*() { return (&x); }
230   operator const F64*() const { return &x; }
231
232   //-------------------------------------- Queries
233  public:
234   bool  isZero() const;
235   F64 len()    const;
236   F64 lenSquared() const;
237   F64 magnitudeSafe() const;
238
239   //-------------------------------------- Mathematical mutators
240  public:
241   void neg();
242   void normalize();
243   void normalizeSafe();
244   void normalize(F64 val);
245   void convolve(const Point3D&);
246   void convolveInverse(const Point3D&);
247
249  public:
250   Point3F toPoint3F() const;
251   // Comparison operators
252   bool operator==(const Point3D&) const;
253   bool operator!=(const Point3D&) const;
254
255   // Arithmetic w/ other points
256   Point3D  operator+(const Point3D&) const;
257   Point3D  operator-(const Point3D&) const;
258   Point3D& operator+=(const Point3D&);
259   Point3D& operator-=(const Point3D&);
260
261   // Arithmetic w/ scalars
262   Point3D  operator*(F64) const;
263   Point3D  operator/(F64) const;
264   Point3D& operator*=(F64);
265   Point3D& operator/=(F64);
266
267   // Unary operators
268   Point3D operator-() const;
269
270   //-------------------------------------- Public static constants
271public:
272   const static Point3D One;
273   const static Point3D Zero;
274};
275
276//------------------------------------------------------------------------------
277//-------------------------------------- Point3I
278//
279inline Point3I::Point3I()
280   : x(0), y(0), z(0)
281{
282}
283
284inline Point3I::Point3I(const Point3I& _copy)
285 : x(_copy.x), y(_copy.y), z(_copy.z)
286{
287   //
288}
289
290inline Point3I::Point3I(S32 xyz)
291 : x(xyz), y(xyz), z(xyz)
292{
293   //
294}
295
296inline Point3I::Point3I(S32 _x, S32 _y, S32 _z)
297 : x(_x), y(_y), z(_z)
298{
299   //
300}
301
302inline void Point3I::set(S32 xyz)
303{
304   x = y = z = xyz;
305}
306
307inline void Point3I::set(S32 _x, S32 _y, S32 _z)
308{
309   x = _x;
310   y = _y;
311   z = _z;
312}
313
314inline void Point3I::setMin(const Point3I& _test)
315{
316   x = (_test.x < x) ? _test.x : x;
317   y = (_test.y < y) ? _test.y : y;
318   z = (_test.z < z) ? _test.z : z;
319}
320
321inline void Point3I::setMax(const Point3I& _test)
322{
323   x = (_test.x > x) ? _test.x : x;
324   y = (_test.y > y) ? _test.y : y;
325   z = (_test.z > z) ? _test.z : z;
326}
327
328inline void Point3I::zero()
329{
330   x = y = z = 0;
331}
332
333inline void Point3I::neg()
334{
335   x = -x;
336   y = -y;
337   z = -z;
338}
339
340inline F32 Point3I::len() const
341{
342   return mSqrt(F32(x*x + y*y + z*z));
343}
344
345inline void Point3I::convolve(const Point3I& c)
346{
347   x *= c.x;
348   y *= c.y;
349   z *= c.z;
350}
351
352inline bool Point3I::isZero() const
353{
354   return ((x == 0) && (y == 0) && (z == 0));
355}
356
357inline bool Point3I::operator==(const Point3I& _test) const
358{
359   return ((x == _test.x) && (y == _test.y) && (z == _test.z));
360}
361
362inline bool Point3I::operator!=(const Point3I& _test) const
363{
364   return (operator==(_test) == false);
365}
366
367inline Point3I Point3I::operator+(const Point3I& _add) const
368{
370}
371
372inline Point3I Point3I::operator-(const Point3I& _rSub) const
373{
374   return Point3I(x - _rSub.x, y - _rSub.y, z - _rSub.z);
375}
376
378{
382
383   return *this;
384}
385
386inline Point3I& Point3I::operator-=(const Point3I& _rSub)
387{
388   x -= _rSub.x;
389   y -= _rSub.y;
390   z -= _rSub.z;
391
392   return *this;
393}
394
395inline Point3I Point3I::operator-() const
396{
397   return Point3I(-x, -y, -z);
398}
399
400inline Point3I Point3I::operator*(S32 mul) const
401{
402   return Point3I(x * mul, y * mul, z * mul);
403}
404
405inline Point3I Point3I::operator/(S32 div) const
406{
407   AssertFatal(div != 0, "Error, div by zero attempted");
408   return Point3I(x/div, y/div, z/div);
409}
410
411inline Point3I& Point3I::operator*=(S32 mul)
412{
413   x *= mul;
414   y *= mul;
415   z *= mul;
416
417   return *this;
418}
419
420inline Point3I& Point3I::operator/=(S32 div)
421{
422   AssertFatal(div != 0, "Error, div by zero attempted");
423
424   x /= div;
425   y /= div;
426   z /= div;
427
428   return *this;
429}
430
431//------------------------------------------------------------------------------
432//-------------------------------------- Point3F
433//
434inline Point3F::Point3F()
435 : x(0.0f), y(0.0f), z(0.0f)
436{
437// Uninitialized points are definitely a problem.
438// Enable the following code to see how often they crop up.
439#ifdef DEBUG_MATH
440   *(U32 *)&x = 0x7FFFFFFA;
441   *(U32 *)&y = 0x7FFFFFFB;
442   *(U32 *)&z = 0x7FFFFFFC;
443#endif
444}
445
446
447inline Point3F::Point3F(const Point3F& _copy)
448 : x(_copy.x), y(_copy.y), z(_copy.z)
449{
450   //
451}
452
453inline Point3F::Point3F(F32 _x, F32 _y, F32 _z)
454 : x(_x), y(_y), z(_z)
455{
456   //
457}
458
459inline Point3F::Point3F(F32 xyz)
460 : x(xyz), y(xyz), z(xyz)
461{
462   //
463}
464
465inline void Point3F::set(F32 xyz)
466{
467   x = y = z = xyz;
468}
469
470inline void Point3F::set(F32 _x, F32 _y, F32 _z)
471{
472   x = _x;
473   y = _y;
474   z = _z;
475}
476
477inline void Point3F::set(const Point3F& copy)
478{
479   x = copy.x;
480   y = copy.y;
481   z = copy.z;
482}
483
484inline void Point3F::setMin(const Point3F& _test)
485{
486   x = (_test.x < x) ? _test.x : x;
487   y = (_test.y < y) ? _test.y : y;
488   z = (_test.z < z) ? _test.z : z;
489}
490
491inline void Point3F::setMax(const Point3F& _test)
492{
493   x = (_test.x > x) ? _test.x : x;
494   y = (_test.y > y) ? _test.y : y;
495   z = (_test.z > z) ? _test.z : z;
496}
497
498inline void Point3F::interpolate(const Point3F& _from, const Point3F& _to, F32 _factor)
499{
500   AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor");
501   m_point3F_interpolate( _from, _to, _factor, *this);
502}
503
504inline void Point3F::zero()
505{
506   x = y = z = 0.0f;
507}
508
509inline bool Point3F::isZero() const
510{
511   return ((x*x) <= POINT_EPSILON) && ((y*y) <= POINT_EPSILON) && ((z*z) <= POINT_EPSILON );
512}
513
514inline bool Point3F::isUnitLength() const
515{
516   return ( mFabs( 1.0f - ( x*x + y*y + z*z ) ) < POINT_EPSILON );
517}
518
519inline bool Point3F::equal( const Point3F &compare, F32 epsilon ) const
520{
521   return( ( mFabs( x - compare.x ) < epsilon ) &&
522           ( mFabs( y - compare.y ) < epsilon ) &&
523           ( mFabs( z - compare.z ) < epsilon ) );
524}
525
526inline U32 Point3F::getLeastComponentIndex() const
527{
528   U32 idx;
529
530   if ( mFabs( x ) < mFabs( y ) )
531   {
532      if ( mFabs( x ) < mFabs( z ) )
533         idx = 0;
534      else
535         idx = 2;
536   }
537   else
538   {
539      if ( mFabs( y ) < mFabs( z ) )
540         idx = 1;
541      else
542         idx = 2;
543   }
544
545   return idx;
546}
547
548inline U32 Point3F::getGreatestComponentIndex() const
549{
550   U32 idx;
551
552   if ( mFabs( x ) > mFabs( y ) )
553   {
554      if ( mFabs( x ) > mFabs( z ) )
555         idx = 0;
556      else
557         idx = 2;
558   }
559   else
560   {
561      if ( mFabs( y ) > mFabs( z ) )
562         idx = 1;
563      else
564         idx = 2;
565   }
566
567   return idx;
568}
569
570inline F32 Point3F::least() const
571{
572   return getMin( mFabs( x ), getMin( mFabs( y ), mFabs( z ) ) );
573}
574
575inline F32 Point3F::most() const
576{
577   return getMax( mFabs( x ), getMax( mFabs( y ), mFabs( z ) ) );
578}
579
580inline void Point3F::neg()
581{
582   x = -x;
583   y = -y;
584   z = -z;
585}
586
587inline void Point3F::convolve(const Point3F& c)
588{
589   x *= c.x;
590   y *= c.y;
591   z *= c.z;
592}
593
594inline void Point3F::convolveInverse(const Point3F& c)
595{
596   x /= c.x;
597   y /= c.y;
598   z /= c.z;
599}
600
601inline F32 Point3F::lenSquared() const
602{
603   return (x * x) + (y * y) + (z * z);
604}
605
606inline F32 Point3F::len() const
607{
608   return mSqrt(x*x + y*y + z*z);
609}
610
611inline void Point3F::normalize()
612{
613   m_point3F_normalize(*this);
614}
615
616inline F32 Point3F::magnitudeSafe() const
617{
618   if( isZero() )
619   {
620      return 0.0f;
621   }
622   else
623   {
624      return len();
625   }
626}
627
628inline void Point3F::normalizeSafe()
629{
630   F32 vmag = magnitudeSafe();
631
632   if( vmag > POINT_EPSILON )
633   {
634      *this *= F32(1.0 / vmag);
635   }
636}
637
638
639inline void Point3F::normalize(F32 val)
640{
641   m_point3F_normalize_f(*this, val);
642}
643
644inline bool Point3F::operator==(const Point3F& _test) const
645{
646   return (x == _test.x) && (y == _test.y) && (z == _test.z);
647}
648
649inline bool Point3F::operator!=(const Point3F& _test) const
650{
651   return operator==(_test) == false;
652}
653
654inline Point3F Point3F::operator+(const Point3F& _add) const
655{
657}
658
659inline Point3F Point3F::operator-(const Point3F& _rSub) const
660{
661   return Point3F(x - _rSub.x, y - _rSub.y, z - _rSub.z);
662}
663
665{
669
670   return *this;
671}
672
673inline Point3F& Point3F::operator-=(const Point3F& _rSub)
674{
675   x -= _rSub.x;
676   y -= _rSub.y;
677   z -= _rSub.z;
678
679   return *this;
680}
681
682inline Point3F Point3F::operator*(F32 _mul) const
683{
684   return Point3F(x * _mul, y * _mul, z * _mul);
685}
686
687inline Point3F Point3F::operator/(F32 _div) const
688{
689   AssertFatal(_div != 0.0f, "Error, div by zero attempted");
690
691   F32 inv = 1.0f / _div;
692
693   return Point3F(x * inv, y * inv, z * inv);
694}
695
696inline Point3F& Point3F::operator*=(F32 _mul)
697{
698   x *= _mul;
699   y *= _mul;
700   z *= _mul;
701
702   return *this;
703}
704
705inline Point3F& Point3F::operator/=(F32 _div)
706{
707   AssertFatal(_div != 0.0f, "Error, div by zero attempted");
708
709   F32 inv = 1.0f / _div;
710   x *= inv;
711   y *= inv;
712   z *= inv;
713
714   return *this;
715}
716
717inline Point3F Point3F::operator*(const Point3F &_vec) const
718{
719   return Point3F(x * _vec.x, y * _vec.y, z * _vec.z);
720}
721
722inline Point3F& Point3F::operator*=(const Point3F &_vec)
723{
724   x *= _vec.x;
725   y *= _vec.y;
726   z *= _vec.z;
727   return *this;
728}
729
730inline Point3F Point3F::operator/(const Point3F &_vec) const
731{
732   AssertFatal(_vec.x != 0.0f && _vec.y != 0.0f && _vec.z != 0.0f, "Error, div by zero attempted");
733   return Point3F(x / _vec.x, y / _vec.y, z / _vec.z);
734}
735
736inline Point3F& Point3F::operator/=(const Point3F &_vec)
737{
738   AssertFatal(_vec.x != 0.0f && _vec.y != 0.0f && _vec.z != 0.0f, "Error, div by zero attempted");
739   x /= _vec.x;
740   y /= _vec.y;
741   z /= _vec.z;
742   return *this;
743}
744
745inline Point3F Point3F::operator-() const
746{
747   return Point3F(-x, -y, -z);
748}
749
750
751inline Point3F& Point3F::operator=(const Point3D &_vec)
752{
753   x = (F32)_vec.x;
754   y = (F32)_vec.y;
755   z = (F32)_vec.z;
756   return *this;
757}
758
759//------------------------------------------------------------------------------
760//-------------------------------------- Point3D
761//
762inline Point3D::Point3D()
763   : x(0.0), y(0.0), z(0.0)
764{
765   //
766}
767
768inline Point3D::Point3D(const Point3D& _copy)
769 : x(_copy.x), y(_copy.y), z(_copy.z)
770{
771   //
772}
773
774inline Point3D::Point3D(const Point3F& _copy)
775 : x(_copy.x), y(_copy.y), z(_copy.z)
776{
777   //
778}
779
780inline Point3D::Point3D(F64 xyz)
781 : x(xyz), y(xyz), z(xyz)
782{
783   //
784}
785
786inline Point3D::Point3D(F64 _x, F64 _y, F64 _z)
787 : x(_x), y(_y), z(_z)
788{
789   //
790}
791
792inline void Point3D::set( F64 xyz )
793{
794   x = y = z = xyz;
795}
796
797inline void Point3D::set(F64 _x, F64 _y, F64 _z)
798{
799   x = _x;
800   y = _y;
801   z = _z;
802}
803
804inline void Point3D::setMin(const Point3D& _test)
805{
806   x = (_test.x < x) ? _test.x : x;
807   y = (_test.y < y) ? _test.y : y;
808   z = (_test.z < z) ? _test.z : z;
809}
810
811inline void Point3D::setMax(const Point3D& _test)
812{
813   x = (_test.x > x) ? _test.x : x;
814   y = (_test.y > y) ? _test.y : y;
815   z = (_test.z > z) ? _test.z : z;
816}
817
818inline void Point3D::interpolate(const Point3D& _from, const Point3D& _to, F64 _factor)
819{
820   AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor");
821   m_point3D_interpolate( _from, _to, _factor, *this);
822}
823
824inline void Point3D::zero()
825{
826   x = y = z = 0.0;
827}
828
829inline bool Point3D::isZero() const
830{
831   return (x == 0.0f) && (y == 0.0f) && (z == 0.0f);
832}
833
834inline void Point3D::neg()
835{
836   x = -x;
837   y = -y;
838   z = -z;
839}
840
841inline void Point3D::convolve(const Point3D& c)
842{
843   x *= c.x;
844   y *= c.y;
845   z *= c.z;
846}
847
848inline void Point3D::convolveInverse(const Point3D& c)
849{
850   x /= c.x;
851   y /= c.y;
852   z /= c.z;
853}
854
855inline F64 Point3D::lenSquared() const
856{
857   return (x * x) + (y * y) + (z * z);
858}
859
860inline F64 Point3D::len() const
861{
862   F64 temp = x*x + y*y + z*z;
863   return (temp > 0.0) ? mSqrtD(temp) : 0.0;
864}
865
866inline void Point3D::normalize()
867{
868   m_point3D_normalize(*this);
869}
870
871inline F64 Point3D::magnitudeSafe() const
872{
873   if( isZero() )
874   {
875      return 0.0;
876   }
877   else
878   {
879      return len();
880   }
881}
882
883inline void Point3D::normalizeSafe()
884{
885   F64 vmag = magnitudeSafe();
886
887   if( vmag > POINT_EPSILON )
888   {
889      *this *= F64(1.0 / vmag);
890   }
891}
892
893inline void Point3D::normalize(F64 val)
894{
895   m_point3D_normalize_f(*this, val);
896}
897
898inline bool Point3D::operator==(const Point3D& _test) const
899{
900   return (x == _test.x) && (y == _test.y) && (z == _test.z);
901}
902
903inline bool Point3D::operator!=(const Point3D& _test) const
904{
905   return operator==(_test) == false;
906}
907
908inline Point3D Point3D::operator+(const Point3D& _add) const
909{
911}
912
913
914inline Point3D Point3D::operator-(const Point3D& _rSub) const
915{
916   return Point3D(x - _rSub.x, y - _rSub.y, z - _rSub.z);
917}
918
920{
924
925   return *this;
926}
927
928inline Point3D& Point3D::operator-=(const Point3D& _rSub)
929{
930   x -= _rSub.x;
931   y -= _rSub.y;
932   z -= _rSub.z;
933
934   return *this;
935}
936
937inline Point3D Point3D::operator*(F64 _mul) const
938{
939   return Point3D(x * _mul, y * _mul, z * _mul);
940}
941
942inline Point3D Point3D::operator/(F64 _div) const
943{
944   AssertFatal(_div != 0.0f, "Error, div by zero attempted");
945
946   F64 inv = 1.0f / _div;
947
948   return Point3D(x * inv, y * inv, z * inv);
949}
950
951inline Point3D& Point3D::operator*=(F64 _mul)
952{
953   x *= _mul;
954   y *= _mul;
955   z *= _mul;
956
957   return *this;
958}
959
960inline Point3D& Point3D::operator/=(F64 _div)
961{
962   AssertFatal(_div != 0.0f, "Error, div by zero attempted");
963
964   F64 inv = 1.0f / _div;
965   x *= inv;
966   y *= inv;
967   z *= inv;
968
969   return *this;
970}
971
972inline Point3D Point3D::operator-() const
973{
974   return Point3D(-x, -y, -z);
975}
976
977inline Point3F Point3D::toPoint3F() const
978{
979   return Point3F((F32)x,(F32)y,(F32)z);
980}
981
982//-------------------------------------------------------------------
983// Non-Member Operators
984//-------------------------------------------------------------------
985
986inline Point3I operator*(S32 mul, const Point3I& multiplicand)
987{
988   return multiplicand * mul;
989}
990
991inline Point3F operator*(F32 mul, const Point3F& multiplicand)
992{
993   return multiplicand * mul;
994}
995
996inline Point3D operator*(F64 mul, const Point3D& multiplicand)
997{
998   return multiplicand * mul;
999}
1000
1001inline F32 mDot(const Point3F &p1, const Point3F &p2)
1002{
1003   return (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z);
1004}
1005
1006inline F64 mDot(const Point3D &p1, const Point3D &p2)
1007{
1008   return (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z);
1009}
1010
1011inline void mCross(const Point3F &a, const Point3F &b, Point3F *res)
1012{
1013   res->x = (a.y * b.z) - (a.z * b.y);
1014   res->y = (a.z * b.x) - (a.x * b.z);
1015   res->z = (a.x * b.y) - (a.y * b.x);
1016}
1017
1018inline void mCross(const Point3D &a, const Point3D &b, Point3D *res)
1019{
1020   res->x = (a.y * b.z) - (a.z * b.y);
1021   res->y = (a.z * b.x) - (a.x * b.z);
1022   res->z = (a.x * b.y) - (a.y * b.x);
1023}
1024
1025inline Point3F mCross(const Point3F &a, const Point3F &b)
1026{
1027   Point3F r;
1028   mCross( a, b, &r );
1029   return r;
1030}
1031
1032inline Point3D mCross(const Point3D &a, const Point3D &b)
1033{
1034   Point3D r;
1035   mCross( a, b, &r );
1036   return r;
1037}
1038
1039/// Returns the vector normalized.
1040inline Point3F mNormalize( const Point3F &vec )
1041{
1042   Point3F out( vec );
1043   out.normalize();
1044   return out;
1045}
1046
1047/// Returns true if the point is NaN.
1048inline bool mIsNaN( const Point3F &p )
1049{
1050   return mIsNaN_F( p.x ) || mIsNaN_F( p.y ) || mIsNaN_F( p.z );
1051}
1052
1053/// Returns a copy of the vector reflected by a normal
1054inline Point3F mReflect( const Point3F &v, const Point3F &n )
1055{
1056   return v - 2 * n * mDot( v, n );
1057}
1058
1059/// Returns a perpendicular vector to the unit length input vector.
1060extern Point3F mPerp( const Point3F &normal );
1061
1062#endif // _MPOINT3_H_
1063
```