• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/// @ref gtx_transform2
2/// @file glm/gtx/transform2.inl
3
4namespace glm
5{
6	template <typename T, precision P>
7	GLM_FUNC_QUALIFIER tmat3x3<T, P> shearX2D(tmat3x3<T, P> const& m, T s)
8	{
9		tmat3x3<T, P> r(1);
10		r[1][0] = s;
11		return m * r;
12	}
13
14	template <typename T, precision P>
15	GLM_FUNC_QUALIFIER tmat3x3<T, P> shearY2D(tmat3x3<T, P> const& m, T s)
16	{
17		tmat3x3<T, P> r(1);
18		r[0][1] = s;
19		return m * r;
20	}
21
22	template <typename T, precision P>
23	GLM_FUNC_QUALIFIER tmat4x4<T, P> shearX3D(tmat4x4<T, P> const& m, T s, T t)
24	{
25		tmat4x4<T, P> r(1);
26		r[0][1] = s;
27		r[0][2] = t;
28		return m * r;
29	}
30
31	template <typename T, precision P>
32	GLM_FUNC_QUALIFIER tmat4x4<T, P> shearY3D(tmat4x4<T, P> const& m, T s, T t)
33	{
34		tmat4x4<T, P> r(1);
35		r[1][0] = s;
36		r[1][2] = t;
37		return m * r;
38	}
39
40	template <typename T, precision P>
41	GLM_FUNC_QUALIFIER tmat4x4<T, P> shearZ3D(tmat4x4<T, P> const& m, T s, T t)
42	{
43		tmat4x4<T, P> r(1);
44		r[2][0] = s;
45		r[2][1] = t;
46		return m * r;
47	}
48
49	template <typename T, precision P>
50	GLM_FUNC_QUALIFIER tmat3x3<T, P> reflect2D(tmat3x3<T, P> const& m, tvec3<T, P> const& normal)
51	{
52		tmat3x3<T, P> r(static_cast<T>(1));
53		r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
54		r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
55		r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
56		r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
57		return m * r;
58	}
59
60	template <typename T, precision P>
61	GLM_FUNC_QUALIFIER tmat4x4<T, P> reflect3D(tmat4x4<T, P> const& m, tvec3<T, P> const& normal)
62	{
63		tmat4x4<T, P> r(static_cast<T>(1));
64		r[0][0] = static_cast<T>(1) - static_cast<T>(2) * normal.x * normal.x;
65		r[0][1] = -static_cast<T>(2) * normal.x * normal.y;
66		r[0][2] = -static_cast<T>(2) * normal.x * normal.z;
67
68		r[1][0] = -static_cast<T>(2) * normal.x * normal.y;
69		r[1][1] = static_cast<T>(1) - static_cast<T>(2) * normal.y * normal.y;
70		r[1][2] = -static_cast<T>(2) * normal.y * normal.z;
71
72		r[2][0] = -static_cast<T>(2) * normal.x * normal.z;
73		r[2][1] = -static_cast<T>(2) * normal.y * normal.z;
74		r[2][2] = static_cast<T>(1) - static_cast<T>(2) * normal.z * normal.z;
75		return m * r;
76	}
77
78	template <typename T, precision P>
79	GLM_FUNC_QUALIFIER tmat3x3<T, P> proj2D(
80		const tmat3x3<T, P>& m,
81		const tvec3<T, P>& normal)
82	{
83		tmat3x3<T, P> r(static_cast<T>(1));
84		r[0][0] = static_cast<T>(1) - normal.x * normal.x;
85		r[0][1] = - normal.x * normal.y;
86		r[1][0] = - normal.x * normal.y;
87		r[1][1] = static_cast<T>(1) - normal.y * normal.y;
88		return m * r;
89	}
90
91	template <typename T, precision P>
92	GLM_FUNC_QUALIFIER tmat4x4<T, P> proj3D(
93		const tmat4x4<T, P>& m,
94		const tvec3<T, P>& normal)
95	{
96		tmat4x4<T, P> r(static_cast<T>(1));
97		r[0][0] = static_cast<T>(1) - normal.x * normal.x;
98		r[0][1] = - normal.x * normal.y;
99		r[0][2] = - normal.x * normal.z;
100		r[1][0] = - normal.x * normal.y;
101		r[1][1] = static_cast<T>(1) - normal.y * normal.y;
102		r[1][2] = - normal.y * normal.z;
103		r[2][0] = - normal.x * normal.z;
104		r[2][1] = - normal.y * normal.z;
105		r[2][2] = static_cast<T>(1) - normal.z * normal.z;
106		return m * r;
107	}
108
109	template <typename T, precision P>
110	GLM_FUNC_QUALIFIER tmat4x4<T, P> scaleBias(T scale, T bias)
111	{
112		tmat4x4<T, P> result;
113		result[3] = tvec4<T, P>(tvec3<T, P>(bias), static_cast<T>(1));
114		result[0][0] = scale;
115		result[1][1] = scale;
116		result[2][2] = scale;
117		return result;
118	}
119
120	template <typename T, precision P>
121	GLM_FUNC_QUALIFIER tmat4x4<T, P> scaleBias(tmat4x4<T, P> const& m, T scale, T bias)
122	{
123		return m * scaleBias(scale, bias);
124	}
125}//namespace glm
126
127