mPoint.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MPOINT_H_
  23. #define _MPOINT_H_
  24. #define POINT_EPSILON (1e-4) ///< Epsilon for point types.
  25. //-------------------------------------- Note: because of a circular dependency,
  26. // the mMathFn.h header is below the point
  27. // class declarations... DMM
  28. #ifndef _PLATFORM_H_
  29. #include "platform/platform.h"
  30. #endif
  31. //------------------------------------------------------------------------------
  32. /// 2D integer point
  33. ///
  34. /// Uses S32 internally.
  35. class Point2I
  36. {
  37. //-------------------------------------- Public data
  38. public:
  39. S32 x; ///< X position
  40. S32 y; ///< Y position
  41. //-------------------------------------- Public interface
  42. public:
  43. Point2I(); ///< Create an uninitialized point.
  44. Point2I(const Point2I&); ///< Copy constructor
  45. Point2I(const S32 in_x, const S32 in_y); ///< Create point from two co-ordinates.
  46. //-------------------------------------- Non-math mutators and misc functions
  47. void set(const S32 in_x, const S32 in_y);///< Set (x,y) position
  48. void setMin(const Point2I&); ///< Store lesser co-ordinates from parameter in this point.
  49. void setMax(const Point2I&); ///< Store greater co-ordinates from parameter in this point.
  50. //-------------------------------------- Math mutators
  51. void neg(); ///< Invert sign of point's co-ordinates.
  52. void convolve(const Point2I&); ///< Convolve this point by parameter.
  53. //-------------------------------------- Queries
  54. bool isZero() const; ///< Is this point at the origin? (No epsilon used)
  55. F32 len() const; ///< Get the length of the point
  56. //-------------------------------------- Overloaded operators
  57. public:
  58. // Comparison operators
  59. bool operator==(const Point2I&) const;
  60. bool operator!=(const Point2I&) const;
  61. // Arithmetic w/ other points
  62. Point2I operator+(const Point2I&) const;
  63. Point2I operator-(const Point2I&) const;
  64. Point2I& operator+=(const Point2I&);
  65. Point2I& operator-=(const Point2I&);
  66. // Arithmetic w/ scalars
  67. Point2I operator*(const S32) const;
  68. Point2I& operator*=(const S32);
  69. Point2I operator/(const S32) const;
  70. Point2I& operator/=(const S32);
  71. // Unary operators
  72. Point2I operator-() const;
  73. //-------------------------------------- Public static constants
  74. public:
  75. const static Point2I One;
  76. const static Point2I Zero;
  77. const static Point2I Min;
  78. const static Point2I Max;
  79. };
  80. //------------------------------------------------------------------------------
  81. /// 3D integer point
  82. ///
  83. /// Uses S32 internally.
  84. class Point3I
  85. {
  86. //-------------------------------------- Public data
  87. public:
  88. S32 x; ///< X co-ordinate
  89. S32 y; ///< Y co-ordinate
  90. S32 z; ///< Z co-ordinate
  91. //-------------------------------------- Public interface
  92. public:
  93. Point3I(); ///< Create an uninitialized point.
  94. Point3I(const Point3I&); ///< Copy constructor.
  95. Point3I(const S32 in_x, const S32 in_y, const S32 in_z); ///< Create a point from co-ordinates.
  96. //-------------------------------------- Non-math mutators and misc functions
  97. void set(const S32 in_x, const S32 in_y, const S32 in_z);///< Set co-ordinates.
  98. void setMin(const Point3I&); ///< Store lesser co-ordinates in this point.
  99. void setMax(const Point3I&); ///< Store greater co-ordinates in this point.
  100. //-------------------------------------- Math mutators
  101. void neg(); ///< Invert co-ordinate's signs.
  102. void convolve(const Point3I&); ///< Convolve by paramater.
  103. //-------------------------------------- Queries
  104. bool isZero() const; ///< Check for point at origin. (No epsilon.)
  105. F32 len() const; ///< Get length.
  106. //-------------------------------------- Overloaded operators
  107. public:
  108. // Comparison operators
  109. bool operator==(const Point3I&) const;
  110. bool operator!=(const Point3I&) const;
  111. // Arithmetic w/ other points
  112. Point3I operator+(const Point3I&) const;
  113. Point3I operator-(const Point3I&) const;
  114. Point3I& operator+=(const Point3I&);
  115. Point3I& operator-=(const Point3I&);
  116. // Arithmetic w/ scalars
  117. Point3I operator*(const S32) const;
  118. Point3I& operator*=(const S32);
  119. Point3I operator/(const S32) const;
  120. Point3I& operator/=(const S32);
  121. // Unary operators
  122. Point3I operator-() const;
  123. //-------------------------------------- Public static constants
  124. public:
  125. const static Point3I One;
  126. const static Point3I Zero;
  127. };
  128. //------------------------------------------------------------------------------
  129. /// 2D floating-point point.
  130. class Point2F
  131. {
  132. //-------------------------------------- Public data
  133. public:
  134. F32 x;
  135. F32 y;
  136. public:
  137. Point2F(); ///< Create uninitialized point.
  138. Point2F(const Point2F&); ///< Copy constructor
  139. Point2F(const F32 _x, const F32 _y); ///< Create point from co-ordinates.
  140. //-------------------------------------- Non-math mutators and misc functions
  141. public:
  142. void set(const F32 _x, const F32 _y);///< Set point's co-ordinates.
  143. void setMin(const Point2F&); ///< Store lesser co-ordinates.
  144. void setMax(const Point2F&); ///< Store greater co-ordinates.
  145. /// Interpolate from a to b, based on c.
  146. ///
  147. /// @param a Starting point.
  148. /// @param b Ending point.
  149. /// @param c Interpolation factor (0.0 .. 1.0).
  150. void interpolate(const Point2F& a, const Point2F& b, const F32 c);
  151. operator F32*() { return (&x); }
  152. operator F32*() const { return (F32*)(&x); }
  153. //-------------------------------------- Queries
  154. public:
  155. bool isZero() const; ///< Check for zero coordinates. (No epsilon.)
  156. F32 len() const; ///< Get length.
  157. F32 lenSquared() const; ///< Get squared length (one sqrt less than len()).
  158. //-------------------------------------- Mathematical mutators
  159. public:
  160. void neg(); ///< Invert signs of co-ordinates.
  161. void normalize(); ///< Normalize vector.
  162. void normalize(F32 val); ///< Normalize, scaling by val.
  163. void convolve(const Point2F&); ///< Convolve by parameter.
  164. void convolveInverse(const Point2F&); ///< Inversely convolute by parameter. (ie, divide)
  165. //Luma: Utility function to round a Point2F
  166. void round() {x = (F32)((S32)(x + 0.5f)); y = (F32)((S32)(y + 0.5f));}
  167. //-------------------------------------- Overloaded operators
  168. public:
  169. // Comparison operators
  170. bool operator==(const Point2F&) const;
  171. bool operator!=(const Point2F&) const;
  172. // Arithmetic w/ other points
  173. Point2F operator+(const Point2F&) const;
  174. Point2F operator-(const Point2F&) const;
  175. Point2F& operator+=(const Point2F&);
  176. Point2F& operator-=(const Point2F&);
  177. // Arithmetic w/ scalars
  178. Point2F operator*(const F32) const;
  179. Point2F operator/(const F32) const;
  180. Point2F& operator*=(const F32);
  181. Point2F& operator/=(const F32);
  182. // Unary operators
  183. Point2F operator-() const;
  184. //-------------------------------------- Public static constants
  185. public:
  186. const static Point2F One;
  187. const static Point2F Zero;
  188. const static Point2F Min;
  189. const static Point2F Max;
  190. };
  191. //------------------------------------------------------------------------------
  192. /// 2D high-precision point.
  193. ///
  194. /// Uses F64 internally.
  195. class Point2D
  196. {
  197. //-------------------------------------- Public data
  198. public:
  199. F64 x; ///< X co-ordinate.
  200. F64 y; ///< Y co-ordinate.
  201. public:
  202. Point2D(); ///< Create uninitialized point.
  203. Point2D(const Point2D&); ///< Copy constructor
  204. Point2D(const F64 _x, const F64 _y); ///< Create point from coordinates.
  205. //-------------------------------------- Non-math mutators and misc functions
  206. public:
  207. void set(const F64 _x, const F64 _y);///< Set point's coordinates.
  208. void setMin(const Point2D&); ///< Store lesser co-ordinates.
  209. void setMax(const Point2D&); ///< Store greater co-ordinates.
  210. /// Interpolate from a to b, based on c.
  211. ///
  212. /// @param a Starting point.
  213. /// @param b Ending point.
  214. /// @param c Interpolation factor (0.0 .. 1.0).
  215. void interpolate(const Point2D &a, const Point2D &b, const F64 c);
  216. operator F64*() { return (&x); }
  217. operator F64*() const { return (F64*)(&x); }
  218. //-------------------------------------- Queries
  219. public:
  220. bool isZero() const;
  221. F64 len() const;
  222. F64 lenSquared() const;
  223. //-------------------------------------- Mathematical mutators
  224. public:
  225. void neg();
  226. void normalize();
  227. void normalize(F64 val);
  228. void convolve(const Point2D&);
  229. void convolveInverse(const Point2D&);
  230. //-------------------------------------- Overloaded operators
  231. public:
  232. // Comparison operators
  233. bool operator==(const Point2D&) const;
  234. bool operator!=(const Point2D&) const;
  235. // Arithmetic w/ other points
  236. Point2D operator+(const Point2D&) const;
  237. Point2D operator-(const Point2D&) const;
  238. Point2D& operator+=(const Point2D&);
  239. Point2D& operator-=(const Point2D&);
  240. // Arithmetic w/ scalars
  241. Point2D operator*(const F64) const;
  242. Point2D operator/(const F64) const;
  243. Point2D& operator*=(const F64);
  244. Point2D& operator/=(const F64);
  245. // Unary operators
  246. Point2D operator-() const;
  247. //-------------------------------------- Public static constants
  248. public:
  249. const static Point2D One;
  250. const static Point2D Zero;
  251. };
  252. //------------------------------------------------------------------------------
  253. class Point3F
  254. {
  255. //-------------------------------------- Public data
  256. public:
  257. F32 x;
  258. F32 y;
  259. F32 z;
  260. public:
  261. Point3F();
  262. Point3F(const Point3F&);
  263. Point3F(const F32 _x, const F32 _y, const F32 _z);
  264. //-------------------------------------- Non-math mutators and misc functions
  265. public:
  266. void set(const F32 _x, const F32 _y, const F32 _z);
  267. void set(const Point3F&);
  268. void setMin(const Point3F&);
  269. void setMax(const Point3F&);
  270. void interpolate(const Point3F&, const Point3F&, const F32);
  271. void zero();
  272. F32& operator [](int i) { /*ASSERT HERE??*/ return( *((&x)+i) ); }
  273. operator F32*() { return (&x); }
  274. operator F32*() const { return (F32*)(&x); }
  275. //-------------------------------------- Queries
  276. public:
  277. bool isZero() const;
  278. F32 len() const;
  279. F32 lenSquared() const;
  280. F32 magnitudeSafe();
  281. bool equal( Point3F &compare );
  282. //-------------------------------------- Mathematical mutators
  283. public:
  284. void neg();
  285. void normalize();
  286. void normalizeSafe();
  287. void normalize(F32 val);
  288. void convolve(const Point3F&);
  289. void convolveInverse(const Point3F&);
  290. //-------------------------------------- Overloaded operators
  291. public:
  292. // Comparison operators
  293. bool operator==(const Point3F&) const;
  294. bool operator!=(const Point3F&) const;
  295. // Arithmetic w/ other points
  296. Point3F operator+(const Point3F&) const;
  297. Point3F operator-(const Point3F&) const;
  298. Point3F& operator+=(const Point3F&);
  299. Point3F& operator-=(const Point3F&);
  300. // Arithmetic w/ scalars
  301. Point3F operator*(const F32) const;
  302. Point3F operator/(const F32) const;
  303. Point3F& operator*=(const F32);
  304. Point3F& operator/=(const F32);
  305. Point3F operator*(const Point3F&) const;
  306. Point3F& operator*=(const Point3F&);
  307. // Unary operators
  308. Point3F operator-() const;
  309. //-------------------------------------- Public static constants
  310. public:
  311. const static Point3F One;
  312. const static Point3F Zero;
  313. const static Point3F Max;
  314. const static Point3F Min;
  315. const static Point3F UnitX;
  316. const static Point3F UnitY;
  317. const static Point3F UnitZ;
  318. };
  319. typedef Point3F VectorF;
  320. typedef Point3F EulerF;
  321. //------------------------------------------------------------------------------
  322. class Point3D
  323. {
  324. //-------------------------------------- Public data
  325. public:
  326. F64 x;
  327. F64 y;
  328. F64 z;
  329. public:
  330. Point3D();
  331. Point3D(const Point3D&);
  332. Point3D(const F64 _x, const F64 _y, const F64 _z);
  333. //-------------------------------------- Non-math mutators and misc functions
  334. public:
  335. void set(const F64 _x, const F64 _y, const F64 _z);
  336. void setMin(const Point3D&);
  337. void setMax(const Point3D&);
  338. void interpolate(const Point3D&, const Point3D&, const F64);
  339. operator F64*() { return (&x); }
  340. operator F64*() const { return (F64*)(&x); }
  341. //-------------------------------------- Queries
  342. public:
  343. bool isZero() const;
  344. F64 len() const;
  345. F64 lenSquared() const;
  346. //-------------------------------------- Mathematical mutators
  347. public:
  348. void neg();
  349. void normalize();
  350. void normalize(F64 val);
  351. void convolve(const Point3D&);
  352. void convolveInverse(const Point3D&);
  353. //-------------------------------------- Overloaded operators
  354. public:
  355. // Comparison operators
  356. bool operator==(const Point3D&) const;
  357. bool operator!=(const Point3D&) const;
  358. // Arithmetic w/ other points
  359. Point3D operator+(const Point3D&) const;
  360. Point3D operator-(const Point3D&) const;
  361. Point3D& operator+=(const Point3D&);
  362. Point3D& operator-=(const Point3D&);
  363. // Arithmetic w/ scalars
  364. Point3D operator*(const F64) const;
  365. Point3D operator/(const F64) const;
  366. Point3D& operator*=(const F64);
  367. Point3D& operator/=(const F64);
  368. // Unary operators
  369. Point3D operator-() const;
  370. //-------------------------------------- Public static constants
  371. public:
  372. const static Point3D One;
  373. const static Point3D Zero;
  374. };
  375. //------------------------------------------------------------------------------
  376. /// 4D floating-point point.
  377. ///
  378. /// Uses F32 internally.
  379. ///
  380. /// Useful for representing quaternions and other 4d beasties.
  381. class Point4F
  382. {
  383. //-------------------------------------- Public data
  384. public:
  385. F32 x; ///< X co-ordinate.
  386. F32 y; ///< Y co-ordinate.
  387. F32 z; ///< Z co-ordinate.
  388. F32 w; ///< W co-ordinate.
  389. public:
  390. Point4F(); ///< Create an unitialized point.
  391. Point4F(const Point4F&); ///< Copy constructor.
  392. /// Create point from coordinates.
  393. Point4F(const F32 _x, const F32 _y, const F32 _z, const F32 _w);
  394. /// Set point's coordinates.
  395. void set(const F32 _x, const F32 _y, const F32 _z, const F32 _w);
  396. /// Interpolate from _pt1 to _pt2, based on _factor.
  397. ///
  398. /// @param _pt1 Starting point.
  399. /// @param _pt2 Ending point.
  400. /// @param _factor Interpolation factor (0.0 .. 1.0).
  401. void interpolate(const Point4F& _pt1, const Point4F& _pt2, const F32 _factor);
  402. operator F32*() { return (&x); }
  403. operator F32*() const { return (F32*)(&x); }
  404. //-------------------------------------- Public static constants
  405. public:
  406. const static Point4F One;
  407. const static Point4F Zero;
  408. };
  409. typedef Point4F Vector4F; ///< Points can be vectors!
  410. #ifndef _MMATHFN_H_
  411. #include "math/mMathFn.h"
  412. #endif
  413. //------------------------------------------------------------------------------
  414. //-------------------------------------- Inline functions inclusions
  415. //------------------------------------------------------------------------------
  416. //-------------------------------------- Point2I
  417. //
  418. inline Point2I::Point2I()
  419. {
  420. //
  421. }
  422. inline Point2I::Point2I(const Point2I& _copy)
  423. : x(_copy.x), y(_copy.y)
  424. {
  425. //
  426. }
  427. inline Point2I::Point2I(const S32 _x, const S32 _y)
  428. : x(_x), y(_y)
  429. {
  430. //
  431. }
  432. inline void Point2I::set(const S32 _x, const S32 _y)
  433. {
  434. x = _x;
  435. y = _y;
  436. }
  437. inline void Point2I::setMin(const Point2I& _test)
  438. {
  439. x = (_test.x < x) ? _test.x : x;
  440. y = (_test.y < y) ? _test.y : y;
  441. }
  442. inline void Point2I::setMax(const Point2I& _test)
  443. {
  444. x = (_test.x > x) ? _test.x : x;
  445. y = (_test.y > y) ? _test.y : y;
  446. }
  447. inline void Point2I::neg()
  448. {
  449. x = -x;
  450. y = -y;
  451. }
  452. inline void Point2I::convolve(const Point2I& c)
  453. {
  454. x *= c.x;
  455. y *= c.y;
  456. }
  457. inline bool Point2I::isZero() const
  458. {
  459. return ((x == 0) && (y == 0));
  460. }
  461. inline F32 Point2I::len() const
  462. {
  463. return mSqrt(F32(x*x + y*y));
  464. }
  465. inline bool Point2I::operator==(const Point2I& _test) const
  466. {
  467. return ((x == _test.x) && (y == _test.y));
  468. }
  469. inline bool Point2I::operator!=(const Point2I& _test) const
  470. {
  471. return (operator==(_test) == false);
  472. }
  473. inline Point2I Point2I::operator+(const Point2I& _add) const
  474. {
  475. return Point2I(x + _add.x, y + _add.y);
  476. }
  477. inline Point2I Point2I::operator-(const Point2I& _rSub) const
  478. {
  479. return Point2I(x - _rSub.x, y - _rSub.y);
  480. }
  481. inline Point2I& Point2I::operator+=(const Point2I& _add)
  482. {
  483. x += _add.x;
  484. y += _add.y;
  485. return *this;
  486. }
  487. inline Point2I& Point2I::operator-=(const Point2I& _rSub)
  488. {
  489. x -= _rSub.x;
  490. y -= _rSub.y;
  491. return *this;
  492. }
  493. inline Point2I Point2I::operator-() const
  494. {
  495. return Point2I(-x, -y);
  496. }
  497. inline Point2I Point2I::operator*(const S32 mul) const
  498. {
  499. return Point2I(x * mul, y * mul);
  500. }
  501. inline Point2I Point2I::operator/(const S32 div) const
  502. {
  503. AssertFatal(div != 0, "Error, div by zero attempted");
  504. return Point2I(x/div, y/div);
  505. }
  506. inline Point2I& Point2I::operator*=(const S32 mul)
  507. {
  508. x *= mul;
  509. y *= mul;
  510. return *this;
  511. }
  512. inline Point2I& Point2I::operator/=(const S32 div)
  513. {
  514. AssertFatal(div != 0, "Error, div by zero attempted");
  515. x /= div;
  516. y /= div;
  517. return *this;
  518. }
  519. //------------------------------------------------------------------------------
  520. //-------------------------------------- Point3I
  521. //
  522. inline Point3I::Point3I()
  523. {
  524. //
  525. }
  526. inline Point3I::Point3I(const Point3I& _copy)
  527. : x(_copy.x), y(_copy.y), z(_copy.z)
  528. {
  529. //
  530. }
  531. inline Point3I::Point3I(const S32 _x, const S32 _y, const S32 _z)
  532. : x(_x), y(_y), z(_z)
  533. {
  534. //
  535. }
  536. inline void Point3I::set(const S32 _x, const S32 _y, const S32 _z)
  537. {
  538. x = _x;
  539. y = _y;
  540. z = _z;
  541. }
  542. inline void Point3I::setMin(const Point3I& _test)
  543. {
  544. x = (_test.x < x) ? _test.x : x;
  545. y = (_test.y < y) ? _test.y : y;
  546. z = (_test.z < z) ? _test.z : z;
  547. }
  548. inline void Point3I::setMax(const Point3I& _test)
  549. {
  550. x = (_test.x > x) ? _test.x : x;
  551. y = (_test.y > y) ? _test.y : y;
  552. z = (_test.z > z) ? _test.z : z;
  553. }
  554. inline void Point3I::neg()
  555. {
  556. x = -x;
  557. y = -y;
  558. z = -z;
  559. }
  560. inline F32 Point3I::len() const
  561. {
  562. return mSqrt(F32(x*x + y*y + z*z));
  563. }
  564. inline void Point3I::convolve(const Point3I& c)
  565. {
  566. x *= c.x;
  567. y *= c.y;
  568. z *= c.z;
  569. }
  570. inline bool Point3I::isZero() const
  571. {
  572. return ((x == 0) && (y == 0) && (z == 0));
  573. }
  574. inline bool Point3I::operator==(const Point3I& _test) const
  575. {
  576. return ((x == _test.x) && (y == _test.y) && (z == _test.z));
  577. }
  578. inline bool Point3I::operator!=(const Point3I& _test) const
  579. {
  580. return (operator==(_test) == false);
  581. }
  582. inline Point3I Point3I::operator+(const Point3I& _add) const
  583. {
  584. return Point3I(x + _add.x, y + _add.y, z + _add.z);
  585. }
  586. inline Point3I Point3I::operator-(const Point3I& _rSub) const
  587. {
  588. return Point3I(x - _rSub.x, y - _rSub.y, z - _rSub.z);
  589. }
  590. inline Point3I& Point3I::operator+=(const Point3I& _add)
  591. {
  592. x += _add.x;
  593. y += _add.y;
  594. z += _add.z;
  595. return *this;
  596. }
  597. inline Point3I& Point3I::operator-=(const Point3I& _rSub)
  598. {
  599. x -= _rSub.x;
  600. y -= _rSub.y;
  601. z -= _rSub.z;
  602. return *this;
  603. }
  604. inline Point3I Point3I::operator-() const
  605. {
  606. return Point3I(-x, -y, -z);
  607. }
  608. inline Point3I Point3I::operator*(const S32 mul) const
  609. {
  610. return Point3I(x * mul, y * mul, z * mul);
  611. }
  612. inline Point3I Point3I::operator/(const S32 div) const
  613. {
  614. AssertFatal(div != 0, "Error, div by zero attempted");
  615. return Point3I(x/div, y/div, z/div);
  616. }
  617. inline Point3I& Point3I::operator*=(const S32 mul)
  618. {
  619. x *= mul;
  620. y *= mul;
  621. z *= mul;
  622. return *this;
  623. }
  624. inline Point3I& Point3I::operator/=(const S32 div)
  625. {
  626. AssertFatal(div != 0, "Error, div by zero attempted");
  627. x /= div;
  628. y /= div;
  629. z /= div;
  630. return *this;
  631. }
  632. //------------------------------------------------------------------------------
  633. //-------------------------------------- Point2F
  634. //
  635. inline Point2F::Point2F()
  636. {
  637. //
  638. }
  639. inline Point2F::Point2F(const Point2F& _copy)
  640. : x(_copy.x), y(_copy.y)
  641. {
  642. //
  643. }
  644. inline Point2F::Point2F(const F32 _x, const F32 _y)
  645. : x(_x), y(_y)
  646. {
  647. }
  648. inline void Point2F::set(const F32 _x, const F32 _y)
  649. {
  650. x = _x;
  651. y = _y;
  652. }
  653. inline void Point2F::setMin(const Point2F& _test)
  654. {
  655. x = (_test.x < x) ? _test.x : x;
  656. y = (_test.y < y) ? _test.y : y;
  657. }
  658. inline void Point2F::setMax(const Point2F& _test)
  659. {
  660. x = (_test.x > x) ? _test.x : x;
  661. y = (_test.y > y) ? _test.y : y;
  662. }
  663. inline void Point2F::interpolate(const Point2F& _rFrom, const Point2F& _to, const F32 _factor)
  664. {
  665. AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor");
  666. x = (_rFrom.x * (1.0f - _factor)) + (_to.x * _factor);
  667. y = (_rFrom.y * (1.0f - _factor)) + (_to.y * _factor);
  668. }
  669. inline bool Point2F::isZero() const
  670. {
  671. return (x == 0.0f) && (y == 0.0f);
  672. }
  673. inline F32 Point2F::lenSquared() const
  674. {
  675. return (x * x) + (y * y);
  676. }
  677. inline void Point2F::neg()
  678. {
  679. x = -x;
  680. y = -y;
  681. }
  682. inline void Point2F::convolve(const Point2F& c)
  683. {
  684. x *= c.x;
  685. y *= c.y;
  686. }
  687. inline void Point2F::convolveInverse(const Point2F& c)
  688. {
  689. x /= c.x;
  690. y /= c.y;
  691. }
  692. inline bool Point2F::operator==(const Point2F& _test) const
  693. {
  694. return (x == _test.x) && (y == _test.y);
  695. }
  696. inline bool Point2F::operator!=(const Point2F& _test) const
  697. {
  698. return operator==(_test) == false;
  699. }
  700. inline Point2F Point2F::operator+(const Point2F& _add) const
  701. {
  702. return Point2F(x + _add.x, y + _add.y);
  703. }
  704. inline Point2F Point2F::operator-(const Point2F& _rSub) const
  705. {
  706. return Point2F(x - _rSub.x, y - _rSub.y);
  707. }
  708. inline Point2F& Point2F::operator+=(const Point2F& _add)
  709. {
  710. x += _add.x;
  711. y += _add.y;
  712. return *this;
  713. }
  714. inline Point2F& Point2F::operator-=(const Point2F& _rSub)
  715. {
  716. x -= _rSub.x;
  717. y -= _rSub.y;
  718. return *this;
  719. }
  720. inline Point2F Point2F::operator*(const F32 _mul) const
  721. {
  722. return Point2F(x * _mul, y * _mul);
  723. }
  724. inline Point2F Point2F::operator/(const F32 _div) const
  725. {
  726. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  727. F32 inv = 1.0f / _div;
  728. return Point2F(x * inv, y * inv);
  729. }
  730. inline Point2F& Point2F::operator*=(const F32 _mul)
  731. {
  732. x *= _mul;
  733. y *= _mul;
  734. return *this;
  735. }
  736. inline Point2F& Point2F::operator/=(const F32 _div)
  737. {
  738. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  739. F32 inv = 1.0f / _div;
  740. x *= inv;
  741. y *= inv;
  742. return *this;
  743. }
  744. inline Point2F Point2F::operator-() const
  745. {
  746. return Point2F(-x, -y);
  747. }
  748. inline F32 Point2F::len() const
  749. {
  750. return mSqrt(x*x + y*y);
  751. }
  752. inline void Point2F::normalize()
  753. {
  754. m_point2F_normalize(*this);
  755. }
  756. inline void Point2F::normalize(F32 val)
  757. {
  758. m_point2F_normalize_f(*this, val);
  759. }
  760. //------------------------------------------------------------------------------
  761. //-------------------------------------- Point2D
  762. //
  763. inline Point2D::Point2D()
  764. {
  765. //
  766. }
  767. inline Point2D::Point2D(const Point2D& _copy)
  768. : x(_copy.x), y(_copy.y)
  769. {
  770. //
  771. }
  772. inline Point2D::Point2D(const F64 _x, const F64 _y)
  773. : x(_x), y(_y)
  774. {
  775. }
  776. inline void Point2D::set(const F64 _x, const F64 _y)
  777. {
  778. x = _x;
  779. y = _y;
  780. }
  781. inline void Point2D::setMin(const Point2D& _test)
  782. {
  783. x = (_test.x < x) ? _test.x : x;
  784. y = (_test.y < y) ? _test.y : y;
  785. }
  786. inline void Point2D::setMax(const Point2D& _test)
  787. {
  788. x = (_test.x > x) ? _test.x : x;
  789. y = (_test.y > y) ? _test.y : y;
  790. }
  791. inline void Point2D::interpolate(const Point2D& _rFrom, const Point2D& _to, const F64 _factor)
  792. {
  793. AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor");
  794. x = (_rFrom.x * (1.0f - _factor)) + (_to.x * _factor);
  795. y = (_rFrom.y * (1.0f - _factor)) + (_to.y * _factor);
  796. }
  797. inline bool Point2D::isZero() const
  798. {
  799. return (x == 0.0f) && (y == 0.0f);
  800. }
  801. inline F64 Point2D::lenSquared() const
  802. {
  803. return (x * x) + (y * y);
  804. }
  805. inline void Point2D::neg()
  806. {
  807. x = -x;
  808. y = -y;
  809. }
  810. inline void Point2D::convolve(const Point2D& c)
  811. {
  812. x *= c.x;
  813. y *= c.y;
  814. }
  815. inline void Point2D::convolveInverse(const Point2D& c)
  816. {
  817. x /= c.x;
  818. y /= c.y;
  819. }
  820. inline bool Point2D::operator==(const Point2D& _test) const
  821. {
  822. return (x == _test.x) && (y == _test.y);
  823. }
  824. inline bool Point2D::operator!=(const Point2D& _test) const
  825. {
  826. return operator==(_test) == false;
  827. }
  828. inline Point2D Point2D::operator+(const Point2D& _add) const
  829. {
  830. return Point2D(x + _add.x, y + _add.y);
  831. }
  832. inline Point2D Point2D::operator-(const Point2D& _rSub) const
  833. {
  834. return Point2D(x - _rSub.x, y - _rSub.y);
  835. }
  836. inline Point2D& Point2D::operator+=(const Point2D& _add)
  837. {
  838. x += _add.x;
  839. y += _add.y;
  840. return *this;
  841. }
  842. inline Point2D& Point2D::operator-=(const Point2D& _rSub)
  843. {
  844. x -= _rSub.x;
  845. y -= _rSub.y;
  846. return *this;
  847. }
  848. inline Point2D Point2D::operator*(const F64 _mul) const
  849. {
  850. return Point2D(x * _mul, y * _mul);
  851. }
  852. inline Point2D Point2D::operator/(const F64 _div) const
  853. {
  854. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  855. F64 inv = 1.0f / _div;
  856. return Point2D(x * inv, y * inv);
  857. }
  858. inline Point2D& Point2D::operator*=(const F64 _mul)
  859. {
  860. x *= _mul;
  861. y *= _mul;
  862. return *this;
  863. }
  864. inline Point2D& Point2D::operator/=(const F64 _div)
  865. {
  866. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  867. F64 inv = 1.0f / _div;
  868. x *= inv;
  869. y *= inv;
  870. return *this;
  871. }
  872. inline Point2D Point2D::operator-() const
  873. {
  874. return Point2D(-x, -y);
  875. }
  876. inline F64 Point2D::len() const
  877. {
  878. return mSqrtD(x*x + y*y);
  879. }
  880. inline void Point2D::normalize()
  881. {
  882. m_point2D_normalize(*this);
  883. }
  884. inline void Point2D::normalize(F64 val)
  885. {
  886. m_point2D_normalize_f(*this, val);
  887. }
  888. //------------------------------------------------------------------------------
  889. //-------------------------------------- Point3F
  890. //
  891. inline Point3F::Point3F()
  892. #if defined(TORQUE_OS_LINUX)
  893. : x(0.f), y(0.f), z(0.f)
  894. #endif
  895. {
  896. // Uninitialized points are definitely a problem.
  897. // Enable the following code to see how often they crop up.
  898. #ifdef DEBUG_MATH
  899. *(U32 *)&x = 0x7FFFFFFA;
  900. *(U32 *)&y = 0x7FFFFFFB;
  901. *(U32 *)&z = 0x7FFFFFFC;
  902. #endif
  903. }
  904. inline Point3F::Point3F(const Point3F& _copy)
  905. : x(_copy.x), y(_copy.y), z(_copy.z)
  906. {
  907. //
  908. }
  909. inline Point3F::Point3F(const F32 _x, const F32 _y, const F32 _z)
  910. : x(_x), y(_y), z(_z)
  911. {
  912. //
  913. }
  914. inline void Point3F::set(const F32 _x, const F32 _y, const F32 _z)
  915. {
  916. x = _x;
  917. y = _y;
  918. z = _z;
  919. }
  920. inline void Point3F::set(const Point3F& copy)
  921. {
  922. x = copy.x;
  923. y = copy.y;
  924. z = copy.z;
  925. }
  926. inline void Point3F::setMin(const Point3F& _test)
  927. {
  928. x = (_test.x < x) ? _test.x : x;
  929. y = (_test.y < y) ? _test.y : y;
  930. z = (_test.z < z) ? _test.z : z;
  931. }
  932. inline void Point3F::setMax(const Point3F& _test)
  933. {
  934. x = (_test.x > x) ? _test.x : x;
  935. y = (_test.y > y) ? _test.y : y;
  936. z = (_test.z > z) ? _test.z : z;
  937. }
  938. inline void Point3F::interpolate(const Point3F& _from, const Point3F& _to, const F32 _factor)
  939. {
  940. AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor");
  941. m_point3F_interpolate( _from, _to, _factor, *this);
  942. }
  943. inline void Point3F::zero()
  944. {
  945. x = y = z = 0.0f;
  946. }
  947. inline bool Point3F::isZero() const
  948. {
  949. return ((x*x) <= POINT_EPSILON) && ((y*y) <= POINT_EPSILON) && ((z*z) <= POINT_EPSILON );
  950. }
  951. inline bool Point3F::equal( Point3F &compare )
  952. {
  953. return( ( mFabs( x - compare.x ) < POINT_EPSILON ) &&
  954. ( mFabs( y - compare.y ) < POINT_EPSILON ) &&
  955. ( mFabs( z - compare.z ) < POINT_EPSILON ) );
  956. }
  957. inline void Point3F::neg()
  958. {
  959. x = -x;
  960. y = -y;
  961. z = -z;
  962. }
  963. inline void Point3F::convolve(const Point3F& c)
  964. {
  965. x *= c.x;
  966. y *= c.y;
  967. z *= c.z;
  968. }
  969. inline void Point3F::convolveInverse(const Point3F& c)
  970. {
  971. x /= c.x;
  972. y /= c.y;
  973. z /= c.z;
  974. }
  975. inline F32 Point3F::lenSquared() const
  976. {
  977. return (x * x) + (y * y) + (z * z);
  978. }
  979. inline F32 Point3F::len() const
  980. {
  981. return mSqrt(x*x + y*y + z*z);
  982. }
  983. inline void Point3F::normalize()
  984. {
  985. m_point3F_normalize(*this);
  986. }
  987. inline F32 Point3F::magnitudeSafe()
  988. {
  989. if( isZero() )
  990. {
  991. return 0.0f;
  992. }
  993. else
  994. {
  995. return len();
  996. }
  997. }
  998. inline void Point3F::normalizeSafe()
  999. {
  1000. F32 vmag = magnitudeSafe();
  1001. if( vmag > POINT_EPSILON )
  1002. {
  1003. *this *= F32(1.0 / vmag);
  1004. }
  1005. }
  1006. inline void Point3F::normalize(F32 val)
  1007. {
  1008. m_point3F_normalize_f(*this, val);
  1009. }
  1010. inline bool Point3F::operator==(const Point3F& _test) const
  1011. {
  1012. return (x == _test.x) && (y == _test.y) && (z == _test.z);
  1013. }
  1014. inline bool Point3F::operator!=(const Point3F& _test) const
  1015. {
  1016. return operator==(_test) == false;
  1017. }
  1018. inline Point3F Point3F::operator+(const Point3F& _add) const
  1019. {
  1020. return Point3F(x + _add.x, y + _add.y, z + _add.z);
  1021. }
  1022. inline Point3F Point3F::operator-(const Point3F& _rSub) const
  1023. {
  1024. return Point3F(x - _rSub.x, y - _rSub.y, z - _rSub.z);
  1025. }
  1026. inline Point3F& Point3F::operator+=(const Point3F& _add)
  1027. {
  1028. x += _add.x;
  1029. y += _add.y;
  1030. z += _add.z;
  1031. return *this;
  1032. }
  1033. inline Point3F& Point3F::operator-=(const Point3F& _rSub)
  1034. {
  1035. x -= _rSub.x;
  1036. y -= _rSub.y;
  1037. z -= _rSub.z;
  1038. return *this;
  1039. }
  1040. inline Point3F Point3F::operator*(const F32 _mul) const
  1041. {
  1042. return Point3F(x * _mul, y * _mul, z * _mul);
  1043. }
  1044. inline Point3F Point3F::operator*(const Point3F &_vec) const
  1045. {
  1046. return Point3F(x * _vec.x, y * _vec.y, z * _vec.z);
  1047. }
  1048. inline Point3F Point3F::operator/(const F32 _div) const
  1049. {
  1050. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  1051. F32 inv = 1.0f / _div;
  1052. return Point3F(x * inv, y * inv, z * inv);
  1053. }
  1054. inline Point3F& Point3F::operator*=(const F32 _mul)
  1055. {
  1056. x *= _mul;
  1057. y *= _mul;
  1058. z *= _mul;
  1059. return *this;
  1060. }
  1061. inline Point3F& Point3F::operator*=(const Point3F &_vec)
  1062. {
  1063. x *= _vec.x;
  1064. y *= _vec.y;
  1065. z *= _vec.z;
  1066. return *this;
  1067. }
  1068. inline Point3F& Point3F::operator/=(const F32 _div)
  1069. {
  1070. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  1071. F32 inv = 1.0f / _div;
  1072. x *= inv;
  1073. y *= inv;
  1074. z *= inv;
  1075. return *this;
  1076. }
  1077. inline Point3F Point3F::operator-() const
  1078. {
  1079. return Point3F(-x, -y, -z);
  1080. }
  1081. //------------------------------------------------------------------------------
  1082. //-------------------------------------- Point3D
  1083. //
  1084. inline Point3D::Point3D()
  1085. {
  1086. //
  1087. }
  1088. inline Point3D::Point3D(const Point3D& _copy)
  1089. : x(_copy.x), y(_copy.y), z(_copy.z)
  1090. {
  1091. //
  1092. }
  1093. inline Point3D::Point3D(const F64 _x, const F64 _y, const F64 _z)
  1094. : x(_x), y(_y), z(_z)
  1095. {
  1096. //
  1097. }
  1098. inline void Point3D::set(const F64 _x, const F64 _y, const F64 _z)
  1099. {
  1100. x = _x;
  1101. y = _y;
  1102. z = _z;
  1103. }
  1104. inline void Point3D::setMin(const Point3D& _test)
  1105. {
  1106. x = (_test.x < x) ? _test.x : x;
  1107. y = (_test.y < y) ? _test.y : y;
  1108. z = (_test.z < z) ? _test.z : z;
  1109. }
  1110. inline void Point3D::setMax(const Point3D& _test)
  1111. {
  1112. x = (_test.x > x) ? _test.x : x;
  1113. y = (_test.y > y) ? _test.y : y;
  1114. z = (_test.z > z) ? _test.z : z;
  1115. }
  1116. inline void Point3D::interpolate(const Point3D& _from, const Point3D& _to, const F64 _factor)
  1117. {
  1118. AssertFatal(_factor >= 0.0f && _factor <= 1.0f, "Out of bound interpolation factor");
  1119. m_point3D_interpolate( _from, _to, _factor, *this);
  1120. }
  1121. inline bool Point3D::isZero() const
  1122. {
  1123. return (x == 0.0f) && (y == 0.0f) && (z == 0.0f);
  1124. }
  1125. inline void Point3D::neg()
  1126. {
  1127. x = -x;
  1128. y = -y;
  1129. z = -z;
  1130. }
  1131. inline void Point3D::convolve(const Point3D& c)
  1132. {
  1133. x *= c.x;
  1134. y *= c.y;
  1135. z *= c.z;
  1136. }
  1137. inline void Point3D::convolveInverse(const Point3D& c)
  1138. {
  1139. x /= c.x;
  1140. y /= c.y;
  1141. z /= c.z;
  1142. }
  1143. inline F64 Point3D::lenSquared() const
  1144. {
  1145. return (x * x) + (y * y) + (z * z);
  1146. }
  1147. inline F64 Point3D::len() const
  1148. {
  1149. return mSqrtD(x*x + y*y + z*z);
  1150. }
  1151. inline void Point3D::normalize()
  1152. {
  1153. m_point3D_normalize(*this);
  1154. }
  1155. inline void Point3D::normalize(F64 val)
  1156. {
  1157. m_point3D_normalize_f(*this, val);
  1158. }
  1159. inline bool Point3D::operator==(const Point3D& _test) const
  1160. {
  1161. return (x == _test.x) && (y == _test.y) && (z == _test.z);
  1162. }
  1163. inline bool Point3D::operator!=(const Point3D& _test) const
  1164. {
  1165. return operator==(_test) == false;
  1166. }
  1167. inline Point3D Point3D::operator+(const Point3D& _add) const
  1168. {
  1169. return Point3D(x + _add.x, y + _add.y, z + _add.z);
  1170. }
  1171. inline Point3D Point3D::operator-(const Point3D& _rSub) const
  1172. {
  1173. return Point3D(x - _rSub.x, y - _rSub.y, z - _rSub.z);
  1174. }
  1175. inline Point3D& Point3D::operator+=(const Point3D& _add)
  1176. {
  1177. x += _add.x;
  1178. y += _add.y;
  1179. z += _add.z;
  1180. return *this;
  1181. }
  1182. inline Point3D& Point3D::operator-=(const Point3D& _rSub)
  1183. {
  1184. x -= _rSub.x;
  1185. y -= _rSub.y;
  1186. z -= _rSub.z;
  1187. return *this;
  1188. }
  1189. inline Point3D Point3D::operator*(const F64 _mul) const
  1190. {
  1191. return Point3D(x * _mul, y * _mul, z * _mul);
  1192. }
  1193. inline Point3D Point3D::operator/(const F64 _div) const
  1194. {
  1195. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  1196. F64 inv = 1.0f / _div;
  1197. return Point3D(x * inv, y * inv, z * inv);
  1198. }
  1199. inline Point3D& Point3D::operator*=(const F64 _mul)
  1200. {
  1201. x *= _mul;
  1202. y *= _mul;
  1203. z *= _mul;
  1204. return *this;
  1205. }
  1206. inline Point3D& Point3D::operator/=(const F64 _div)
  1207. {
  1208. AssertFatal(_div != 0.0f, "Error, div by zero attempted");
  1209. F64 inv = 1.0f / _div;
  1210. x *= inv;
  1211. y *= inv;
  1212. z *= inv;
  1213. return *this;
  1214. }
  1215. inline Point3D Point3D::operator-() const
  1216. {
  1217. return Point3D(-x, -y, -z);
  1218. }
  1219. //------------------------------------------------------------------------------
  1220. //-------------------------------------- Point4F
  1221. //
  1222. inline Point4F::Point4F()
  1223. {
  1224. //
  1225. }
  1226. inline Point4F::Point4F(const Point4F& _copy)
  1227. : x(_copy.x), y(_copy.y), z(_copy.z), w(_copy.w)
  1228. {
  1229. //
  1230. }
  1231. inline Point4F::Point4F(const F32 _x, const F32 _y, const F32 _z, const F32 _w)
  1232. : x(_x), y(_y), z(_z), w(_w)
  1233. {
  1234. //
  1235. }
  1236. inline void Point4F::set(const F32 _x, const F32 _y, const F32 _z, const F32 _w)
  1237. {
  1238. x = _x;
  1239. y = _y;
  1240. z = _z;
  1241. w = _w;
  1242. }
  1243. inline void Point4F::interpolate(const Point4F& _from, const Point4F& _to, const F32 _factor)
  1244. {
  1245. x = (_from.x * (1.0f - _factor)) + (_to.x * _factor);
  1246. y = (_from.y * (1.0f - _factor)) + (_to.y * _factor);
  1247. z = (_from.z * (1.0f - _factor)) + (_to.z * _factor);
  1248. w = (_from.w * (1.0f - _factor)) + (_to.w * _factor);
  1249. }
  1250. //--------------------------------------------------------------------------
  1251. //-------------------------------------- NON-MEMBER Operators
  1252. //
  1253. inline Point2I operator*(const S32 mul, const Point2I& multiplicand)
  1254. {
  1255. return multiplicand * mul;
  1256. }
  1257. inline Point3I operator*(const S32 mul, const Point3I& multiplicand)
  1258. {
  1259. return multiplicand * mul;
  1260. }
  1261. inline Point2F operator*(const F32 mul, const Point2F& multiplicand)
  1262. {
  1263. return multiplicand * mul;
  1264. }
  1265. inline Point3F operator*(const F32 mul, const Point3F& multiplicand)
  1266. {
  1267. return multiplicand * mul;
  1268. }
  1269. inline Point2D operator*(const F64 mul, const Point2D& multiplicand)
  1270. {
  1271. return multiplicand * mul;
  1272. }
  1273. inline Point3D operator*(const F64 mul, const Point3D& multiplicand)
  1274. {
  1275. return multiplicand * mul;
  1276. }
  1277. #endif // _POINT_H_