From e62817b8252974b8a98393275874ee303840bf13 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Fri, 12 May 2017 18:49:50 +0500 Subject: 2017-05-12 --- depedencies/include/glm/gtx/rotate_vector.inl | 188 ++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 depedencies/include/glm/gtx/rotate_vector.inl (limited to 'depedencies/include/glm/gtx/rotate_vector.inl') diff --git a/depedencies/include/glm/gtx/rotate_vector.inl b/depedencies/include/glm/gtx/rotate_vector.inl new file mode 100644 index 0000000..5620e96 --- /dev/null +++ b/depedencies/include/glm/gtx/rotate_vector.inl @@ -0,0 +1,188 @@ +/// @ref gtx_rotate_vector +/// @file glm/gtx/rotate_vector.inl + +namespace glm +{ + template + GLM_FUNC_QUALIFIER tvec3 slerp + ( + tvec3 const & x, + tvec3 const & y, + T const & a + ) + { + // get cosine of angle between vectors (-1 -> 1) + T CosAlpha = dot(x, y); + // get angle (0 -> pi) + T Alpha = acos(CosAlpha); + // get sine of angle between vectors (0 -> 1) + T SinAlpha = sin(Alpha); + // this breaks down when SinAlpha = 0, i.e. Alpha = 0 or pi + T t1 = sin((static_cast(1) - a) * Alpha) / SinAlpha; + T t2 = sin(a * Alpha) / SinAlpha; + + // interpolate src vectors + return x * t1 + y * t2; + } + + template + GLM_FUNC_QUALIFIER tvec2 rotate + ( + tvec2 const & v, + T const & angle + ) + { + tvec2 Result; + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.x = v.x * Cos - v.y * Sin; + Result.y = v.x * Sin + v.y * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec3 rotate + ( + tvec3 const & v, + T const & angle, + tvec3 const & normal + ) + { + return tmat3x3(glm::rotate(angle, normal)) * v; + } + /* + template + GLM_FUNC_QUALIFIER tvec3 rotateGTX( + const tvec3& x, + T angle, + const tvec3& normal) + { + const T Cos = cos(radians(angle)); + const T Sin = sin(radians(angle)); + return x * Cos + ((x * normal) * (T(1) - Cos)) * normal + cross(x, normal) * Sin; + } + */ + template + GLM_FUNC_QUALIFIER tvec4 rotate + ( + tvec4 const & v, + T const & angle, + tvec3 const & normal + ) + { + return rotate(angle, normal) * v; + } + + template + GLM_FUNC_QUALIFIER tvec3 rotateX + ( + tvec3 const & v, + T const & angle + ) + { + tvec3 Result(v); + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.y = v.y * Cos - v.z * Sin; + Result.z = v.y * Sin + v.z * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec3 rotateY + ( + tvec3 const & v, + T const & angle + ) + { + tvec3 Result = v; + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.x = v.x * Cos + v.z * Sin; + Result.z = -v.x * Sin + v.z * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec3 rotateZ + ( + tvec3 const & v, + T const & angle + ) + { + tvec3 Result = v; + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.x = v.x * Cos - v.y * Sin; + Result.y = v.x * Sin + v.y * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 rotateX + ( + tvec4 const & v, + T const & angle + ) + { + tvec4 Result = v; + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.y = v.y * Cos - v.z * Sin; + Result.z = v.y * Sin + v.z * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 rotateY + ( + tvec4 const & v, + T const & angle + ) + { + tvec4 Result = v; + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.x = v.x * Cos + v.z * Sin; + Result.z = -v.x * Sin + v.z * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tvec4 rotateZ + ( + tvec4 const & v, + T const & angle + ) + { + tvec4 Result = v; + T const Cos(cos(angle)); + T const Sin(sin(angle)); + + Result.x = v.x * Cos - v.y * Sin; + Result.y = v.x * Sin + v.y * Cos; + return Result; + } + + template + GLM_FUNC_QUALIFIER tmat4x4 orientation + ( + tvec3 const & Normal, + tvec3 const & Up + ) + { + if(all(equal(Normal, Up))) + return tmat4x4(T(1)); + + tvec3 RotationAxis = cross(Up, Normal); + T Angle = acos(dot(Normal, Up)); + + return rotate(Angle, RotationAxis); + } +}//namespace glm -- cgit v1.2.3