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