代码之家  ›  专栏  ›  技术社区  ›  Simiil

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

  •  1
  • Simiil  · 技术社区  · 16 年前

    我有一张平面图,就像我说的,还有一个等轴测视图的相机。现在当我在窗口中单击时,我想得到我在地图上单击的坐标。有什么帮助吗?

    1 回复  |  直到 16 年前
        1
  •  2
  •   Simiil    16 年前

    事实上,我知道了。

    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
    

    推荐文章