简体   繁体   English

在OpenTK中翻译对象

[英]Translating Object in OpenTK

Hello I'm currently using the 您好,我目前正在使用

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

Way of translating an object in OpenTK where the Vector3 values are from -1 to 1 在Vector3值从-1到1的OpenTK中转换对象的方式

How do I change this and make the values of a movable object to go pixel wise that way I can set up a scene based on the user's screen size. 如何更改此设置,并使可移动对象的值朝像素方向移动,以便可以根据用户的屏幕尺寸设置场景。

Thanks! 谢谢!

In legacy OpenGL 1.x, you can achieve this by setting up an orthographic projection with GL.Ortho : 在旧版OpenGL 1.x中,您可以通过使用GL.Ortho设置正交投影来实现

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

Be forewarned that this will make your application difficult to port to high-resolution (4K) monitors. 请注意,这将使您的应用程序难以移植到高分辨率(4K)显示器。 I would advise using a resolution-independent approach if at all possible. 我建议尽可能使用与分辨率无关的方法。 For example: 例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM