如何从 GLUT 坐标转换为窗口坐标
How to convert from GLUT coordinates to window coordinates
可能的重复项:
过剩鼠标坐标
假设我有一个 600x600 的窗口。
当我收到鼠标事件时,我不知道鼠标的真实位置是什么,在 OpenGL 中,我使用它来绘制点:
(-0.5,0.5) | (0.5,0.5)
|
--------(0,0)-------
|
|
(-0.5,-0.5) | (0.5,-0.5)
但是当我收到取决于窗口大小的 GLUT 鼠标事件时,我会得到不同的坐标。我想要一个相对(到窗口)坐标系。我怎么得到这个?
我很确定 glut 会给你窗口空间中的鼠标坐标(即,如果窗口是 800x600 并且鼠标位置在中间,它会给你 x:400, y: 300),所以如果你想把它带到你上面发布的 opengl 空间,你会执行以下操作:
float x = (400 / 800) - 0.5f; //0.0
float y = (300 / 600) - 0.5f; //0.0
所以通用版本看起来像这样:
float mouseX = (theGlutMouseXCoordinate / theGlutWindowWidth) - 0.5f;
float mouseY = (theGlutMouseYCoordinate / theGlutWindowHeight) - 0.5f;
也许我误读了你的问题,或者过度简化了答案,但你不只是在寻找这样的东西吗:
float x = mouse.x / screen.width; //x now in [0,1]
float y = mouse.y / screen.height; //y now in [0,1]
x-=0.5f;
y-=0.5f;
或颠倒:
float wx = (x + 0.5f) * screen.width;
float wy = (Y + 0.5f) * screen.height;
相关文章:
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 在 OpenGL 中将笛卡尔世界坐标转换为球面局部坐标
- 如何将鼠标坐标转换为"mm"
- 如何将 QTabWidget 坐标转换为其子坐标?
- 将 2D 图像坐标转换为 z = 0 的 3D 世界坐标
- 如何将世界坐标转换为相机图像坐标
- 将鼠标坐标转换为世界空间坐标
- 将画布坐标转换为外部微件的坐标
- 将 2D 屏幕坐标转换为 3D 世界坐标
- 如何将像素坐标转换为世界坐标
- 如何从 GLUT 坐标转换为窗口坐标
- 将点云的坐标转换为点云库中的另一个坐标,从而使地平面成为X-O-Y平面?
- 将 X Y 坐标转换为拉特长等距柱状投影C++
- 将 3D 坐标转换为 3ds 中的 2D 最大值
- 将屏幕鼠标坐标转换为窗口坐标
- Opengl 屏幕到地图坐标转换
- 在 OpenGL 中将 3D 坐标转换为屏幕坐标
- 将双点坐标转换为字符串
- gluUnProject试图将鼠标坐标转换为opengl坐标的奇怪行为
- 从视口坐标转换为[-1,1]^2顶点[ENGGL]