首页 > 解决方案 > 左上原点的 OpenTK 正交投影

问题描述

如何设置 openTK 以便获得正交投影,其中:

我目前有这个:

_projectionMatrix = Matrix4.CreateOrthographicOffCenter(
    ClientRectangle.X, ClientRectangle.Width,
    ClientRectangle.Y, ClientRectangle.Height, -1.0f, 1.0f);

我不能完全理解发生了什么,但似乎原点现在在左下角,我也不知道坐标是否与屏幕上的像素匹配。

标签: c#openglprojectionopentk

解决方案


的参数Matrix4.CreateOrthographicOffCenter是长方体视图体积的leftrightbottomtopnearfar

如果视图 ( ) 的原点ClientRectangle.Y必须位于顶部,则必须交换topandbottom参数:

_projectionMatrix = Matrix4.CreateOrthographicOffCenter(
    ClientRectangle.X, 
    ClientRectangle.X + ClientRectangle.Width,
    ClientRectangle.Y + ClientRectangle.Height, 
    ClientRectangle.Y,
    -1.0f, 1.0f);

推荐阅读