简体   繁体   中英

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

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 :

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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