在 OpenTK 中翻译对象

本文关键字:对象 翻译 OpenTK | 更新日期: 2023-09-27 18:34:57

您好,我目前正在使用

 Vector3 translation = new Vector3( tx, ty, tz);
        GL.Translate(translation);

OpenTK 中转换对象的方式,其中 Vector3 值从 -1 到 1

我如何更改此设置并使可移动对象的值以像素方式进行可以根据用户的屏幕尺寸设置场景。

谢谢!

在 OpenTK 中翻译对象

在旧版 OpenGL 1.x 中,您可以通过使用 GL 设置正交投影来实现此目的。邻:

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, Width, Height, 0, -1, 1);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Translate(1.0f, 0, 0); // translates by 1 pixel

请注意,这将使您的应用程序难以移植到高分辨率 (4K( 显示器。如果可能的话,我建议使用与决议无关的方法。例如:

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1, 1, 1, -1, -1, 1);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Translate(1.0f / Width, 0, 0); // translates by 1 pixel