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