UE4 OpenGL坐标系
生活随笔
收集整理的這篇文章主要介紹了
UE4 OpenGL坐标系
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
UE4 & OpenGL坐標系
UE4 使用左手系(DX),OpenGL固定管線使用右手系,可以通過可編程的管線在OpenGL渲染管線中使用和UE4一樣的左手系,即修改觀察矩陣和投影矩陣。WebGL屬于可編程的管線,可以使用左手和右手系。
三維空間的坐標系
- 局部空間(Local Space,或者稱為物體空間(Object Space))
- 世界空間(World Space)
- 觀察空間(View Space,或者稱為視覺空間(Eye Space)) 或是視圖坐標系
- 裁剪空間(Clip Space) 或是投影坐標系
- 歸一化設備坐標系(Normalized device coordinates)
- 屏幕空間(Screen Space)
左右手坐標系變換在裁剪空間和觀察空間進行。
GLM
GLM更改默認的慣用手,使用GLM FORCE LEFT handled。若要更改默認的“近剪裁平面”和“遠剪裁平面”定義,請使用GLM FORCE DEPTH ZERO To ONE。
使用D3D坐標系。
#define GLM_FORCE_LEFT_HANDED #define GLM_FORCE_DEPTH_ZERO_TO_ONE投影坐標系
正射投影矩陣
右手系-正射投影矩陣
template<typename T>GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_NO(T left, T right, T bottom, T top, T zNear, T zFar){mat<4, 4, T, defaultp> Result(1);Result[0][0] = static_cast<T>(2) / (right - left);Result[1][1] = static_cast<T>(2) / (top - bottom);Result[2][2] = - static_cast<T>(2) / (zFar - zNear);Result[3][0] = - (right + left) / (right - left);Result[3][1] = - (top + bottom) / (top - bottom);Result[3][2] = - (zFar + zNear) / (zFar - zNear);return Result;}左手系-正射投影矩陣
template<typename T>GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_ZO(T left, T right, T bottom, T top, T zNear, T zFar){mat<4, 4, T, defaultp> Result(1);Result[0][0] = static_cast<T>(2) / (right - left);Result[1][1] = static_cast<T>(2) / (top - bottom);Result[2][2] = static_cast<T>(1) / (zFar - zNear);Result[3][0] = - (right + left) / (right - left);Result[3][1] = - (top + bottom) / (top - bottom);Result[3][2] = - zNear / (zFar - zNear);return Result;}透視投影
右手系-透視投影
左手系-透視投影
視圖坐標系
//右手系 template<typename T, qualifier Q>GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAtRH(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up){//forward:Wvec<3, T, Q> const f(normalize(center - eye));//right:Vvec<3, T, Q> const s(normalize(cross(f, up)));//up:Uvec<3, T, Q> const u(cross(s, f));mat<4, 4, T, Q> Result(1);Result[0][0] = s.x;Result[1][0] = s.y;Result[2][0] = s.z;Result[0][1] = u.x;Result[1][1] = u.y;Result[2][1] = u.z;Result[0][2] =-f.x;Result[1][2] =-f.y;Result[2][2] =-f.z;Result[3][0] =-dot(s, eye);Result[3][1] =-dot(u, eye);Result[3][2] = dot(f, eye);return Result;}//左手系template<typename T, qualifier Q>GLM_FUNC_QUALIFIER mat<4, 4, T, Q> lookAtLH(vec<3, T, Q> const& eye, vec<3, T, Q> const& center, vec<3, T, Q> const& up){vec<3, T, Q> const f(normalize(center - eye));vec<3, T, Q> const s(normalize(cross(up, f)));vec<3, T, Q> const u(cross(f, s));mat<4, 4, T, Q> Result(1);Result[0][0] = s.x;Result[1][0] = s.y;Result[2][0] = s.z;Result[0][1] = u.x;Result[1][1] = u.y;Result[2][1] = u.z;Result[0][2] = f.x;Result[1][2] = f.y;Result[2][2] = f.z;Result[3][0] = -dot(s, eye);Result[3][1] = -dot(u, eye);Result[3][2] = -dot(f, eye);return Result;}參考文章
總結(jié)
以上是生活随笔為你收集整理的UE4 OpenGL坐标系的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 监听浏览器刷新操作
- 下一篇: OpenGL学习---1.1 OpenG