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