二维平面只包含缩放和平移的模型矩阵
[ sx 0 0 tx ] ← X轴缩放(sx)与X轴平移(tx)
[ 0 sy 0 ty ] ← Y轴缩放(sy)与Y轴平移(ty)
[ 0 0 1 0 ] ← Z轴不缩放、不平移(保持1)
[ 0 0 0 1 ] ← 齐次坐标标识(固定为1)二维平面包含缩放、旋转和平移的模型矩阵
[ sx·cosθ -sy·sinθ 0 tx ]
[ sx·sinθ sy·cosθ 0 ty ]
[ 0 0 1 0 ]
[ 0 0 0 1 ]二维平面视口大小与窗口大小一致,生成投影矩阵
// 创建二维正交投影矩阵
Matrix4 projectionMatrix = Matrix4.CreateOrthographicOffCenter(
left: 0, // X轴最小值(对应屏幕左边缘)
right: windowWidth, // X轴最大值(对应屏幕右边缘)
bottom: windowHeight, // Y轴最小值(对应屏幕下边缘,注意翻转)
top: 0, // Y轴最大值(对应屏幕上边缘,注意翻转)
zNear: -1, // 近平面(Z轴可见范围起点)
zFar: 1 // 远平面(Z轴可见范围终点)
);对应的4×4 投影矩阵结构如下:
[ 2/windowWidth 0 0 -(windowWidth)/(windowWidth) ]
[ 0 -2/windowHeight 0 (windowHeight)/(windowHeight) ]
[ 0 0 -2/(1+1) 0 ]
[ 0 0 0 1 ]简化后核心作用:
[0, windowWidth] 映射到标准化设备坐标(NDC)的 [-1, 1][0, windowHeight] 映射到标准化设备坐标(NDC)的 [1, -1](实现 Y 轴翻转)[0] 映射到 NDC 的 [0](二维场景无需深度变化)bottom = windowHeight 和 top = 0 实现翻转。OnResize 事件中更新)。GL.Viewport(0, 0, windowWidth, windowHeight)),否则投影会出现拉伸。原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。