OpenGL坐标变换



我有一个大小为(475574)的窗口。当我使用鼠标点击事件获取屏幕上的位置时我在(0-475,0-574)的范围内。我正在使用glOrthof(-1.5、+1.5、-1.5、+15.0、4.0、15.0)所以我的问题是如何将鼠标事件中的点转换为3DopenGL点。

例如-我将如何将(100200)转换为(-1.2,0.234,6)

您需要在两个坐标系之间进行转换,才能将屏幕坐标转换为世界坐标。

//calculate ratio
widthRatio = 3.0 / width; // 3.0 = total width of viewport
heightRatio = 3.0 / height; // 3.0 = total height of viewport
worldX = (screenX * widthRatio) - 1.5; // subtract 1.5 (half of viewport width) to get origin
worldY = (screenY * heightRatio) - 1.5;

worldX和worldY现在应该是视口中的适当点。

最新更新