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_mat2x3.inl 25/// @date 2006-08-05 / 2011-06-15 26/// @author Christophe Riccio 27/////////////////////////////////////////////////////////////////////////////////// 28 29namespace glm{ 30namespace detail 31{ 32 template <typename T, precision P> 33 GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tmat2x3<T, P>::length() const 34 { 35 return 2; 36 } 37 38 ////////////////////////////////////// 39 // Accesses 40 41 template <typename T, precision P> 42 GLM_FUNC_QUALIFIER typename tmat2x3<T, P>::col_type & 43 tmat2x3<T, P>::operator[] 44 ( 45 length_t i 46 ) 47 { 48 assert(i < this->length()); 49 return this->value[i]; 50 } 51 52 template <typename T, precision P> 53 GLM_FUNC_QUALIFIER typename tmat2x3<T, P>::col_type const & 54 tmat2x3<T, P>::operator[] 55 ( 56 length_t i 57 ) const 58 { 59 assert(i < this->length()); 60 return this->value[i]; 61 } 62 63 ////////////////////////////////////////////////////////////// 64 // Constructors 65 66 template <typename T, precision P> 67 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3() 68 { 69 this->value[0] = col_type(T(1), T(0), T(0)); 70 this->value[1] = col_type(T(0), T(1), T(0)); 71 } 72 73 template <typename T, precision P> 74 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 75 ( 76 tmat2x3<T, P> const & m 77 ) 78 { 79 this->value[0] = m.value[0]; 80 this->value[1] = m.value[1]; 81 } 82 83 template <typename T, precision P> 84 template <precision Q> 85 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3( 86 tmat2x3<T, Q> const & m) 87 { 88 this->value[0] = m.value[0]; 89 this->value[1] = m.value[1]; 90 } 91 92 template <typename T, precision P> 93 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 94 ( 95 ctor 96 ) 97 {} 98 99 template <typename T, precision P> 100 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 101 ( 102 T const & s 103 ) 104 { 105 this->value[0] = col_type(s, T(0), T(0)); 106 this->value[1] = col_type(T(0), s, T(0)); 107 } 108 109 template <typename T, precision P> 110 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 111 ( 112 T const & x0, T const & y0, T const & z0, 113 T const & x1, T const & y1, T const & z1 114 ) 115 { 116 this->value[0] = col_type(x0, y0, z0); 117 this->value[1] = col_type(x1, y1, z1); 118 } 119 120 template <typename T, precision P> 121 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 122 ( 123 col_type const & v0, 124 col_type const & v1 125 ) 126 { 127 this->value[0] = v0; 128 this->value[1] = v1; 129 } 130 131 ////////////////////////////////////// 132 // Conversion constructors 133 template <typename T, precision P> 134 template < 135 typename X1, typename Y1, typename Z1, 136 typename X2, typename Y2, typename Z2> 137 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 138 ( 139 X1 const & x1, Y1 const & y1, Z1 const & z1, 140 X2 const & x2, Y2 const & y2, Z2 const & z2 141 ) 142 { 143 this->value[0] = col_type(static_cast<T>(x1), value_type(y1), value_type(z1)); 144 this->value[1] = col_type(static_cast<T>(x2), value_type(y2), value_type(z2)); 145 } 146 147 template <typename T, precision P> 148 template <typename V1, typename V2> 149 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 150 ( 151 tvec3<V1, P> const & v1, 152 tvec3<V2, P> const & v2 153 ) 154 { 155 this->value[0] = col_type(v1); 156 this->value[1] = col_type(v2); 157 } 158 159 ////////////////////////////////////// 160 // Matrix conversions 161 162 template <typename T, precision P> 163 template <typename U, precision Q> 164 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 165 ( 166 tmat2x3<U, Q> const & m 167 ) 168 { 169 this->value[0] = col_type(m[0]); 170 this->value[1] = col_type(m[1]); 171 } 172 173 template <typename T, precision P> 174 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 175 ( 176 tmat2x2<T, P> const & m 177 ) 178 { 179 this->value[0] = col_type(m[0], T(0)); 180 this->value[1] = col_type(m[1], T(0)); 181 } 182 183 template <typename T, precision P> 184 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 185 ( 186 tmat3x3<T, P> const & m 187 ) 188 { 189 this->value[0] = col_type(m[0]); 190 this->value[1] = col_type(m[1]); 191 } 192 193 template <typename T, precision P> 194 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 195 ( 196 tmat4x4<T, P> const & m 197 ) 198 { 199 this->value[0] = col_type(m[0]); 200 this->value[1] = col_type(m[1]); 201 } 202 203 template <typename T, precision P> 204 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 205 ( 206 tmat2x4<T, P> const & m 207 ) 208 { 209 this->value[0] = col_type(m[0]); 210 this->value[1] = col_type(m[1]); 211 } 212 213 template <typename T, precision P> 214 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 215 ( 216 tmat3x2<T, P> const & m 217 ) 218 { 219 this->value[0] = col_type(m[0], T(0)); 220 this->value[1] = col_type(m[1], T(0)); 221 } 222 223 template <typename T, precision P> 224 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 225 ( 226 tmat3x4<T, P> const & m 227 ) 228 { 229 this->value[0] = col_type(m[0]); 230 this->value[1] = col_type(m[1]); 231 } 232 233 template <typename T, precision P> 234 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 235 ( 236 tmat4x2<T, P> const & m 237 ) 238 { 239 this->value[0] = col_type(m[0], T(0)); 240 this->value[1] = col_type(m[1], T(0)); 241 } 242 243 template <typename T, precision P> 244 GLM_FUNC_QUALIFIER tmat2x3<T, P>::tmat2x3 245 ( 246 tmat4x3<T, P> const & m 247 ) 248 { 249 this->value[0] = m[0]; 250 this->value[1] = m[1]; 251 } 252 253 ////////////////////////////////////////////////////////////// 254 // Unary updatable operators 255 256 template <typename T, precision P> 257 GLM_FUNC_QUALIFIER tmat2x3<T, P>& tmat2x3<T, P>::operator= (tmat2x3<T, P> const & m) 258 { 259 this->value[0] = m[0]; 260 this->value[1] = m[1]; 261 return *this; 262 } 263 264 template <typename T, precision P> 265 template <typename U> 266 GLM_FUNC_QUALIFIER tmat2x3<T, P>& tmat2x3<T, P>::operator= (tmat2x3<U, P> const & m) 267 { 268 this->value[0] = m[0]; 269 this->value[1] = m[1]; 270 return *this; 271 } 272 273 template <typename T, precision P> 274 template <typename U> 275 GLM_FUNC_QUALIFIER tmat2x3<T, P> & tmat2x3<T, P>::operator+= (U s) 276 { 277 this->value[0] += s; 278 this->value[1] += s; 279 return *this; 280 } 281 282 template <typename T, precision P> 283 template <typename U> 284 GLM_FUNC_QUALIFIER tmat2x3<T, P>& tmat2x3<T, P>::operator+= (tmat2x3<U, P> const & m) 285 { 286 this->value[0] += m[0]; 287 this->value[1] += m[1]; 288 return *this; 289 } 290 291 template <typename T, precision P> 292 template <typename U> 293 GLM_FUNC_QUALIFIER tmat2x3<T, P>& tmat2x3<T, P>::operator-= (U s) 294 { 295 this->value[0] -= s; 296 this->value[1] -= s; 297 return *this; 298 } 299 300 template <typename T, precision P> 301 template <typename U> 302 GLM_FUNC_QUALIFIER tmat2x3<T, P>& tmat2x3<T, P>::operator-= (tmat2x3<U, P> const & m) 303 { 304 this->value[0] -= m[0]; 305 this->value[1] -= m[1]; 306 return *this; 307 } 308 309 template <typename T, precision P> 310 template <typename U> 311 GLM_FUNC_QUALIFIER tmat2x3<T, P>& tmat2x3<T, P>::operator*= (U s) 312 { 313 this->value[0] *= s; 314 this->value[1] *= s; 315 return *this; 316 } 317 318 template <typename T, precision P> 319 template <typename U> 320 GLM_FUNC_QUALIFIER tmat2x3<T, P> & tmat2x3<T, P>::operator/= (U s) 321 { 322 this->value[0] /= s; 323 this->value[1] /= s; 324 return *this; 325 } 326 327 template <typename T, precision P> 328 GLM_FUNC_QUALIFIER tmat2x3<T, P> & tmat2x3<T, P>::operator++() 329 { 330 ++this->value[0]; 331 ++this->value[1]; 332 return *this; 333 } 334 335 template <typename T, precision P> 336 GLM_FUNC_QUALIFIER tmat2x3<T, P> & tmat2x3<T, P>::operator--() 337 { 338 --this->value[0]; 339 --this->value[1]; 340 return *this; 341 } 342 343 template <typename T, precision P> 344 GLM_FUNC_QUALIFIER tmat2x3<T, P> tmat2x3<T, P>::operator++(int) 345 { 346 tmat2x3<T, P> Result(*this); 347 ++*this; 348 return Result; 349 } 350 351 template <typename T, precision P> 352 GLM_FUNC_QUALIFIER tmat2x3<T, P> tmat2x3<T, P>::operator--(int) 353 { 354 tmat2x3<T, P> Result(*this); 355 --*this; 356 return Result; 357 } 358 359 ////////////////////////////////////////////////////////////// 360 // Binary operators 361 362 template <typename T, precision P> 363 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator+ 364 ( 365 tmat2x3<T, P> const & m, 366 T const & s 367 ) 368 { 369 return tmat2x3<T, P>( 370 m[0] + s, 371 m[1] + s); 372 } 373 374 template <typename T, precision P> 375 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator+ 376 ( 377 tmat2x3<T, P> const & m1, 378 tmat2x3<T, P> const & m2 379 ) 380 { 381 return tmat2x3<T, P>( 382 m1[0] + m2[0], 383 m1[1] + m2[1]); 384 } 385 386 template <typename T, precision P> 387 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator- 388 ( 389 tmat2x3<T, P> const & m, 390 T const & s 391 ) 392 { 393 return tmat2x3<T, P>( 394 m[0] - s, 395 m[1] - s); 396 } 397 398 template <typename T, precision P> 399 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator- 400 ( 401 tmat2x3<T, P> const & m1, 402 tmat2x3<T, P> const & m2 403 ) 404 { 405 return tmat2x3<T, P>( 406 m1[0] - m2[0], 407 m1[1] - m2[1]); 408 } 409 410 template <typename T, precision P> 411 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator* 412 ( 413 tmat2x3<T, P> const & m, 414 T const & s 415 ) 416 { 417 return tmat2x3<T, P>( 418 m[0] * s, 419 m[1] * s); 420 } 421 422 template <typename T, precision P> 423 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator* 424 ( 425 T const & s, 426 tmat2x3<T, P> const & m 427 ) 428 { 429 return tmat2x3<T, P>( 430 m[0] * s, 431 m[1] * s); 432 } 433 434 template <typename T, precision P> 435 GLM_FUNC_QUALIFIER typename tmat2x3<T, P>::col_type operator* 436 ( 437 tmat2x3<T, P> const & m, 438 typename tmat2x3<T, P>::row_type const & v) 439 { 440 return typename tmat2x3<T, P>::col_type( 441 m[0][0] * v.x + m[1][0] * v.y, 442 m[0][1] * v.x + m[1][1] * v.y, 443 m[0][2] * v.x + m[1][2] * v.y); 444 } 445 446 template <typename T, precision P> 447 GLM_FUNC_QUALIFIER typename tmat2x3<T, P>::row_type operator* 448 ( 449 typename tmat2x3<T, P>::col_type const & v, 450 tmat2x3<T, P> const & m) 451 { 452 return typename tmat2x3<T, P>::row_type( 453 v.x * m[0][0] + v.y * m[0][1] + v.z * m[0][2], 454 v.x * m[1][0] + v.y * m[1][1] + v.z * m[1][2]); 455 } 456 457 template <typename T, precision P> 458 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator* 459 ( 460 tmat2x3<T, P> const & m1, 461 tmat2x2<T, P> const & m2 462 ) 463 { 464 return tmat2x3<T, P>( 465 m1[0][0] * m2[0][0] + m1[1][0] * m2[0][1], 466 m1[0][1] * m2[0][0] + m1[1][1] * m2[0][1], 467 m1[0][2] * m2[0][0] + m1[1][2] * m2[0][1], 468 m1[0][0] * m2[1][0] + m1[1][0] * m2[1][1], 469 m1[0][1] * m2[1][0] + m1[1][1] * m2[1][1], 470 m1[0][2] * m2[1][0] + m1[1][2] * m2[1][1]); 471 } 472 473 template <typename T, precision P> 474 GLM_FUNC_QUALIFIER tmat3x3<T, P> operator* 475 ( 476 tmat2x3<T, P> const & m1, 477 tmat3x2<T, P> const & m2 478 ) 479 { 480 T SrcA00 = m1[0][0]; 481 T SrcA01 = m1[0][1]; 482 T SrcA02 = m1[0][2]; 483 T SrcA10 = m1[1][0]; 484 T SrcA11 = m1[1][1]; 485 T SrcA12 = m1[1][2]; 486 487 T SrcB00 = m2[0][0]; 488 T SrcB01 = m2[0][1]; 489 T SrcB10 = m2[1][0]; 490 T SrcB11 = m2[1][1]; 491 T SrcB20 = m2[2][0]; 492 T SrcB21 = m2[2][1]; 493 494 tmat3x3<T, P> Result(tmat3x3<T, P>::_null); 495 Result[0][0] = SrcA00 * SrcB00 + SrcA10 * SrcB01; 496 Result[0][1] = SrcA01 * SrcB00 + SrcA11 * SrcB01; 497 Result[0][2] = SrcA02 * SrcB00 + SrcA12 * SrcB01; 498 Result[1][0] = SrcA00 * SrcB10 + SrcA10 * SrcB11; 499 Result[1][1] = SrcA01 * SrcB10 + SrcA11 * SrcB11; 500 Result[1][2] = SrcA02 * SrcB10 + SrcA12 * SrcB11; 501 Result[2][0] = SrcA00 * SrcB20 + SrcA10 * SrcB21; 502 Result[2][1] = SrcA01 * SrcB20 + SrcA11 * SrcB21; 503 Result[2][2] = SrcA02 * SrcB20 + SrcA12 * SrcB21; 504 return Result; 505 } 506 507 template <typename T, precision P> 508 GLM_FUNC_QUALIFIER tmat4x3<T, P> operator* 509 ( 510 tmat2x3<T, P> const & m1, 511 tmat4x2<T, P> const & m2 512 ) 513 { 514 return tmat4x3<T, P>( 515 m1[0][0] * m2[0][0] + m1[1][0] * m2[0][1], 516 m1[0][1] * m2[0][0] + m1[1][1] * m2[0][1], 517 m1[0][2] * m2[0][0] + m1[1][2] * m2[0][1], 518 m1[0][0] * m2[1][0] + m1[1][0] * m2[1][1], 519 m1[0][1] * m2[1][0] + m1[1][1] * m2[1][1], 520 m1[0][2] * m2[1][0] + m1[1][2] * m2[1][1], 521 m1[0][0] * m2[2][0] + m1[1][0] * m2[2][1], 522 m1[0][1] * m2[2][0] + m1[1][1] * m2[2][1], 523 m1[0][2] * m2[2][0] + m1[1][2] * m2[2][1], 524 m1[0][0] * m2[3][0] + m1[1][0] * m2[3][1], 525 m1[0][1] * m2[3][0] + m1[1][1] * m2[3][1], 526 m1[0][2] * m2[3][0] + m1[1][2] * m2[3][1]); 527 } 528 529 template <typename T, precision P> 530 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator/ 531 ( 532 tmat2x3<T, P> const & m, 533 T const & s 534 ) 535 { 536 return tmat2x3<T, P>( 537 m[0] / s, 538 m[1] / s); 539 } 540 541 template <typename T, precision P> 542 GLM_FUNC_QUALIFIER tmat2x3<T, P> operator/ 543 ( 544 T const & s, 545 tmat2x3<T, P> const & m 546 ) 547 { 548 return tmat2x3<T, P>( 549 s / m[0], 550 s / m[1]); 551 } 552 553 // Unary constant operators 554 template <typename T, precision P> 555 GLM_FUNC_QUALIFIER tmat2x3<T, P> const operator- 556 ( 557 tmat2x3<T, P> const & m 558 ) 559 { 560 return tmat2x3<T, P>( 561 -m[0], 562 -m[1]); 563 } 564 565 ////////////////////////////////////// 566 // Boolean operators 567 568 template <typename T, precision P> 569 GLM_FUNC_QUALIFIER bool operator== 570 ( 571 tmat2x3<T, P> const & m1, 572 tmat2x3<T, P> const & m2 573 ) 574 { 575 return (m1[0] == m2[0]) && (m1[1] == m2[1]); 576 } 577 578 template <typename T, precision P> 579 GLM_FUNC_QUALIFIER bool operator!= 580 ( 581 tmat2x3<T, P> const & m1, 582 tmat2x3<T, P> const & m2 583 ) 584 { 585 return (m1[0] != m2[0]) || (m1[1] != m2[1]); 586 } 587} //namespace detail 588} //namespace glm 589