等距视图中类似鼠标的 RTS (LWJGL)

发布于 2024-09-07 15:23:12 字数 92 浏览 10 评论 0原文

我确实对等距视图中的鼠标点击有疑问。 简而言之,我有一张平面地图,就像我说的,有一个等距视图的相机。现在,当我单击窗口时,我想获取我在地图上单击的位置的坐标。有帮助吗?

I really have an issue with mouseclicks in an isometric view.
Simply i have a flat map, and, like i said, a camera in an isometric view. Now when i click in the window i want to get the Coordinates where i clicked on the map. Any Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2024-09-14 15:23:12

事实上,我想通了。

int winX = ...  //the x coordinate of the Click, given Parameter
int winY = ... //the y Coordinate of the Click, given Parameter
FloatBuffer winZ = BufferUtils.createFloatBuffer(1); //the x coordinate of the click, will be calculated
FloatBuffer pos = BufferUtils.createFloatBuffer(3); // the final position of the click
FloatBuffer modelview = BufferUtils.createFloatBuffer(16); 
FloatBuffer projection = BufferUtils.createFloatBuffer(16); 
IntBuffer viewport = BufferUtils.createIntBuffer(16); 

GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat(GL11.GL_PROJECTIONMATRIX, projection);

GL11.glReadPixels(winX, winY, 1,1, GL11._GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ) //calculate the Z Coordinate of the Click
GLU.gluUnProject((float)(winX), (float)(winY), (float)(winZ.get(0)), modelview, projection, viewport, pos); //Calculating the 3D Position of the click, saved in pos

现在,既然您有了 3D 坐标,您就可以进行一些简单的矢量计算和碰撞检测来获取您单击的点

actually, i figured it out.

int winX = ...  //the x coordinate of the Click, given Parameter
int winY = ... //the y Coordinate of the Click, given Parameter
FloatBuffer winZ = BufferUtils.createFloatBuffer(1); //the x coordinate of the click, will be calculated
FloatBuffer pos = BufferUtils.createFloatBuffer(3); // the final position of the click
FloatBuffer modelview = BufferUtils.createFloatBuffer(16); 
FloatBuffer projection = BufferUtils.createFloatBuffer(16); 
IntBuffer viewport = BufferUtils.createIntBuffer(16); 

GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat(GL11.GL_PROJECTIONMATRIX, projection);

GL11.glReadPixels(winX, winY, 1,1, GL11._GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ) //calculate the Z Coordinate of the Click
GLU.gluUnProject((float)(winX), (float)(winY), (float)(winZ.get(0)), modelview, projection, viewport, pos); //Calculating the 3D Position of the click, saved in pos

Now since you have the 3D Coordinates you can do some simple vector calculation and collision detection to get the point you clicked on

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文