/glm/core/type_vec1.inl
C++ Header | 928 lines | 775 code | 96 blank | 57 comment | 2 complexity | e30cc8a928cabdfc4d1c587116c3921c 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_vec1.inl
25/// @date 2008-08-25 / 2011-06-15
26/// @author Christophe Riccio
27///////////////////////////////////////////////////////////////////////////////////
28
29namespace glm{
30namespace detail
31{
32 template <typename T>
33 GLM_FUNC_QUALIFIER typename tvec1<T>::size_type tvec1<T>::length() const
34 {
35 return 1;
36 }
37
38 //////////////////////////////////////
39 // Accesses
40
41 template <typename T>
42 GLM_FUNC_QUALIFIER typename tvec1<T>::value_type & tvec1<T>::operator[]
43 (
44 size_type i
45 )
46 {
47 assert(i < this->length());
48 return (&x)[i];
49 }
50
51 template <typename T>
52 GLM_FUNC_QUALIFIER typename tvec1<T>::value_type const & tvec1<T>::operator[]
53 (
54 size_type i
55 ) const
56 {
57 assert(i < this->length());
58 return (&x)[i];
59 }
60
61 //////////////////////////////////////
62 // Implicit basic constructors
63
64 template <typename T>
65 GLM_FUNC_QUALIFIER tvec1<T>::tvec1() :
66 x(value_type(0))
67 {}
68
69 template <typename T>
70 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
71 (
72 ctor
73 )
74 {}
75
76 template <typename T>
77 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
78 (
79 tvec1<T> const & v
80 ) :
81 x(v.x)
82 {}
83
84 //////////////////////////////////////
85 // Explicit basic constructors
86
87 template <typename T>
88 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
89 (
90 value_type const & s
91 ) :
92 x(s)
93 {}
94
95 //////////////////////////////////////
96 // Swizzle constructors
97
98 template <typename T>
99 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
100 (
101 tref1<T> const & r
102 ) :
103 x(r.x)
104 {}
105
106 //////////////////////////////////////
107 // Convertion scalar constructors
108
109 template <typename T>
110 template <typename U>
111 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
112 (
113 U const & s
114 ) :
115 x(value_type(s))
116 {}
117
118 //////////////////////////////////////
119 // Convertion vector constructors
120
121 template <typename T>
122 template <typename U>
123 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
124 (
125 tvec2<U> const & v
126 ) :
127 x(value_type(v.x))
128 {}
129
130 template <typename T>
131 template <typename U>
132 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
133 (
134 tvec3<U> const & v
135 ) :
136 x(value_type(v.x))
137 {}
138
139 template <typename T>
140 template <typename U>
141 GLM_FUNC_QUALIFIER tvec1<T>::tvec1
142 (
143 tvec4<U> const & v
144 ) :
145 x(value_type(v.x))
146 {}
147
148 //////////////////////////////////////
149 // Unary arithmetic operators
150
151 template <typename T>
152 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator=
153 (
154 tvec1<T> const & v
155 )
156 {
157 this->x = v.x;
158 return *this;
159 }
160
161 template <typename T>
162 template <typename U>
163 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator=
164 (
165 tvec1<U> const & v
166 )
167 {
168 this->x = T(v.x);
169 return *this;
170 }
171
172 template <typename T>
173 template <typename U>
174 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator+=
175 (
176 U const & s
177 )
178 {
179 this->x += T(s);
180 return *this;
181 }
182
183 template <typename T>
184 template <typename U>
185 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator+=
186 (
187 tvec1<U> const & v
188 )
189 {
190 this->x += T(v.x);
191 return *this;
192 }
193
194 template <typename T>
195 template <typename U>
196 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator-=
197 (
198 U const & s
199 )
200 {
201 this->x -= T(s);
202 return *this;
203 }
204
205 template <typename T>
206 template <typename U>
207 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator-=
208 (
209 tvec1<U> const & v
210 )
211 {
212 this->x -= T(v.x);
213 return *this;
214 }
215
216 template <typename T>
217 template <typename U>
218 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator*=
219 (
220 U const & s
221 )
222 {
223 this->x *= T(s);
224 return *this;
225 }
226
227 template <typename T>
228 template <typename U>
229 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator*=
230 (
231 tvec1<U> const & v
232 )
233 {
234 this->x *= T(v.x);
235 return *this;
236 }
237
238 template <typename T>
239 template <typename U>
240 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator/=
241 (
242 U const & s
243 )
244 {
245 this->x /= T(s);
246 return *this;
247 }
248
249 template <typename T>
250 template <typename U>
251 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator/=
252 (
253 tvec1<U> const & v
254 )
255 {
256 this->x /= T(v.x);
257 return *this;
258 }
259
260 template <typename T>
261 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator++()
262 {
263 ++this->x;
264 return *this;
265 }
266
267 template <typename T>
268 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator--()
269 {
270 --this->x;
271 return *this;
272 }
273
274 //////////////////////////////////////
275 // Boolean operators
276
277 template <typename T>
278 GLM_FUNC_QUALIFIER bool operator==
279 (
280 tvec1<T> const & v1,
281 tvec1<T> const & v2
282 )
283 {
284 return (v1.x == v2.x);
285 }
286
287 template <typename T>
288 GLM_FUNC_QUALIFIER bool operator!=
289 (
290 tvec1<T> const & v1,
291 tvec1<T> const & v2
292 )
293 {
294 return (v1.x != v2.x);
295 }
296
297 //////////////////////////////////////
298 // Unary bit operators
299
300 template <typename T>
301 template <typename U>
302 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator%=
303 (
304 U const & s
305 )
306 {
307 this->x %= T(s);
308 return *this;
309 }
310
311 template <typename T>
312 template <typename U>
313 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator%=
314 (
315 tvec1<U> const & v
316 )
317 {
318 this->x %= T(v.x);
319 return *this;
320 }
321
322 template <typename T>
323 template <typename U>
324 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator&=
325 (
326 U const & s
327 )
328 {
329 this->x &= T(s);
330 return *this;
331 }
332
333 template <typename T>
334 template <typename U>
335 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator&=
336 (
337 tvec1<U> const & v
338 )
339 {
340 this->x &= T(v.x);
341 return *this;
342 }
343
344 template <typename T>
345 template <typename U>
346 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator|=
347 (
348 U const & s
349 )
350 {
351 this->x |= T(s);
352 return *this;
353 }
354
355 template <typename T>
356 template <typename U>
357 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator|=
358 (
359 tvec1<U> const & v
360 )
361 {
362 this->x |= U(v.x);
363 return *this;
364 }
365
366 template <typename T>
367 template <typename U>
368 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator^=
369 (
370 U const & s
371 )
372 {
373 this->x ^= T(s);
374 return *this;
375 }
376
377 template <typename T>
378 template <typename U>
379 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator^=
380 (
381 tvec1<U> const & v
382 )
383 {
384 this->x ^= T(v.x);
385 return *this;
386 }
387
388 template <typename T>
389 template <typename U>
390 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator<<=
391 (
392 U const & s
393 )
394 {
395 this->x <<= T(s);
396 return *this;
397 }
398
399 template <typename T>
400 template <typename U>
401 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator<<=
402 (
403 tvec1<U> const & v
404 )
405 {
406 this->x <<= T(v.x);
407 return *this;
408 }
409
410 template <typename T>
411 template <typename U>
412 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator>>=
413 (
414 U const & s
415 )
416 {
417 this->x >>= T(s);
418 return *this;
419 }
420
421 template <typename T>
422 template <typename U>
423 GLM_FUNC_QUALIFIER tvec1<T> & tvec1<T>::operator>>=
424 (
425 tvec1<U> const & v
426 )
427 {
428 this->x >>= T(v.x);
429 return *this;
430 }
431
432 //////////////////////////////////////
433 // Swizzle operators
434
435 template <typename T>
436 GLM_FUNC_QUALIFIER T
437 tvec1<T>::swizzle(comp x) const
438 {
439 return (*this)[x];
440 }
441
442 template <typename T>
443 GLM_FUNC_QUALIFIER tvec2<T>
444 tvec1<T>::swizzle
445 (
446 comp x,
447 comp y
448 ) const
449 {
450 return tvec2<T>(
451 (*this)[x],
452 (*this)[y]);
453 }
454
455 template <typename T>
456 GLM_FUNC_QUALIFIER tvec3<T>
457 tvec1<T>::swizzle
458 (
459 comp x,
460 comp y,
461 comp z
462 ) const
463 {
464 return tvec3<T>(
465 (*this)[x],
466 (*this)[y],
467 (*this)[z]);
468 }
469
470 template <typename T>
471 GLM_FUNC_QUALIFIER tvec4<T>
472 tvec1<T>::swizzle
473 (
474 comp x,
475 comp y,
476 comp z,
477 comp w
478 ) const
479 {
480 return tvec4<T>(
481 (*this)[x],
482 (*this)[y],
483 (*this)[z],
484 (*this)[w]);
485 }
486
487 template <typename T>
488 GLM_FUNC_QUALIFIER tref1<T>
489 tvec1<T>::swizzle
490 (
491 comp x
492 )
493 {
494 return tref1<T>(
495 (*this)[x]);
496 }
497
498 //////////////////////////////////////
499 // Binary arithmetic operators
500
501 template <typename T>
502 GLM_FUNC_QUALIFIER tvec1<T> operator+
503 (
504 tvec1<T> const & v,
505 typename tvec1<T>::value_type const & s
506 )
507 {
508 return tvec1<T>(
509 v.x + s);
510 }
511
512 template <typename T>
513 GLM_FUNC_QUALIFIER tvec1<T> operator+
514 (
515 typename tvec1<T>::value_type const & s,
516 tvec1<T> const & v
517 )
518 {
519 return tvec1<T>(
520 s + v.x);
521 }
522
523 template <typename T>
524 GLM_FUNC_QUALIFIER tvec1<T> operator+
525 (
526 tvec1<T> const & v1,
527 tvec1<T> const & v2
528 )
529 {
530 return tvec1<T>(
531 v1.x + v2.x);
532 }
533
534 //operator-
535 template <typename T>
536 GLM_FUNC_QUALIFIER tvec1<T> operator-
537 (
538 tvec1<T> const & v,
539 typename tvec1<T>::value_type const & s
540 )
541 {
542 return tvec1<T>(
543 v.x - s);
544 }
545
546 template <typename T>
547 GLM_FUNC_QUALIFIER tvec1<T> operator-
548 (
549 typename tvec1<T>::value_type const & s,
550 tvec1<T> const & v
551 )
552 {
553 return tvec1<T>(
554 s - v.x);
555 }
556
557 template <typename T>
558 GLM_FUNC_QUALIFIER tvec1<T> operator-
559 (
560 tvec1<T> const & v1,
561 tvec1<T> const & v2
562 )
563 {
564 return tvec1<T>(
565 v1.x - v2.x);
566 }
567
568 //operator*
569 template <typename T>
570 GLM_FUNC_QUALIFIER tvec1<T> operator*
571 (
572 tvec1<T> const & v,
573 typename tvec1<T>::value_type const & s
574 )
575 {
576 return tvec1<T>(
577 v.x * s);
578 }
579
580 template <typename T>
581 GLM_FUNC_QUALIFIER tvec1<T> operator*
582 (
583 typename tvec1<T>::value_type const & s,
584 tvec1<T> const & v
585 )
586 {
587 return tvec1<T>(
588 s * v.x);
589 }
590
591 template <typename T>
592 GLM_FUNC_QUALIFIER tvec1<T> operator*
593 (
594 tvec1<T> const & v1,
595 tvec1<T> const & v2
596 )
597 {
598 return tvec1<T>(
599 v1.x * v2.x);
600 }
601
602 //operator/
603 template <typename T>
604 GLM_FUNC_QUALIFIER tvec1<T> operator/
605 (
606 tvec1<T> const & v,
607 typename tvec1<T>::value_type const & s
608 )
609 {
610 return tvec1<T>(
611 v.x / s);
612 }
613
614 template <typename T>
615 GLM_FUNC_QUALIFIER tvec1<T> operator/
616 (
617 typename tvec1<T>::value_type const & s,
618 tvec1<T> const & v
619 )
620 {
621 return tvec1<T>(
622 s / v.x);
623 }
624
625 template <typename T>
626 GLM_FUNC_QUALIFIER tvec1<T> operator/
627 (
628 tvec1<T> const & v1,
629 tvec1<T> const & v2
630 )
631 {
632 return tvec1<T>(
633 v1.x / v2.x);
634 }
635
636 // Unary constant operators
637 template <typename T>
638 GLM_FUNC_QUALIFIER tvec1<T> operator-
639 (
640 tvec1<T> const & v
641 )
642 {
643 return tvec1<T>(
644 -v.x);
645 }
646
647 template <typename T>
648 GLM_FUNC_QUALIFIER tvec1<T> operator++
649 (
650 tvec1<T> const & v,
651 int
652 )
653 {
654 return tvec1<T>(
655 v.x + T(1));
656 }
657
658 template <typename T>
659 GLM_FUNC_QUALIFIER tvec1<T> operator--
660 (
661 tvec1<T> const & v,
662 int
663 )
664 {
665 return tvec1<T>(
666 v.x - T(1));
667 }
668
669 //////////////////////////////////////
670 // Binary bit operators
671
672 template <typename T>
673 GLM_FUNC_QUALIFIER tvec1<T> operator%
674 (
675 tvec1<T> const & v,
676 typename tvec1<T>::value_type const & s
677 )
678 {
679 return tvec1<T>(
680 v.x % s);
681 }
682
683 template <typename T>
684 GLM_FUNC_QUALIFIER tvec1<T> operator%
685 (
686 typename tvec1<T>::value_type const & s,
687 tvec1<T> const & v
688 )
689 {
690 return tvec1<T>(
691 s % v.x);
692 }
693
694 template <typename T>
695 GLM_FUNC_QUALIFIER tvec1<T> operator%
696 (
697 tvec1<T> const & v1,
698 tvec1<T> const & v2
699 )
700 {
701 return tvec1<T>(
702 v1.x % v2.x);
703 }
704
705 template <typename T>
706 GLM_FUNC_QUALIFIER tvec1<T> operator&
707 (
708 tvec1<T> const & v,
709 typename tvec1<T>::value_type const & s
710 )
711 {
712 return tvec1<T>(
713 v.x & s);
714 }
715
716 template <typename T>
717 GLM_FUNC_QUALIFIER tvec1<T> operator&
718 (
719 typename tvec1<T>::value_type const & s,
720 tvec1<T> const & v
721 )
722 {
723 return tvec1<T>(
724 s & v.x);
725 }
726
727 template <typename T>
728 GLM_FUNC_QUALIFIER tvec1<T> operator&
729 (
730 tvec1<T> const & v1,
731 tvec1<T> const & v2
732 )
733 {
734 return tvec1<T>(
735 v1.x & v2.x);
736 }
737
738 template <typename T>
739 GLM_FUNC_QUALIFIER tvec1<T> operator|
740 (
741 tvec1<T> const & v,
742 typename tvec1<T>::value_type const & s
743 )
744 {
745 return tvec1<T>(
746 v.x | s);
747 }
748
749 template <typename T>
750 GLM_FUNC_QUALIFIER tvec1<T> operator|
751 (
752 typename tvec1<T>::value_type const & s,
753 tvec1<T> const & v
754 )
755 {
756 return tvec1<T>(
757 s | v.x);
758 }
759
760 template <typename T>
761 GLM_FUNC_QUALIFIER tvec1<T> operator|
762 (
763 tvec1<T> const & v1,
764 tvec1<T> const & v2
765 )
766 {
767 return tvec1<T>(
768 v1.x | v2.x);
769 }
770
771 template <typename T>
772 GLM_FUNC_QUALIFIER tvec1<T> operator^
773 (
774 tvec1<T> const & v,
775 typename tvec1<T>::value_type const & s
776 )
777 {
778 return tvec1<T>(
779 v.x ^ s);
780 }
781
782 template <typename T>
783 GLM_FUNC_QUALIFIER tvec1<T> operator^
784 (
785 typename tvec1<T>::value_type const & s,
786 tvec1<T> const & v
787 )
788 {
789 return tvec1<T>(
790 s ^ v.x);
791 }
792
793 template <typename T>
794 GLM_FUNC_QUALIFIER tvec1<T> operator^
795 (
796 tvec1<T> const & v1,
797 tvec1<T> const & v2
798 )
799 {
800 return tvec1<T>(
801 v1.x ^ v2.x);
802 }
803
804 template <typename T>
805 GLM_FUNC_QUALIFIER tvec1<T> operator<<
806 (
807 tvec1<T> const & v,
808 typename tvec1<T>::value_type const & s
809 )
810 {
811 return tvec1<T>(
812 v.x << s);
813 }
814
815 template <typename T>
816 GLM_FUNC_QUALIFIER tvec1<T> operator<<
817 (
818 typename tvec1<T>::value_type const & s,
819 tvec1<T> const & v
820 )
821 {
822 return tvec1<T>(
823 s << v.x);
824 }
825
826 template <typename T>
827 GLM_FUNC_QUALIFIER tvec1<T> operator<<
828 (
829 tvec1<T> const & v1,
830 tvec1<T> const & v2
831 )
832 {
833 return tvec1<T>(
834 v1.x << v2.x);
835 }
836
837 template <typename T>
838 GLM_FUNC_QUALIFIER tvec1<T> operator>>
839 (
840 tvec1<T> const & v,
841 typename tvec1<T>::value_type const & s
842 )
843 {
844 return tvec1<T>(
845 v.x >> s);
846 }
847
848 template <typename T>
849 GLM_FUNC_QUALIFIER tvec1<T> operator>>
850 (
851 typename tvec1<T>::value_type const & s,
852 tvec1<T> const & v
853 )
854 {
855 return tvec1<T>(
856 s >> v.x);
857 }
858
859 template <typename T>
860 GLM_FUNC_QUALIFIER tvec1<T> operator>>
861 (
862 tvec1<T> const & v1,
863 tvec1<T> const & v2
864 )
865 {
866 return tvec1<T>(
867 v1.x >> v2.x);
868 }
869
870 template <typename T>
871 GLM_FUNC_QUALIFIER tvec1<T> operator~
872 (
873 tvec1<T> const & v
874 )
875 {
876 return tvec1<T>(
877 ~v.x);
878 }
879
880 //////////////////////////////////////
881 // tref definition
882
883 template <typename T>
884 GLM_FUNC_QUALIFIER tref1<T>::tref1
885 (
886 T & x
887 ) :
888 x(x)
889 {}
890
891 template <typename T>
892 GLM_FUNC_QUALIFIER tref1<T>::tref1
893 (
894 tref1<T> const & r
895 ) :
896 x(r.x)
897 {}
898
899 template <typename T>
900 GLM_FUNC_QUALIFIER tref1<T>::tref1
901 (
902 tvec1<T> const & v
903 ) :
904 x(v.x)
905 {}
906
907 template <typename T>
908 GLM_FUNC_QUALIFIER tref1<T> & tref1<T>::operator=
909 (
910 tref1<T> const & r
911 )
912 {
913 x = r.x;
914 return *this;
915 }
916
917 template <typename T>
918 GLM_FUNC_QUALIFIER tref1<T> & tref1<T>::operator=
919 (
920 tvec1<T> const & v
921 )
922 {
923 x = v.x;
924 return *this;
925 }
926
927}//namespace detail
928}//namespace glm