您好,我目前正在使用
Vector3 translation = new Vector3( tx, ty, tz);
GL.Translate(translation);
在 OpenTK 中转换对象的方式,其中 Vector3 值从 -1 到 1
我如何更改此设置并使可移动对象的值以像素方式进行可以根据用户的屏幕尺寸设置场景。
谢谢!
在旧版 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