Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

c# - 左上原点的OpenTK正交投影(OpenTK orthographic projection with left top origin)

How do I setup openTK so I get a orthographic projection where:

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

  • The origin is in the top left corner of the screen

    (原点在屏幕的左上角)

  • I can use "normal" pixel coordinates, for instance: if my window is 500 X 400 then:

    (我可以使用“正常”像素坐标,例如:如果我的窗口是500 X 400,则:)

    • 0,0 is the top left corner

      (0,0是左上角)

    • 500,0 is the top right corner

      (500,0是右上角)

    • 500,400 is the bottom right corner

      (500,400是右下角)

    • 0,400 is the bottom left corner

      (0,400是左下角)

I currenly have this:

(我目前有这个:)

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

I'm not fully able to understand what's happening but is seems the origin is now in the bottom left, also I don't know if the coordinates match with the pixels on screen.

(我无法完全理解正在发生的事情,但似乎原点现在位于左下角,而且我也不知道坐标是否与屏幕上的像素匹配。)

  ask by lsie translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The parameters to Matrix4.CreateOrthographicOffCenter are the left , right , bottom , top , near , and far of the cuboid view volume.

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

If the origin of the view ( ClientRectangle.Y ) has to be at the top, then you've to swap the top and bottom parameter:

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...