1/////////////////////////////////////////////////////////////////////////////////////////////////// 2// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net) 3/////////////////////////////////////////////////////////////////////////////////////////////////// 4// Created : 2005-12-21 5// Updated : 2007-08-14 6// Licence : This source is under MIT License 7// File : glm/gtx/euler_angles.inl 8/////////////////////////////////////////////////////////////////////////////////////////////////// 9 10namespace glm 11{ 12 template <typename T> 13 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleX 14 ( 15 T const & angleX 16 ) 17 { 18 T cosX = glm::cos(angleX); 19 T sinX = glm::sin(angleX); 20 21 return detail::tmat4x4<T, defaultp>( 22 T(1), T(0), T(0), T(0), 23 T(0), cosX, sinX, T(0), 24 T(0),-sinX, cosX, T(0), 25 T(0), T(0), T(0), T(1)); 26 } 27 28 template <typename T> 29 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleY 30 ( 31 T const & angleY 32 ) 33 { 34 T cosY = glm::cos(angleY); 35 T sinY = glm::sin(angleY); 36 37 return detail::tmat4x4<T, defaultp>( 38 cosY, T(0), -sinY, T(0), 39 T(0), T(1), T(0), T(0), 40 sinY, T(0), cosY, T(0), 41 T(0), T(0), T(0), T(1)); 42 } 43 44 template <typename T> 45 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleZ 46 ( 47 T const & angleZ 48 ) 49 { 50 T cosZ = glm::cos(angleZ); 51 T sinZ = glm::sin(angleZ); 52 53 return detail::tmat4x4<T, defaultp>( 54 cosZ, sinZ, T(0), T(0), 55 -sinZ, cosZ, T(0), T(0), 56 T(0), T(0), T(1), T(0), 57 T(0), T(0), T(0), T(1)); 58 } 59 60 template <typename T> 61 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleXY 62 ( 63 T const & angleX, 64 T const & angleY 65 ) 66 { 67 T cosX = glm::cos(angleX); 68 T sinX = glm::sin(angleX); 69 T cosY = glm::cos(angleY); 70 T sinY = glm::sin(angleY); 71 72 return detail::tmat4x4<T, defaultp>( 73 cosY, -sinX * -sinY, cosX * -sinY, T(0), 74 T(0), cosX, sinX, T(0), 75 sinY, -sinX * cosY, cosX * cosY, T(0), 76 T(0), T(0), T(0), T(1)); 77 } 78 79 template <typename T> 80 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleYX 81 ( 82 T const & angleY, 83 T const & angleX 84 ) 85 { 86 T cosX = glm::cos(angleX); 87 T sinX = glm::sin(angleX); 88 T cosY = glm::cos(angleY); 89 T sinY = glm::sin(angleY); 90 91 return detail::tmat4x4<T, defaultp>( 92 cosY, 0, -sinY, T(0), 93 sinY * sinX, cosX, cosY * sinX, T(0), 94 sinY * cosX, -sinX, cosY * cosX, T(0), 95 T(0), T(0), T(0), T(1)); 96 } 97 98 template <typename T> 99 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleXZ 100 ( 101 T const & angleX, 102 T const & angleZ 103 ) 104 { 105 return eulerAngleX(angleX) * eulerAngleZ(angleZ); 106 } 107 108 template <typename T> 109 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleZX 110 ( 111 T const & angleZ, 112 T const & angleX 113 ) 114 { 115 return eulerAngleZ(angleZ) * eulerAngleX(angleX); 116 } 117 118 template <typename T> 119 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleYZ 120 ( 121 T const & angleY, 122 T const & angleZ 123 ) 124 { 125 return eulerAngleY(angleY) * eulerAngleZ(angleZ); 126 } 127 128 template <typename T> 129 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleZY 130 ( 131 T const & angleZ, 132 T const & angleY 133 ) 134 { 135 return eulerAngleZ(angleZ) * eulerAngleY(angleY); 136 } 137 138 template <typename T> 139 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> eulerAngleYXZ 140 ( 141 T const & yaw, 142 T const & pitch, 143 T const & roll 144 ) 145 { 146 T tmp_ch = glm::cos(yaw); 147 T tmp_sh = glm::sin(yaw); 148 T tmp_cp = glm::cos(pitch); 149 T tmp_sp = glm::sin(pitch); 150 T tmp_cb = glm::cos(roll); 151 T tmp_sb = glm::sin(roll); 152 153 detail::tmat4x4<T, defaultp> Result; 154 Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb; 155 Result[0][1] = tmp_sb * tmp_cp; 156 Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb; 157 Result[0][3] = static_cast<T>(0); 158 Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb; 159 Result[1][1] = tmp_cb * tmp_cp; 160 Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb; 161 Result[1][3] = static_cast<T>(0); 162 Result[2][0] = tmp_sh * tmp_cp; 163 Result[2][1] = -tmp_sp; 164 Result[2][2] = tmp_ch * tmp_cp; 165 Result[2][3] = static_cast<T>(0); 166 Result[3][0] = static_cast<T>(0); 167 Result[3][1] = static_cast<T>(0); 168 Result[3][2] = static_cast<T>(0); 169 Result[3][3] = static_cast<T>(1); 170 return Result; 171 } 172 173 template <typename T> 174 GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> yawPitchRoll 175 ( 176 T const & yaw, 177 T const & pitch, 178 T const & roll 179 ) 180 { 181 T tmp_ch = glm::cos(yaw); 182 T tmp_sh = glm::sin(yaw); 183 T tmp_cp = glm::cos(pitch); 184 T tmp_sp = glm::sin(pitch); 185 T tmp_cb = glm::cos(roll); 186 T tmp_sb = glm::sin(roll); 187 188 detail::tmat4x4<T, defaultp> Result; 189 Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb; 190 Result[0][1] = tmp_sb * tmp_cp; 191 Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb; 192 Result[0][3] = static_cast<T>(0); 193 Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb; 194 Result[1][1] = tmp_cb * tmp_cp; 195 Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb; 196 Result[1][3] = static_cast<T>(0); 197 Result[2][0] = tmp_sh * tmp_cp; 198 Result[2][1] = -tmp_sp; 199 Result[2][2] = tmp_ch * tmp_cp; 200 Result[2][3] = static_cast<T>(0); 201 Result[3][0] = static_cast<T>(0); 202 Result[3][1] = static_cast<T>(0); 203 Result[3][2] = static_cast<T>(0); 204 Result[3][3] = static_cast<T>(1); 205 return Result; 206 } 207 208 template <typename T> 209 GLM_FUNC_QUALIFIER detail::tmat2x2<T, defaultp> orientate2 210 ( 211 T const & angle 212 ) 213 { 214 T c = glm::cos(angle); 215 T s = glm::sin(angle); 216 217 detail::tmat2x2<T, defaultp> Result; 218 Result[0][0] = c; 219 Result[0][1] = s; 220 Result[1][0] = -s; 221 Result[1][1] = c; 222 return Result; 223 } 224 225 template <typename T> 226 GLM_FUNC_QUALIFIER detail::tmat3x3<T, defaultp> orientate3 227 ( 228 T const & angle 229 ) 230 { 231 T c = glm::cos(angle); 232 T s = glm::sin(angle); 233 234 detail::tmat3x3<T, defaultp> Result; 235 Result[0][0] = c; 236 Result[0][1] = s; 237 Result[0][2] = 0.0f; 238 Result[1][0] = -s; 239 Result[1][1] = c; 240 Result[1][2] = 0.0f; 241 Result[2][0] = 0.0f; 242 Result[2][1] = 0.0f; 243 Result[2][2] = 1.0f; 244 return Result; 245 } 246 247 template <typename T, precision P> 248 GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> orientate3 249 ( 250 detail::tvec3<T, P> const & angles 251 ) 252 { 253 return detail::tmat3x3<T, P>(yawPitchRoll(angles.x, angles.y, angles.z)); 254 } 255 256 template <typename T, precision P> 257 GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> orientate4 258 ( 259 detail::tvec3<T, P> const & angles 260 ) 261 { 262 return yawPitchRoll(angles.z, angles.x, angles.y); 263 } 264}//namespace glm 265