/glm/core/type_vec4.inl

https://bitbucket.org/ggerganov/test_opengl · C++ Header · 1378 lines · 1208 code · 113 blank · 57 comment · 14 complexity · bff185042ceb37d20962d3492610244d MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
  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 deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// 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 FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref core
  24. /// @file glm/core/type_tvec4.inl
  25. /// @date 2008-08-23 / 2011-06-15
  26. /// @author Christophe Riccio
  27. ///////////////////////////////////////////////////////////////////////////////////
  28. namespace glm{
  29. namespace detail
  30. {
  31. template <typename T>
  32. GLM_FUNC_QUALIFIER typename tvec4<T>::size_type tvec4<T>::length() const
  33. {
  34. return 4;
  35. }
  36. //////////////////////////////////////
  37. // Accesses
  38. template <typename T>
  39. GLM_FUNC_QUALIFIER typename tvec4<T>::value_type &
  40. tvec4<T>::operator[]
  41. (
  42. size_type i
  43. )
  44. {
  45. assert(i < this->length());
  46. return (&x)[i];
  47. }
  48. template <typename T>
  49. GLM_FUNC_QUALIFIER typename tvec4<T>::value_type const &
  50. tvec4<T>::operator[]
  51. (
  52. size_type i
  53. ) const
  54. {
  55. assert(i < this->length());
  56. return (&x)[i];
  57. }
  58. //////////////////////////////////////
  59. // Implicit basic constructors
  60. template <typename T>
  61. GLM_FUNC_QUALIFIER tvec4<T>::tvec4() :
  62. x(value_type(0)),
  63. y(value_type(0)),
  64. z(value_type(0)),
  65. w(value_type(0))
  66. {}
  67. template <typename T>
  68. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  69. (
  70. ctor
  71. )
  72. {}
  73. template <typename T>
  74. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  75. (
  76. type const & v
  77. ) :
  78. x(v.x),
  79. y(v.y),
  80. z(v.z),
  81. w(v.w)
  82. {}
  83. //////////////////////////////////////
  84. // Explicit basic constructors
  85. template <typename T>
  86. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  87. (
  88. value_type const & s
  89. ) :
  90. x(s),
  91. y(s),
  92. z(s),
  93. w(s)
  94. {}
  95. template <typename T>
  96. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  97. (
  98. value_type const & s1,
  99. value_type const & s2,
  100. value_type const & s3,
  101. value_type const & s4
  102. ) :
  103. x(s1),
  104. y(s2),
  105. z(s3),
  106. w(s4)
  107. {}
  108. //////////////////////////////////////
  109. // Swizzle constructors
  110. template <typename T>
  111. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  112. (
  113. tref4<T> const & r
  114. ) :
  115. x(r.x),
  116. y(r.y),
  117. z(r.z),
  118. w(r.w)
  119. {}
  120. template <typename T>
  121. template <typename A, typename B, typename C>
  122. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  123. (
  124. tref2<A> const & v,
  125. B const & s1,
  126. C const & s2
  127. ) :
  128. x(value_type(v.x)),
  129. y(value_type(v.y)),
  130. z(value_type(s1)),
  131. w(value_type(s2))
  132. {}
  133. template <typename T>
  134. template <typename A, typename B, typename C>
  135. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  136. (
  137. A const & s1,
  138. tref2<B> const & v,
  139. C const & s2
  140. ) :
  141. x(value_type(s1)),
  142. y(value_type(v.x)),
  143. z(value_type(v.y)),
  144. w(value_type(s2))
  145. {}
  146. template <typename T>
  147. template <typename A, typename B, typename C>
  148. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  149. (
  150. A const & s1,
  151. B const & s2,
  152. tref2<C> const & v
  153. ) :
  154. x(value_type(s1)),
  155. y(value_type(s2)),
  156. z(value_type(v.x)),
  157. w(value_type(v.y))
  158. {}
  159. template <typename T>
  160. template <typename A, typename B>
  161. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  162. (
  163. tref3<A> const & v,
  164. B const & s
  165. ) :
  166. x(value_type(v.x)),
  167. y(value_type(v.y)),
  168. z(value_type(v.z)),
  169. w(value_type(s))
  170. {}
  171. template <typename T>
  172. template <typename A, typename B>
  173. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  174. (
  175. A const & s,
  176. tref3<B> const & v
  177. ) :
  178. x(value_type(s)),
  179. y(value_type(v.x)),
  180. z(value_type(v.y)),
  181. w(value_type(v.z))
  182. {}
  183. template <typename T>
  184. template <typename A, typename B>
  185. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  186. (
  187. tref2<A> const & v1,
  188. tref2<B> const & v2
  189. ) :
  190. x(value_type(v1.x)),
  191. y(value_type(v1.y)),
  192. z(value_type(v2.x)),
  193. w(value_type(v2.y))
  194. {}
  195. template <typename T>
  196. template <typename A, typename B>
  197. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  198. (
  199. tvec2<A> const & v1,
  200. tref2<B> const & v2
  201. ) :
  202. x(value_type(v1.x)),
  203. y(value_type(v1.y)),
  204. z(value_type(v2.x)),
  205. w(value_type(v2.y))
  206. {}
  207. template <typename T>
  208. template <typename A, typename B>
  209. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  210. (
  211. tref2<A> const & v1,
  212. tvec2<B> const & v2
  213. ) :
  214. x(value_type(v1.x)),
  215. y(value_type(v1.y)),
  216. z(value_type(v2.x)),
  217. w(value_type(v2.y))
  218. {}
  219. //////////////////////////////////////
  220. // Convertion scalar constructors
  221. template <typename T>
  222. template <typename U>
  223. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  224. (
  225. U const & x
  226. ) :
  227. x(value_type(x)),
  228. y(value_type(x)),
  229. z(value_type(x)),
  230. w(value_type(x))
  231. {}
  232. template <typename T>
  233. template <typename A, typename B, typename C, typename D>
  234. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  235. (
  236. A const & x,
  237. B const & y,
  238. C const & z,
  239. D const & w
  240. ) :
  241. x(value_type(x)),
  242. y(value_type(y)),
  243. z(value_type(z)),
  244. w(value_type(w))
  245. {}
  246. //////////////////////////////////////
  247. // Convertion vector constructors
  248. template <typename T>
  249. template <typename A, typename B, typename C>
  250. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  251. (
  252. tvec2<A> const & v,
  253. B const & s1,
  254. C const & s2
  255. ) :
  256. x(value_type(v.x)),
  257. y(value_type(v.y)),
  258. z(value_type(s1)),
  259. w(value_type(s2))
  260. {}
  261. template <typename T>
  262. template <typename A, typename B, typename C>
  263. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  264. (
  265. A const & s1,
  266. tvec2<B> const & v,
  267. C const & s2
  268. ) :
  269. x(value_type(s1)),
  270. y(value_type(v.x)),
  271. z(value_type(v.y)),
  272. w(value_type(s2))
  273. {}
  274. template <typename T>
  275. template <typename A, typename B, typename C>
  276. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  277. (
  278. A const & s1,
  279. B const & s2,
  280. tvec2<C> const & v
  281. ) :
  282. x(value_type(s1)),
  283. y(value_type(s2)),
  284. z(value_type(v.x)),
  285. w(value_type(v.y))
  286. {}
  287. template <typename T>
  288. template <typename A, typename B>
  289. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  290. (
  291. tvec3<A> const & v,
  292. B const & s
  293. ) :
  294. x(value_type(v.x)),
  295. y(value_type(v.y)),
  296. z(value_type(v.z)),
  297. w(value_type(s))
  298. {}
  299. template <typename T>
  300. template <typename A, typename B>
  301. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  302. (
  303. A const & s,
  304. tvec3<B> const & v
  305. ) :
  306. x(value_type(s)),
  307. y(value_type(v.x)),
  308. z(value_type(v.y)),
  309. w(value_type(v.z))
  310. {}
  311. template <typename T>
  312. template <typename A, typename B>
  313. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  314. (
  315. tvec2<A> const & v1,
  316. tvec2<B> const & v2
  317. ) :
  318. x(value_type(v1.x)),
  319. y(value_type(v1.y)),
  320. z(value_type(v2.x)),
  321. w(value_type(v2.y))
  322. {}
  323. template <typename T>
  324. template <typename U>
  325. GLM_FUNC_QUALIFIER tvec4<T>::tvec4
  326. (
  327. tvec4<U> const & v
  328. ) :
  329. x(value_type(v.x)),
  330. y(value_type(v.y)),
  331. z(value_type(v.z)),
  332. w(value_type(v.w))
  333. {}
  334. //////////////////////////////////////
  335. // Unary arithmetic operators
  336. template <typename T>
  337. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator=
  338. (
  339. tvec4<T> const & v
  340. )
  341. {
  342. this->x = v.x;
  343. this->y = v.y;
  344. this->z = v.z;
  345. this->w = v.w;
  346. return *this;
  347. }
  348. template <typename T>
  349. template <typename U>
  350. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator=
  351. (
  352. tvec4<U> const & v
  353. )
  354. {
  355. this->x = T(v.x);
  356. this->y = T(v.y);
  357. this->z = T(v.z);
  358. this->w = T(v.w);
  359. return *this;
  360. }
  361. template <typename T>
  362. template <typename U>
  363. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator+=
  364. (
  365. U const & s
  366. )
  367. {
  368. this->x += T(s);
  369. this->y += T(s);
  370. this->z += T(s);
  371. this->w += T(s);
  372. return *this;
  373. }
  374. template <typename T>
  375. template <typename U>
  376. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator+=
  377. (
  378. tvec4<U> const & v
  379. )
  380. {
  381. this->x += T(v.x);
  382. this->y += T(v.y);
  383. this->z += T(v.z);
  384. this->w += T(v.w);
  385. return *this;
  386. }
  387. template <typename T>
  388. template <typename U>
  389. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator-=
  390. (
  391. U const & s
  392. )
  393. {
  394. this->x -= T(s);
  395. this->y -= T(s);
  396. this->z -= T(s);
  397. this->w -= T(s);
  398. return *this;
  399. }
  400. template <typename T>
  401. template <typename U>
  402. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator-=
  403. (
  404. tvec4<U> const & v
  405. )
  406. {
  407. this->x -= T(v.x);
  408. this->y -= T(v.y);
  409. this->z -= T(v.z);
  410. this->w -= T(v.w);
  411. return *this;
  412. }
  413. template <typename T>
  414. template <typename U>
  415. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator*=
  416. (
  417. U const & s
  418. )
  419. {
  420. this->x *= T(s);
  421. this->y *= T(s);
  422. this->z *= T(s);
  423. this->w *= T(s);
  424. return *this;
  425. }
  426. template <typename T>
  427. template <typename U>
  428. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator*=
  429. (
  430. tvec4<U> const & v
  431. )
  432. {
  433. this->x *= T(v.x);
  434. this->y *= T(v.y);
  435. this->z *= T(v.z);
  436. this->w *= T(v.w);
  437. return *this;
  438. }
  439. template <typename T>
  440. template <typename U>
  441. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator/=
  442. (
  443. U const & s
  444. )
  445. {
  446. this->x /= T(s);
  447. this->y /= T(s);
  448. this->z /= T(s);
  449. this->w /= T(s);
  450. return *this;
  451. }
  452. template <typename T>
  453. template <typename U>
  454. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator/=
  455. (
  456. tvec4<U> const & v
  457. )
  458. {
  459. this->x /= T(v.x);
  460. this->y /= T(v.y);
  461. this->z /= T(v.z);
  462. this->w /= T(v.w);
  463. return *this;
  464. }
  465. template <typename T>
  466. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator++()
  467. {
  468. ++this->x;
  469. ++this->y;
  470. ++this->z;
  471. ++this->w;
  472. return *this;
  473. }
  474. template <typename T>
  475. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator--()
  476. {
  477. --this->x;
  478. --this->y;
  479. --this->z;
  480. --this->w;
  481. return *this;
  482. }
  483. //////////////////////////////////////
  484. // Unary bit operators
  485. template <typename T>
  486. template <typename U>
  487. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator%=
  488. (
  489. U const & s
  490. )
  491. {
  492. this->x %= T(s);
  493. this->y %= T(s);
  494. this->z %= T(s);
  495. this->w %= T(s);
  496. return *this;
  497. }
  498. template <typename T>
  499. template <typename U>
  500. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator%=
  501. (
  502. tvec4<U> const & v
  503. )
  504. {
  505. this->x %= T(v.x);
  506. this->y %= T(v.y);
  507. this->z %= T(v.z);
  508. this->w %= T(v.w);
  509. return *this;
  510. }
  511. template <typename T>
  512. template <typename U>
  513. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator&=
  514. (
  515. U const & s
  516. )
  517. {
  518. this->x &= T(s);
  519. this->y &= T(s);
  520. this->z &= T(s);
  521. this->w &= T(s);
  522. return *this;
  523. }
  524. template <typename T>
  525. template <typename U>
  526. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator&=
  527. (
  528. tvec4<U> const & v
  529. )
  530. {
  531. this->x &= T(v.x);
  532. this->y &= T(v.y);
  533. this->z &= T(v.z);
  534. this->w &= T(v.w);
  535. return *this;
  536. }
  537. template <typename T>
  538. template <typename U>
  539. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator|=
  540. (
  541. U const & s
  542. )
  543. {
  544. this->x |= T(s);
  545. this->y |= T(s);
  546. this->z |= T(s);
  547. this->w |= T(s);
  548. return *this;
  549. }
  550. template <typename T>
  551. template <typename U>
  552. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator|=
  553. (
  554. tvec4<U> const & v
  555. )
  556. {
  557. this->x |= T(v.x);
  558. this->y |= T(v.y);
  559. this->z |= T(v.z);
  560. this->w |= T(v.w);
  561. return *this;
  562. }
  563. template <typename T>
  564. template <typename U>
  565. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator^=
  566. (
  567. U const & s
  568. )
  569. {
  570. this->x ^= T(s);
  571. this->y ^= T(s);
  572. this->z ^= T(s);
  573. this->w ^= T(s);
  574. return *this;
  575. }
  576. template <typename T>
  577. template <typename U>
  578. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator^=
  579. (
  580. tvec4<U> const & v
  581. )
  582. {
  583. this->x ^= T(v.x);
  584. this->y ^= T(v.y);
  585. this->z ^= T(v.z);
  586. this->w ^= T(v.w);
  587. return *this;
  588. }
  589. template <typename T>
  590. template <typename U>
  591. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator<<=
  592. (
  593. U const & s
  594. )
  595. {
  596. this->x <<= T(s);
  597. this->y <<= T(s);
  598. this->z <<= T(s);
  599. this->w <<= T(s);
  600. return *this;
  601. }
  602. template <typename T>
  603. template <typename U>
  604. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator<<=
  605. (
  606. tvec4<U> const & v
  607. )
  608. {
  609. this->x <<= T(v.x);
  610. this->y <<= T(v.y);
  611. this->z <<= T(v.z);
  612. this->w <<= T(v.w);
  613. return *this;
  614. }
  615. template <typename T>
  616. template <typename U>
  617. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator>>=
  618. (
  619. U const & s
  620. )
  621. {
  622. this->x >>= T(s);
  623. this->y >>= T(s);
  624. this->z >>= T(s);
  625. this->w >>= T(s);
  626. return *this;
  627. }
  628. template <typename T>
  629. template <typename U>
  630. GLM_FUNC_QUALIFIER tvec4<T> & tvec4<T>::operator>>=
  631. (
  632. tvec4<U> const & v
  633. )
  634. {
  635. this->x >>= T(v.x);
  636. this->y >>= T(v.y);
  637. this->z >>= T(v.z);
  638. this->w >>= T(v.w);
  639. return *this;
  640. }
  641. //////////////////////////////////////
  642. // Swizzle operators
  643. template <typename T>
  644. GLM_FUNC_QUALIFIER typename tvec4<T>::value_type
  645. tvec4<T>::swizzle
  646. (
  647. comp x
  648. ) const
  649. {
  650. return (*this)[x];
  651. }
  652. template <typename T>
  653. GLM_FUNC_QUALIFIER tvec2<T> tvec4<T>::swizzle
  654. (
  655. comp x,
  656. comp y
  657. ) const
  658. {
  659. return tvec2<T>(
  660. (*this)[x],
  661. (*this)[y]);
  662. }
  663. template <typename T>
  664. GLM_FUNC_QUALIFIER tvec3<T> tvec4<T>::swizzle
  665. (
  666. comp x,
  667. comp y,
  668. comp z
  669. ) const
  670. {
  671. return tvec3<T>(
  672. (*this)[x],
  673. (*this)[y],
  674. (*this)[z]);
  675. }
  676. template <typename T>
  677. GLM_FUNC_QUALIFIER tvec4<T> tvec4<T>::swizzle
  678. (
  679. comp x,
  680. comp y,
  681. comp z,
  682. comp w
  683. ) const
  684. {
  685. return tvec4<T>(
  686. (*this)[x],
  687. (*this)[y],
  688. (*this)[z],
  689. (*this)[w]);
  690. }
  691. template <typename T>
  692. GLM_FUNC_QUALIFIER tref2<T> tvec4<T>::swizzle
  693. (
  694. comp x,
  695. comp y
  696. )
  697. {
  698. return tref2<T>(
  699. (*this)[x],
  700. (*this)[y]);
  701. }
  702. template <typename T>
  703. GLM_FUNC_QUALIFIER tref3<T> tvec4<T>::swizzle
  704. (
  705. comp x,
  706. comp y,
  707. comp z
  708. )
  709. {
  710. return tref3<T>(
  711. (*this)[x],
  712. (*this)[y],
  713. (*this)[z]);
  714. }
  715. template <typename T>
  716. GLM_FUNC_QUALIFIER tref4<T> tvec4<T>::swizzle
  717. (
  718. comp x,
  719. comp y,
  720. comp z,
  721. comp w
  722. )
  723. {
  724. return tref4<T>(
  725. (*this)[x],
  726. (*this)[y],
  727. (*this)[z],
  728. (*this)[w]);
  729. }
  730. //////////////////////////////////////
  731. // Binary arithmetic operators
  732. template <typename T>
  733. GLM_FUNC_QUALIFIER tvec4<T> operator+
  734. (
  735. tvec4<T> const & v,
  736. typename tvec4<T>::value_type const & s
  737. )
  738. {
  739. return tvec4<T>(
  740. v.x + s,
  741. v.y + s,
  742. v.z + s,
  743. v.w + s);
  744. }
  745. template <typename T>
  746. GLM_FUNC_QUALIFIER tvec4<T> operator+
  747. (
  748. typename tvec4<T>::value_type const & s,
  749. tvec4<T> const & v
  750. )
  751. {
  752. return tvec4<T>(
  753. s + v.x,
  754. s + v.y,
  755. s + v.z,
  756. s + v.w);
  757. }
  758. template <typename T>
  759. GLM_FUNC_QUALIFIER tvec4<T> operator+
  760. (
  761. tvec4<T> const & v1,
  762. tvec4<T> const & v2
  763. )
  764. {
  765. return tvec4<T>(
  766. v1.x + v2.x,
  767. v1.y + v2.y,
  768. v1.z + v2.z,
  769. v1.w + v2.w);
  770. }
  771. //operator-
  772. template <typename T>
  773. GLM_FUNC_QUALIFIER tvec4<T> operator-
  774. (
  775. tvec4<T> const & v,
  776. typename tvec4<T>::value_type const & s
  777. )
  778. {
  779. return tvec4<T>(
  780. v.x - s,
  781. v.y - s,
  782. v.z - s,
  783. v.w - s);
  784. }
  785. template <typename T>
  786. GLM_FUNC_QUALIFIER tvec4<T> operator-
  787. (
  788. typename tvec4<T>::value_type const & s,
  789. tvec4<T> const & v
  790. )
  791. {
  792. return tvec4<T>(
  793. s - v.x,
  794. s - v.y,
  795. s - v.z,
  796. s - v.w);
  797. }
  798. template <typename T>
  799. GLM_FUNC_QUALIFIER tvec4<T> operator-
  800. (
  801. tvec4<T> const & v1,
  802. tvec4<T> const & v2
  803. )
  804. {
  805. return tvec4<T>(
  806. v1.x - v2.x,
  807. v1.y - v2.y,
  808. v1.z - v2.z,
  809. v1.w - v2.w);
  810. }
  811. //operator*
  812. template <typename T>
  813. GLM_FUNC_QUALIFIER tvec4<T> operator*
  814. (
  815. tvec4<T> const & v,
  816. typename tvec4<T>::value_type const & s
  817. )
  818. {
  819. return tvec4<T>(
  820. v.x * s,
  821. v.y * s,
  822. v.z * s,
  823. v.w * s);
  824. }
  825. template <typename T>
  826. GLM_FUNC_QUALIFIER tvec4<T> operator*
  827. (
  828. typename tvec4<T>::value_type const & s,
  829. tvec4<T> const & v
  830. )
  831. {
  832. return tvec4<T>(
  833. s * v.x,
  834. s * v.y,
  835. s * v.z,
  836. s * v.w);
  837. }
  838. template <typename T>
  839. GLM_FUNC_QUALIFIER tvec4<T> operator*
  840. (
  841. tvec4<T> const & v1,
  842. tvec4<T> const & v2
  843. )
  844. {
  845. return tvec4<T>(
  846. v1.x * v2.x,
  847. v1.y * v2.y,
  848. v1.z * v2.z,
  849. v1.w * v2.w);
  850. }
  851. //operator/
  852. template <typename T>
  853. GLM_FUNC_QUALIFIER tvec4<T> operator/
  854. (
  855. tvec4<T> const & v,
  856. typename tvec4<T>::value_type const & s
  857. )
  858. {
  859. return tvec4<T>(
  860. v.x / s,
  861. v.y / s,
  862. v.z / s,
  863. v.w / s);
  864. }
  865. template <typename T>
  866. GLM_FUNC_QUALIFIER tvec4<T> operator/
  867. (
  868. typename tvec4<T>::value_type const & s,
  869. tvec4<T> const & v
  870. )
  871. {
  872. return tvec4<T>(
  873. s / v.x,
  874. s / v.y,
  875. s / v.z,
  876. s / v.w);
  877. }
  878. template <typename T>
  879. GLM_FUNC_QUALIFIER tvec4<T> operator/
  880. (
  881. tvec4<T> const & v1,
  882. tvec4<T> const & v2
  883. )
  884. {
  885. return tvec4<T>(
  886. v1.x / v2.x,
  887. v1.y / v2.y,
  888. v1.z / v2.z,
  889. v1.w / v2.w);
  890. }
  891. // Unary constant operators
  892. template <typename T>
  893. GLM_FUNC_QUALIFIER tvec4<T> operator-
  894. (
  895. tvec4<T> const & v
  896. )
  897. {
  898. return tvec4<T>(
  899. -v.x,
  900. -v.y,
  901. -v.z,
  902. -v.w);
  903. }
  904. template <typename T>
  905. GLM_FUNC_QUALIFIER tvec4<T> operator++
  906. (
  907. tvec4<T> const & v,
  908. int
  909. )
  910. {
  911. typename tvec4<T>::value_type One(1);
  912. return tvec4<T>(
  913. v.x + One,
  914. v.y + One,
  915. v.z + One,
  916. v.w + One);
  917. }
  918. template <typename T>
  919. GLM_FUNC_QUALIFIER tvec4<T> operator--
  920. (
  921. tvec4<T> const & v,
  922. int
  923. )
  924. {
  925. typename tvec4<T>::value_type One(1);
  926. return tvec4<T>(
  927. v.x - One,
  928. v.y - One,
  929. v.z - One,
  930. v.w - One);
  931. }
  932. //////////////////////////////////////
  933. // Boolean operators
  934. template <typename T>
  935. GLM_FUNC_QUALIFIER bool operator==
  936. (
  937. tvec4<T> const & v1,
  938. tvec4<T> const & v2
  939. )
  940. {
  941. return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z) && (v1.w == v2.w);
  942. }
  943. template <typename T>
  944. GLM_FUNC_QUALIFIER bool operator!=
  945. (
  946. tvec4<T> const & v1,
  947. tvec4<T> const & v2
  948. )
  949. {
  950. return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z) || (v1.w != v2.w);
  951. }
  952. //////////////////////////////////////
  953. // Binary bit operators
  954. template <typename T>
  955. GLM_FUNC_QUALIFIER tvec4<T> operator%
  956. (
  957. tvec4<T> const & v,
  958. typename tvec4<T>::value_type const & s
  959. )
  960. {
  961. return tvec4<T>(
  962. v.x % s,
  963. v.y % s,
  964. v.z % s,
  965. v.w % s);
  966. }
  967. template <typename T>
  968. GLM_FUNC_QUALIFIER tvec4<T> operator%
  969. (
  970. typename tvec4<T>::value_type const & s,
  971. tvec4<T> const & v
  972. )
  973. {
  974. return tvec4<T>(
  975. s % v.x,
  976. s % v.y,
  977. s % v.z,
  978. s % v.w);
  979. }
  980. template <typename T>
  981. GLM_FUNC_QUALIFIER tvec4<T> operator%
  982. (
  983. tvec4<T> const & v1,
  984. tvec4<T> const & v2
  985. )
  986. {
  987. return tvec4<T>(
  988. v1.x % v2.x,
  989. v1.y % v2.y,
  990. v1.z % v2.z,
  991. v1.w % v2.w);
  992. }
  993. template <typename T>
  994. GLM_FUNC_QUALIFIER tvec4<T> operator&
  995. (
  996. tvec4<T> const & v,
  997. typename tvec4<T>::value_type const & s
  998. )
  999. {
  1000. return tvec4<T>(
  1001. v.x & s,
  1002. v.y & s,
  1003. v.z & s,
  1004. v.w & s);
  1005. }
  1006. template <typename T>
  1007. GLM_FUNC_QUALIFIER tvec4<T> operator&
  1008. (
  1009. typename tvec4<T>::value_type const & s,
  1010. tvec4<T> const & v
  1011. )
  1012. {
  1013. return tvec4<T>(
  1014. s & v.x,
  1015. s & v.y,
  1016. s & v.z,
  1017. s & v.w);
  1018. }
  1019. template <typename T>
  1020. GLM_FUNC_QUALIFIER tvec4<T> operator&
  1021. (
  1022. tvec4<T> const & v1,
  1023. tvec4<T> const & v2
  1024. )
  1025. {
  1026. return tvec4<T>(
  1027. v1.x & v2.x,
  1028. v1.y & v2.y,
  1029. v1.z & v2.z,
  1030. v1.w & v2.w);
  1031. }
  1032. template <typename T>
  1033. GLM_FUNC_QUALIFIER tvec4<T> operator|
  1034. (
  1035. tvec4<T> const & v,
  1036. typename tvec4<T>::value_type const & s
  1037. )
  1038. {
  1039. return tvec4<T>(
  1040. v.x | s,
  1041. v.y | s,
  1042. v.z | s,
  1043. v.w | s);
  1044. }
  1045. template <typename T>
  1046. GLM_FUNC_QUALIFIER tvec4<T> operator|
  1047. (
  1048. typename tvec4<T>::value_type const & s,
  1049. tvec4<T> const & v
  1050. )
  1051. {
  1052. return tvec4<T>(
  1053. s | v.x,
  1054. s | v.y,
  1055. s | v.z,
  1056. s | v.w);
  1057. }
  1058. template <typename T>
  1059. GLM_FUNC_QUALIFIER tvec4<T> operator|
  1060. (
  1061. tvec4<T> const & v1,
  1062. tvec4<T> const & v2
  1063. )
  1064. {
  1065. return tvec4<T>(
  1066. v1.x | v2.x,
  1067. v1.y | v2.y,
  1068. v1.z | v2.z,
  1069. v1.w | v2.w);
  1070. }
  1071. template <typename T>
  1072. GLM_FUNC_QUALIFIER tvec4<T> operator^
  1073. (
  1074. tvec4<T> const & v,
  1075. typename tvec4<T>::value_type const & s
  1076. )
  1077. {
  1078. return tvec4<T>(
  1079. v.x ^ s,
  1080. v.y ^ s,
  1081. v.z ^ s,
  1082. v.w ^ s);
  1083. }
  1084. template <typename T>
  1085. GLM_FUNC_QUALIFIER tvec4<T> operator^
  1086. (
  1087. typename tvec4<T>::value_type const & s,
  1088. tvec4<T> const & v
  1089. )
  1090. {
  1091. return tvec4<T>(
  1092. s ^ v.x,
  1093. s ^ v.y,
  1094. s ^ v.z,
  1095. s ^ v.w);
  1096. }
  1097. template <typename T>
  1098. GLM_FUNC_QUALIFIER tvec4<T> operator^
  1099. (
  1100. tvec4<T> const & v1,
  1101. tvec4<T> const & v2
  1102. )
  1103. {
  1104. return tvec4<T>(
  1105. v1.x ^ v2.x,
  1106. v1.y ^ v2.y,
  1107. v1.z ^ v2.z,
  1108. v1.w ^ v2.w);
  1109. }
  1110. template <typename T>
  1111. GLM_FUNC_QUALIFIER tvec4<T> operator<<
  1112. (
  1113. tvec4<T> const & v,
  1114. typename tvec4<T>::value_type const & s
  1115. )
  1116. {
  1117. return tvec4<T>(
  1118. v.x << s,
  1119. v.y << s,
  1120. v.z << s,
  1121. v.w << s);
  1122. }
  1123. template <typename T>
  1124. GLM_FUNC_QUALIFIER tvec4<T> operator<<
  1125. (
  1126. typename tvec4<T>::value_type const & s,
  1127. tvec4<T> const & v
  1128. )
  1129. {
  1130. return tvec4<T>(
  1131. s << v.x,
  1132. s << v.y,
  1133. s << v.z,
  1134. s << v.w);
  1135. }
  1136. template <typename T>
  1137. GLM_FUNC_QUALIFIER tvec4<T> operator<<
  1138. (
  1139. tvec4<T> const & v1,
  1140. tvec4<T> const & v2
  1141. )
  1142. {
  1143. return tvec4<T>(
  1144. v1.x << v2.x,
  1145. v1.y << v2.y,
  1146. v1.z << v2.z,
  1147. v1.w << v2.w);
  1148. }
  1149. template <typename T>
  1150. GLM_FUNC_QUALIFIER tvec4<T> operator>>
  1151. (
  1152. tvec4<T> const & v,
  1153. typename tvec4<T>::value_type const & s
  1154. )
  1155. {
  1156. return tvec4<T>(
  1157. v.x >> s,
  1158. v.y >> s,
  1159. v.z >> s,
  1160. v.w >> s);
  1161. }
  1162. template <typename T>
  1163. GLM_FUNC_QUALIFIER tvec4<T> operator>>
  1164. (
  1165. typename tvec4<T>::value_type const & s,
  1166. tvec4<T> const & v
  1167. )
  1168. {
  1169. return tvec4<T>(
  1170. s >> v.x,
  1171. s >> v.y,
  1172. s >> v.z,
  1173. s >> v.w);
  1174. }
  1175. template <typename T>
  1176. GLM_FUNC_QUALIFIER tvec4<T> operator>>
  1177. (
  1178. tvec4<T> const & v1,
  1179. tvec4<T> const & v2
  1180. )
  1181. {
  1182. return tvec4<T>(
  1183. v1.x >> v2.x,
  1184. v1.y >> v2.y,
  1185. v1.z >> v2.z,
  1186. v1.w >> v2.w);
  1187. }
  1188. template <typename T>
  1189. GLM_FUNC_QUALIFIER tvec4<T> operator~
  1190. (
  1191. tvec4<T> const & v
  1192. )
  1193. {
  1194. return tvec4<T>(
  1195. ~v.x,
  1196. ~v.y,
  1197. ~v.z,
  1198. ~v.w);
  1199. }
  1200. //////////////////////////////////////
  1201. // tref definition
  1202. template <typename T>
  1203. tref4<T>::tref4
  1204. (
  1205. T & x,
  1206. T & y,
  1207. T & z,
  1208. T & w
  1209. ) :
  1210. x(x),
  1211. y(y),
  1212. z(z),
  1213. w(w)
  1214. {}
  1215. template <typename T>
  1216. tref4<T>::tref4
  1217. (
  1218. tref4<T> const & r
  1219. ) :
  1220. x(r.x),
  1221. y(r.y),
  1222. z(r.z),
  1223. w(r.w)
  1224. {}
  1225. template <typename T>
  1226. tref4<T>::tref4
  1227. (
  1228. tvec4<T> const & v
  1229. ) :
  1230. x(v.x),
  1231. y(v.y),
  1232. z(v.z),
  1233. w(v.w)
  1234. {}
  1235. template <typename T>
  1236. tref4<T>& tref4<T>::operator=
  1237. (
  1238. tref4<T> const & r
  1239. )
  1240. {
  1241. x = r.x;
  1242. y = r.y;
  1243. z = r.z;
  1244. w = r.w;
  1245. return *this;
  1246. }
  1247. template <typename T>
  1248. tref4<T>& tref4<T>::operator=
  1249. (
  1250. tvec4<T> const & v
  1251. )
  1252. {
  1253. x = v.x;
  1254. y = v.y;
  1255. z = v.z;
  1256. w = v.w;
  1257. return *this;
  1258. }
  1259. template <typename T>
  1260. GLM_FUNC_QUALIFIER tvec4<T> tref4<T>::operator() ()
  1261. {
  1262. return tvec4<T>(this->x, this->y, this->z, this->w);
  1263. }
  1264. }//namespace detail
  1265. }//namespace glm