gpt4 book ai didi

java - 等距 View 中类似鼠标的 RTS (LWJGL)

转载 作者:行者123 更新时间:2023-11-30 05:11:45 29 4
gpt4 key购买 nike

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

最佳答案

其实我已经明白了。

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 坐标,您就可以进行一些简单的 vector 计算和碰撞检测来获取您单击的点

关于java - 等距 View 中类似鼠标的 RTS (LWJGL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3140580/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com