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