【问题标题】:OpenTK orthographic projection with left top origin左上原点的 OpenTK 正交投影
【发布时间】:2019-12-01 15:50:02
【问题描述】:

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

  • 原点在屏幕左上角
  • 我可以使用“正常”像素坐标,例如:如果我的窗口是 500 X 400,那么:
    • 0,0 是左上角
    • 500,0 是右上角
    • 500,400 是右下角
    • 0,400 是左下角

我现在有这个:

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

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

【问题讨论】:

    标签: c# opengl projection opentk


    【解决方案1】:

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

    如果视图的原点 (ClientRectangle.Y) 必须在顶部,那么您必须交换 topbottom 参数:

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

    【讨论】:

    • 成功了!除了我的文本现在是颠倒的事实之外:imgur.com/a/gvLdwFo 文本是使用 QuickFont 呈现的。有什么想法吗?
    • 当然文字是颠倒的。那是你想做的。改变之前,原点在底部,y方向向上。现在原点在顶部,y 方向向下。您必须更改文本渲染以弥补这一点。
    猜你喜欢
    • 2012-11-04
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 2023-03-03
    • 2011-11-25
    • 2013-01-22
    • 2015-03-07
    • 1970-01-01
    相关资源
    最近更新 更多