Home | History | Annotate | Download | only in gtx
      1 ///////////////////////////////////////////////////////////////////////////////////////////////////
      2 // OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
      3 ///////////////////////////////////////////////////////////////////////////////////////////////////
      4 // Created : 2005-02-28
      5 // Updated : 2005-04-23
      6 // Licence : This source is under MIT License
      7 // File : glm/gtx/transform2.inl
      8 ///////////////////////////////////////////////////////////////////////////////////////////////////
      9 
     10 namespace glm
     11 {
     12 	template <typename T, precision P>
     13 	GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> shearX2D(
     14 		const detail::tmat3x3<T, P>& m, 
     15 		T s)
     16 	{
     17 		detail::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 detail::tmat3x3<T, P> shearY2D(
     24 		const detail::tmat3x3<T, P>& m, 
     25 		T s)
     26 	{
     27 		detail::tmat3x3<T, P> r(1);
     28 		r[1][0] = s;
     29 		return m * r;
     30 	}
     31 
     32 	template <typename T, precision P>
     33 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> shearX3D(
     34 		const detail::tmat4x4<T, P>& m, 
     35 		T s, 
     36 		T t)
     37 	{
     38 		detail::tmat4x4<T, P> r(1);
     39 		r[1][0] = s;
     40 		r[2][0] = t;
     41 		return m * r;
     42 	}
     43 
     44 	template <typename T, precision P>
     45 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> shearY3D(
     46 		const detail::tmat4x4<T, P>& m, 
     47 		T s, 
     48 		T t)
     49 	{
     50 		detail::tmat4x4<T, P> r(1);
     51 		r[0][1] = s;
     52 		r[2][1] = t;
     53 		return m * r;
     54 	}
     55 
     56 	template <typename T, precision P>
     57 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> shearZ3D(
     58 		const detail::tmat4x4<T, P>& m, 
     59 		T s, 
     60 		T t)
     61 	{
     62 		detail::tmat4x4<T, P> r(1);
     63 		r[0][2] = s;
     64 		r[1][2] = t;
     65 		return m * r;
     66 	}
     67 
     68 	template <typename T, precision P>
     69 	GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> reflect2D(
     70 		const detail::tmat3x3<T, P>& m, 
     71 		const detail::tvec3<T, P>& normal)
     72 	{
     73 		detail::tmat3x3<T, P> r(1);
     74 		r[0][0] = 1 - 2 * normal.x * normal.x;
     75 		r[0][1] = -2 * normal.x * normal.y;
     76 		r[1][0] = -2 * normal.x * normal.y;
     77 		r[1][1] = 1 - 2 * normal.y * normal.y;
     78 		return m * r;
     79 	}
     80 
     81 	template <typename T, precision P>
     82 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> reflect3D(
     83 		const detail::tmat4x4<T, P>& m, 
     84 		const detail::tvec3<T, P>& normal)
     85 	{
     86 		detail::tmat4x4<T, P> r(1);
     87 		r[0][0] = 1 - 2 * normal.x * normal.x;
     88 		r[0][1] = -2 * normal.x * normal.y;
     89 		r[0][2] = -2 * normal.x * normal.z;
     90 
     91 		r[1][0] = -2 * normal.x * normal.y;
     92 		r[1][1] = 1 - 2 * normal.y * normal.y;
     93 		r[1][2] = -2 * normal.y * normal.z;
     94 
     95 		r[2][0] = -2 * normal.x * normal.z;
     96 		r[2][1] = -2 * normal.y * normal.z;
     97 		r[2][2] = 1 - 2 * normal.z * normal.z;
     98 		return m * r;
     99 	}
    100 
    101 	template <typename T, precision P>
    102 	GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> proj2D(
    103 		const detail::tmat3x3<T, P>& m, 
    104 		const detail::tvec3<T, P>& normal)
    105 	{
    106 		detail::tmat3x3<T, P> r(1);
    107 		r[0][0] = 1 - normal.x * normal.x;
    108 		r[0][1] = - normal.x * normal.y;
    109 		r[1][0] = - normal.x * normal.y;
    110 		r[1][1] = 1 - normal.y * normal.y;
    111 		return m * r;
    112 	}
    113 
    114 	template <typename T, precision P>
    115 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> proj3D(
    116 		const detail::tmat4x4<T, P>& m, 
    117 		const detail::tvec3<T, P>& normal)
    118 	{
    119 		detail::tmat4x4<T, P> r(1);
    120 		r[0][0] = 1 - normal.x * normal.x;
    121 		r[0][1] = - normal.x * normal.y;
    122 		r[0][2] = - normal.x * normal.z;
    123 		r[1][0] = - normal.x * normal.y;
    124 		r[1][1] = 1 - normal.y * normal.y;
    125 		r[1][2] = - normal.y * normal.z;
    126 		r[2][0] = - normal.x * normal.z;
    127 		r[2][1] = - normal.y * normal.z;
    128 		r[2][2] = 1 - normal.z * normal.z;
    129 		return m * r;
    130 	}
    131 
    132 	template <typename T, precision P>
    133 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> scaleBias(
    134 		T scale, 
    135 		T bias)
    136 	{
    137 		detail::tmat4x4<T, P> result;
    138 		result[3] = detail::tvec4<T, P>(detail::tvec3<T, P>(bias), T(1));
    139 		result[0][0] = scale;
    140 		result[1][1] = scale;
    141 		result[2][2] = scale;
    142 		return result;
    143 	}
    144 
    145 	template <typename T, precision P> 
    146 	GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> scaleBias(
    147 		const detail::tmat4x4<T, P>& m, 
    148 		T scale, 
    149 		T bias)
    150 	{
    151 		return m * scaleBias(scale, bias);
    152 	}
    153 }//namespace glm
    154 
    155