【问题标题】:RTS like Mouse in an isometric view (LWJGL)等轴测视图中的类似鼠标的 RTS (LWJGL)
【发布时间】:2010-06-29 12:29:55
【问题描述】:

我在等轴测视图中的鼠标点击确实存在问题。 简单地说,我有一张平面地图,而且,就像我说的,有一个等距视图中的相机。现在,当我在窗口中单击时,我想获取我在地图上单击的坐标。有什么帮助吗?

【问题讨论】:

    标签: java mouse lwjgl isometric


    【解决方案1】:

    其实,我想通了。

    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 坐标,你可以做一些简单的矢量计算和碰撞检测来得到你点击的点

    【讨论】:

    • 您不需要使用 glReadPixels,只要假设 Z 分量为 0.5 左右(即在近剪辑平面和远剪辑平面之间的中间),您就会得到相同的结果。跨度>
    猜你喜欢
    • 2014-06-18
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多