Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

844 lines
17 KiB

  1. #ifndef _VecMath_h
  2. #define _VecMath_h
  3. // File: VecMath.h
  4. //
  5. // Classes to support 2D and 3D linear vector space and their duals
  6. // D. P. Mitchell 95/06/02.
  7. //
  8. // History:
  9. // -@- 07/06/95 (mikemarr) - added Print and Read functions
  10. // -@- 08/01/95 (mikemarr) - added fuzzy compare for floats
  11. // -@- 04/15/96 (mikemarr) - changed stdio stuff to don's stream stuff
  12. // -@- 04/18/96 (mikemarr) - added vector.inl to this file
  13. // -@- 06/21/96 (mikemarr) - added +=, etc. operators
  14. // -@- 06/21/96 (mikemarr) - added Rotate
  15. // -@- 10/29/97 (mikemarr) - removed I/O
  16. // - changed +=,-=,*=,/= operators to return reference
  17. // - added operator const float *
  18. // - added Unitize, Perp, NormSquared, SetNorm, Negate
  19. // - comments/cleanup
  20. // - changed fuzzy equal to be IsEqual, operator == to be exact
  21. // - bug fix on Transpose
  22. // - changed multiple divides to be 1 divide + multiplies
  23. // - assert on divide by zero
  24. // -@- 11/04/97 (mikemarr) - added intialization with SIZE
  25. // Function: FloatEquals
  26. // Peform a "fuzzy" compare of two floating point numbers. This relies
  27. // on the IEEE bit representation of floating point numbers.
  28. int FloatEquals(float x1, float x2);
  29. class CoVector2;
  30. class CoVector3;
  31. class Vector3;
  32. // Class: Vector2
  33. // Hungarian: v
  34. // Description:
  35. // This class represents a floating point 2D column vector useful for computational
  36. // geometry calculations.
  37. class Vector2 {
  38. public:
  39. Vector2() {}
  40. Vector2(float a, float b) : x(a), y(b) {}
  41. Vector2(const SIZE &siz) : x(float(siz.cx)), y(float(siz.cy)) {}
  42. friend Vector2 operator +(const Vector2 &u, const Vector2 &v);
  43. friend Vector2 operator -(const Vector2 &u, const Vector2 &v);
  44. friend Vector2 operator -(const Vector2 &u);
  45. friend Vector2 operator *(const Vector2 &u, float a);
  46. friend Vector2 operator *(float a, const Vector2 &u);
  47. friend Vector2 operator /(const Vector2 &u, float a);
  48. friend int operator ==(const Vector2 &u, const Vector2 &v);
  49. friend int operator !=(const Vector2 &u, const Vector2 &v);
  50. friend Vector2 & operator +=(Vector2 &u, const Vector2 &v);
  51. friend Vector2 & operator -=(Vector2 &u, const Vector2 &v);
  52. friend Vector2 & operator *=(Vector2 &u, float a);
  53. friend Vector2 & operator /=(Vector2 &u, float a);
  54. #ifndef DISABLE_CROSSDOT
  55. friend float Cross(const Vector2 &u, const Vector2 &v);
  56. friend float Dot(const Vector2 &u, const Vector2 &v);
  57. #endif
  58. friend int IsEqual(const Vector2 &u, const Vector2 &v);
  59. operator const float *() const { return &x; }
  60. CoVector2 Transpose() const;
  61. float Norm() const;
  62. float NormSquared() const;
  63. void SetNorm(float a);
  64. Vector2 Unit() const;
  65. void Unitize();
  66. Vector2 Perp() const; // points to left
  67. void Negate();
  68. public:
  69. float x, y;
  70. };
  71. // Class: CoVector2
  72. // Hungarian: cv
  73. // Description:
  74. // This class represents a floating point 2D row vector useful for computational
  75. // geometry calculations.
  76. class CoVector2 {
  77. public:
  78. CoVector2() {}
  79. CoVector2(float a, float b) : x(a), y(b) {}
  80. CoVector2(const SIZE &siz) : x(float(siz.cx)), y(float(siz.cy)) {}
  81. friend CoVector2 operator +(const CoVector2 &u, const CoVector2 &v);
  82. friend CoVector2 operator -(const CoVector2 &u, const CoVector2 &v);
  83. friend CoVector2 operator -(const CoVector2 &u);
  84. friend CoVector2 operator *(const CoVector2 &u, float a);
  85. friend CoVector2 operator *(float a, const CoVector2 &u);
  86. friend CoVector2 operator /(const CoVector2 &u, float a);
  87. friend int operator ==(const CoVector2 &u, const CoVector2 &v);
  88. friend int operator !=(const CoVector2 &u, const CoVector2 &v);
  89. friend CoVector2 & operator +=(CoVector2 &u, const CoVector2 &v);
  90. friend CoVector2 & operator -=(CoVector2 &u, const CoVector2 &v);
  91. friend CoVector2 & operator *=(CoVector2 &u, float a);
  92. friend CoVector2 & operator /=(CoVector2 &u, float a);
  93. #ifndef DISABLE_CROSSDOT
  94. friend float Cross(const CoVector2 &u, const CoVector2 &v);
  95. friend float Dot(const CoVector2 &u, const CoVector2 &v);
  96. #endif
  97. friend int IsEqual(const CoVector2 &u, const CoVector2 &v);
  98. operator const float *() const { return &x; }
  99. Vector2 Transpose() const;
  100. float Norm() const;
  101. float NormSquared() const;
  102. void SetNorm(float a);
  103. CoVector2 Unit() const;
  104. void Unitize();
  105. friend float operator *(const CoVector2 &c, const Vector2 &v);
  106. CoVector2 Perp() const; // points to left
  107. void Negate();
  108. public:
  109. float x, y;
  110. };
  111. // Class: Vector3
  112. // Hungarian: v
  113. // Description:
  114. // This class represents a floating point 3D column vector useful for computational
  115. // geometry calculations.
  116. class Vector3 {
  117. public:
  118. Vector3() {}
  119. Vector3(float a, float b, float c) : x(a), y(b), z(c) {}
  120. friend Vector3 operator +(const Vector3 &u, const Vector3 &v);
  121. friend Vector3 operator -(const Vector3 &u, const Vector3 &v);
  122. friend Vector3 operator -(const Vector3 &u);
  123. friend Vector3 operator *(const Vector3 &u, float a);
  124. friend Vector3 operator *(float a, const Vector3 &u);
  125. friend Vector3 operator /(const Vector3 &u, float a);
  126. friend int operator ==(const Vector3 &u, const Vector3 &v);
  127. friend int operator !=(const Vector3 &u, const Vector3 &v);
  128. friend Vector3 & operator +=(Vector3 &u, const Vector3 &v);
  129. friend Vector3 & operator -=(Vector3 &u, const Vector3 &v);
  130. friend Vector3 & operator *=(Vector3 &u, float a);
  131. friend Vector3 & operator /=(Vector3 &u, float a);
  132. #ifndef DISABLE_CROSSDOT
  133. friend Vector3 Cross(const Vector3 &u, const Vector3 &v);
  134. friend float Dot(const Vector3 &u, const Vector3 &v);
  135. #endif
  136. friend int IsEqual(const Vector3 &u, const Vector3 &v);
  137. operator const float *() const { return &x; }
  138. CoVector3 Transpose() const;
  139. float Norm() const;
  140. float NormSquared() const;
  141. void SetNorm(float a);
  142. Vector3 Unit() const;
  143. void Unitize();
  144. Vector2 Project(DWORD iAxis) const;
  145. void Rotate(const Vector3 &vAxis, float fTheta);
  146. void Negate();
  147. public:
  148. float x, y, z;
  149. };
  150. // Class: CoVector3
  151. // Hungarian: cv
  152. // Description:
  153. // This class represents a floating point 3D row vector useful for computational
  154. // geometry calculations.
  155. class CoVector3 {
  156. public:
  157. CoVector3() {}
  158. CoVector3(float a, float b, float c) : x(a), y(b), z(c) {}
  159. friend CoVector3 operator +(const CoVector3 &u, const CoVector3 &v);
  160. friend CoVector3 operator -(const CoVector3 &u, const CoVector3 &v);
  161. friend CoVector3 operator -(const CoVector3 &u);
  162. friend CoVector3 operator *(const CoVector3 &u, float a);
  163. friend CoVector3 operator *(float, const CoVector3 &u);
  164. friend CoVector3 operator /(const CoVector3 &u, float a);
  165. friend int operator ==(const CoVector3 &u, const CoVector3 &v);
  166. friend int operator !=(const CoVector3 &u, const CoVector3 &v);
  167. friend CoVector3 & operator +=(CoVector3 &u, const CoVector3 &v);
  168. friend CoVector3 & operator -=(CoVector3 &u, const CoVector3 &v);
  169. friend CoVector3 & operator *=(CoVector3 &u, float a);
  170. friend CoVector3 & operator /=(CoVector3 &u, float a);
  171. #ifndef DISABLE_CROSSDOT
  172. friend CoVector3 Cross(const CoVector3 &u, const CoVector3 &v);
  173. friend float Dot(const CoVector3 &u, const CoVector3 &v);
  174. #endif
  175. friend int IsEqual(const CoVector3 &u, const CoVector3 &v);
  176. operator const float *() const { return &x; }
  177. Vector3 Transpose() const;
  178. float Norm() const;
  179. float NormSquared() const;
  180. void SetNorm(float a);
  181. CoVector3 Unit() const;
  182. void Unitize();
  183. friend float operator *(const CoVector3 &c, const Vector3 &u); // linear form
  184. void Negate();
  185. public:
  186. float x, y, z;
  187. };
  188. ////////////
  189. // Vector2
  190. ////////////
  191. inline Vector2
  192. operator +(const Vector2 &u, const Vector2 &v)
  193. {
  194. return Vector2(u.x+v.x, u.y+v.y);
  195. }
  196. inline Vector2
  197. operator -(const Vector2 &u, const Vector2 &v)
  198. {
  199. return Vector2(u.x-v.x, u.y-v.y);
  200. }
  201. inline Vector2
  202. operator -(const Vector2 &v)
  203. {
  204. return Vector2(-v.x, -v.y);
  205. }
  206. inline Vector2
  207. operator *(float a, const Vector2 &v)
  208. {
  209. return Vector2(a*v.x, a*v.y);
  210. }
  211. inline Vector2
  212. operator *(const Vector2 &v, float a)
  213. {
  214. return Vector2(a*v.x, a*v.y);
  215. }
  216. inline Vector2
  217. operator /(const Vector2 &v, float a)
  218. {
  219. MMASSERT(a != 0.f);
  220. float fTmp = 1.f/a;
  221. return Vector2(v.x * fTmp, v.y * fTmp);
  222. }
  223. inline int
  224. operator ==(const Vector2 &u, const Vector2 &v)
  225. {
  226. return ((u.x == v.x) && (u.y == v.y));
  227. }
  228. inline int
  229. IsEqual(const Vector2 &u, const Vector2 &v)
  230. {
  231. return (FloatEquals(u.x, v.x) && FloatEquals(u.y, v.y));
  232. }
  233. inline int
  234. operator !=(const Vector2 &u, const Vector2 &v)
  235. {
  236. return !(u == v);
  237. }
  238. inline Vector2 &
  239. operator +=(Vector2 &u, const Vector2 &v)
  240. {
  241. u.x += v.x;
  242. u.y += v.y;
  243. return u;
  244. }
  245. inline Vector2 &
  246. operator -=(Vector2 &u, const Vector2 &v)
  247. {
  248. u.x -= v.x;
  249. u.y -= v.y;
  250. return u;
  251. }
  252. inline Vector2 &
  253. operator *=(Vector2 &u, float a)
  254. {
  255. u.x *= a;
  256. u.y *= a;
  257. return u;
  258. }
  259. inline Vector2 &
  260. operator /=(Vector2 &u, float a)
  261. {
  262. MMASSERT(a != 0.f);
  263. float fTmp = 1.f/a;
  264. u.x *= fTmp;
  265. u.y *= fTmp;
  266. return u;
  267. }
  268. #ifndef DISABLE_CROSSDOT
  269. inline float
  270. Cross(const Vector2 &u, const Vector2 &v)
  271. {
  272. return u.x*v.y - u.y*v.x;
  273. }
  274. inline float
  275. Dot(const Vector2 &u, const Vector2 &v)
  276. {
  277. return u.x*v.x + u.y*v.y;
  278. }
  279. #endif
  280. inline CoVector2
  281. Vector2::Transpose() const
  282. {
  283. return CoVector2(x, y);
  284. }
  285. inline Vector2
  286. Vector2::Unit() const
  287. {
  288. return *this/this->Norm();
  289. }
  290. inline void
  291. Vector2::Unitize()
  292. {
  293. *this /= this->Norm();
  294. }
  295. inline Vector2
  296. Vector2::Perp() const
  297. {
  298. return Vector2(-y, x);
  299. }
  300. inline float
  301. Vector2::NormSquared() const
  302. {
  303. return x*x + y*y;
  304. }
  305. inline void
  306. Vector2::SetNorm(float a)
  307. {
  308. *this *= (a / Norm());
  309. }
  310. inline void
  311. Vector2::Negate()
  312. {
  313. x = -x; y = -y;
  314. }
  315. //////////////
  316. // CoVector2
  317. //////////////
  318. inline CoVector2
  319. operator +(const CoVector2 &u, const CoVector2 &v)
  320. {
  321. return CoVector2(u.x+v.x, u.y+v.y);
  322. }
  323. inline CoVector2
  324. operator -(const CoVector2 &u, const CoVector2 &v)
  325. {
  326. return CoVector2(u.x-v.x, u.y-v.y);
  327. }
  328. inline CoVector2
  329. operator -(const CoVector2 &v)
  330. {
  331. return CoVector2(-v.x, -v.y);
  332. }
  333. inline CoVector2
  334. operator *(float a, const CoVector2 &v)
  335. {
  336. return CoVector2(a*v.x, a*v.y);
  337. }
  338. inline CoVector2
  339. operator *(const CoVector2 &v, float a)
  340. {
  341. return CoVector2(a*v.x, a*v.y);
  342. }
  343. inline CoVector2
  344. operator /(const CoVector2 &v, float a)
  345. {
  346. MMASSERT(a != 0.f);
  347. float fTmp = 1.f/a;
  348. return CoVector2(v.x * fTmp, v.y * fTmp);
  349. }
  350. inline int
  351. operator ==(const CoVector2 &u, const CoVector2 &v)
  352. {
  353. return ((u.x == v.x) && (u.y == v.y));
  354. }
  355. inline int
  356. IsEqual(const CoVector2 &u, const CoVector2 &v)
  357. {
  358. return (FloatEquals(u.x, v.x) && FloatEquals(u.y, v.y));
  359. }
  360. inline int
  361. operator !=(const CoVector2 &u, const CoVector2 &v)
  362. {
  363. return !(u == v);
  364. }
  365. inline CoVector2 &
  366. operator +=(CoVector2 &u, const CoVector2 &v)
  367. {
  368. u.x += v.x;
  369. u.y += v.y;
  370. return u;
  371. }
  372. inline CoVector2 &
  373. operator -=(CoVector2 &u, const CoVector2 &v)
  374. {
  375. u.x -= v.x;
  376. u.y -= v.y;
  377. return u;
  378. }
  379. inline CoVector2 &
  380. operator *=(CoVector2 &u, float a)
  381. {
  382. u.x *= a;
  383. u.y *= a;
  384. return u;
  385. }
  386. inline CoVector2 &
  387. operator /=(CoVector2 &u, float a)
  388. {
  389. MMASSERT(a != 0.f);
  390. float fTmp = 1.f/a;
  391. u.x *= fTmp;
  392. u.y *= fTmp;
  393. return u;
  394. }
  395. #ifndef DISABLE_CROSSDOT
  396. inline float
  397. Cross(const CoVector2 &u, const CoVector2 &v)
  398. {
  399. return u.x*v.y - u.y*v.x;
  400. }
  401. inline float
  402. Dot(const CoVector2 &u, const CoVector2 &v)
  403. {
  404. return u.x*v.x + u.y*v.y;
  405. }
  406. #endif
  407. inline Vector2
  408. CoVector2::Transpose() const
  409. {
  410. return Vector2(x, y);
  411. }
  412. inline CoVector2
  413. CoVector2::Unit() const
  414. {
  415. return *this/this->Norm();
  416. }
  417. inline void
  418. CoVector2::Unitize()
  419. {
  420. *this /= this->Norm();
  421. }
  422. inline float
  423. operator *(const CoVector2 &c, const Vector2 &v)
  424. {
  425. return c.x*v.x + c.y*v.y;
  426. }
  427. inline CoVector2
  428. CoVector2::Perp() const
  429. {
  430. return CoVector2(-y, x);
  431. }
  432. inline float
  433. CoVector2::NormSquared() const
  434. {
  435. return x*x + y*y;
  436. }
  437. inline void
  438. CoVector2::SetNorm(float a)
  439. {
  440. *this *= (a / Norm());
  441. }
  442. inline void
  443. CoVector2::Negate()
  444. {
  445. x = -x; y = -y;
  446. }
  447. ////////////
  448. // Vector3
  449. ////////////
  450. inline Vector3
  451. operator +(const Vector3 &u, const Vector3 &v)
  452. {
  453. return Vector3(u.x+v.x, u.y+v.y, u.z+v.z);
  454. }
  455. inline Vector3
  456. operator -(const Vector3 &u, const Vector3 &v)
  457. {
  458. return Vector3(u.x-v.x, u.y-v.y, u.z-v.z);
  459. }
  460. inline Vector3
  461. operator -(const Vector3 &v)
  462. {
  463. return Vector3(-v.x, -v.y, -v.z);
  464. }
  465. inline Vector3
  466. operator *(float a, const Vector3 &v)
  467. {
  468. return Vector3(a*v.x, a*v.y, a*v.z);
  469. }
  470. inline Vector3
  471. operator *(const Vector3 &v, float a)
  472. {
  473. return Vector3(a*v.x, a*v.y, a*v.z);
  474. }
  475. inline Vector3
  476. operator /(const Vector3 &v, float a)
  477. {
  478. float fTmp = 1.f / a;
  479. return Vector3(v.x * fTmp, v.y * fTmp, v.z * fTmp);
  480. }
  481. inline int
  482. operator ==(const Vector3 &u, const Vector3 &v)
  483. {
  484. return ((u.x == v.x) && (u.y == v.y) && (u.z == v.z));
  485. }
  486. inline int
  487. IsEqual(const Vector3 &u, const Vector3 &v)
  488. {
  489. return (FloatEquals(u.x, v.x) && FloatEquals(u.y, v.y) && FloatEquals(u.z, v.z));
  490. }
  491. inline int
  492. operator !=(const Vector3 &u, const Vector3 &v)
  493. {
  494. return !(u == v);
  495. }
  496. inline Vector3 &
  497. operator +=(Vector3 &u, const Vector3 &v)
  498. {
  499. u.x += v.x;
  500. u.y += v.y;
  501. u.z += v.z;
  502. return u;
  503. }
  504. inline Vector3 &
  505. operator -=(Vector3 &u, const Vector3 &v)
  506. {
  507. u.x -= v.x;
  508. u.y -= v.y;
  509. u.z -= v.z;
  510. return u;
  511. }
  512. inline Vector3 &
  513. operator *=(Vector3 &u, float a)
  514. {
  515. u.x *= a;
  516. u.y *= a;
  517. u.z *= a;
  518. return u;
  519. }
  520. inline Vector3 &
  521. operator /=(Vector3 &u, float a)
  522. {
  523. MMASSERT(a != 0.f);
  524. float fTmp = 1.f/a;
  525. u.x *= fTmp;
  526. u.y *= fTmp;
  527. u.z *= fTmp;
  528. return u;
  529. }
  530. #ifndef DISABLE_CROSSDOT
  531. inline Vector3
  532. Cross(const Vector3 &u, const Vector3 &v)
  533. {
  534. return Vector3(u.y*v.z-u.z*v.y, u.z*v.x-u.x*v.z, u.x*v.y-u.y*v.x);
  535. }
  536. inline float
  537. Dot(const Vector3 &u, const Vector3 &v)
  538. {
  539. return u.x*v.x + u.y*v.y + u.z*v.z;
  540. }
  541. #endif
  542. inline float
  543. operator *(const CoVector3 &c, const Vector3 &v)
  544. {
  545. return c.x*v.x + c.y*v.y + c.z*v.z;
  546. }
  547. inline CoVector3
  548. Vector3::Transpose() const
  549. {
  550. return CoVector3(x, y, z);
  551. }
  552. inline Vector3
  553. Vector3::Unit() const
  554. {
  555. return *this/this->Norm();
  556. }
  557. inline void
  558. Vector3::Unitize()
  559. {
  560. *this /= this->Norm();
  561. }
  562. inline float
  563. Vector3::NormSquared() const
  564. {
  565. return x*x + y*y + z*z;
  566. }
  567. inline void
  568. Vector3::SetNorm(float a)
  569. {
  570. *this *= (a / Norm());
  571. }
  572. inline void
  573. Vector3::Negate()
  574. {
  575. x = -x; y = -y; z = -z;
  576. }
  577. inline Vector2
  578. Vector3::Project(DWORD iAxis) const
  579. {
  580. switch (iAxis) {
  581. case 0: return Vector2(y, z);
  582. case 1: return Vector2(x, z);
  583. case 2: return Vector2(x, y);
  584. }
  585. return Vector2(0.f, 0.f);
  586. }
  587. //////////////
  588. // CoVector3
  589. //////////////
  590. inline CoVector3
  591. operator +(const CoVector3 &u, const CoVector3 &v)
  592. {
  593. return CoVector3(u.x+v.x, u.y+v.y, u.z+v.z);
  594. }
  595. inline CoVector3
  596. operator -(const CoVector3 &u, const CoVector3 &v)
  597. {
  598. return CoVector3(u.x-v.x, u.y-v.y, u.z-v.z);
  599. }
  600. inline CoVector3
  601. operator -(const CoVector3 &v)
  602. {
  603. return CoVector3(-v.x, -v.y, -v.z);
  604. }
  605. inline CoVector3
  606. operator *(float a, const CoVector3 &v)
  607. {
  608. return CoVector3(a*v.x, a*v.y, a*v.z);
  609. }
  610. inline CoVector3
  611. operator *(const CoVector3 &v, float a)
  612. {
  613. return CoVector3(a*v.x, a*v.y, a*v.z);
  614. }
  615. inline CoVector3
  616. operator /(const CoVector3 &v, float a)
  617. {
  618. MMASSERT(a != 0.f);
  619. float fTmp = 1.f/a;
  620. return CoVector3(v.x * fTmp, v.y * fTmp, v.z * fTmp);
  621. }
  622. inline int
  623. operator ==(const CoVector3 &u, const CoVector3 &v)
  624. {
  625. return ((u.x == v.x) && (u.y == v.y) && (u.z == v.z));
  626. }
  627. inline int
  628. IsEqual(const CoVector3 &u, const CoVector3 &v)
  629. {
  630. return (FloatEquals(u.x, v.x) && FloatEquals(u.y, v.y) && FloatEquals(u.z, v.z));
  631. }
  632. inline int
  633. operator !=(const CoVector3 &u, const CoVector3 &v)
  634. {
  635. return !(u == v);
  636. }
  637. inline CoVector3 &
  638. operator +=(CoVector3 &u, const CoVector3 &v)
  639. {
  640. u.x += v.x;
  641. u.y += v.y;
  642. u.z += v.z;
  643. return u;
  644. }
  645. inline CoVector3 &
  646. operator -=(CoVector3 &u, const CoVector3 &v)
  647. {
  648. u.x -= v.x;
  649. u.y -= v.y;
  650. u.z -= v.z;
  651. return u;
  652. }
  653. inline CoVector3 &
  654. operator *=(CoVector3 &u, float a)
  655. {
  656. u.x *= a;
  657. u.y *= a;
  658. u.z *= a;
  659. return u;
  660. }
  661. inline CoVector3 &
  662. operator /=(CoVector3 &u, float a)
  663. {
  664. MMASSERT(a != 0.f);
  665. float fTmp = 1.f/a;
  666. u.x *= fTmp;
  667. u.y *= fTmp;
  668. u.z *= fTmp;
  669. return u;
  670. }
  671. #ifndef DISABLE_CROSSDOT
  672. inline CoVector3
  673. Cross(const CoVector3 &u, const CoVector3 &v)
  674. {
  675. return CoVector3(u.y*v.z-u.z*v.y, u.z*v.x-u.x*v.z, u.x*v.y-u.y*v.x);
  676. }
  677. inline float
  678. Dot(const CoVector3 &u, const CoVector3 &v)
  679. {
  680. return u.x*v.x + u.y*v.y + u.z*v.z;
  681. }
  682. #endif
  683. inline Vector3
  684. CoVector3::Transpose() const
  685. {
  686. return Vector3(x, y, z);
  687. }
  688. inline CoVector3
  689. CoVector3::Unit() const
  690. {
  691. return *this/this->Norm();
  692. }
  693. inline void
  694. CoVector3::Unitize()
  695. {
  696. *this /= this->Norm();
  697. }
  698. inline float
  699. CoVector3::NormSquared() const
  700. {
  701. return x*x + y*y + z*z;
  702. }
  703. inline void
  704. CoVector3::SetNorm(float a)
  705. {
  706. *this *= (a / Norm());
  707. }
  708. inline void
  709. CoVector3::Negate()
  710. {
  711. x = -x; y = -y; z = -z;
  712. }
  713. #endif