public void Map_to_Space(int x, int y) { unsafe { double *modelview = stackalloc double[16]; double *projection = stackalloc double[16]; int * viewport = stackalloc int[16]; PO pn, pf; pn = new PO(); pf = new PO(); GLU.glGetDoublev(GLU.GL_MODELVIEW_MATRIX, modelview); GLU.glGetDoublev(GLU.GL_PROJECTION_MATRIX, projection); GLU.glGetIntegerv(GLU.GL_VIEWPORT, viewport); double world_x, world_y, world_z; GLU.gluUnProject((double)x, (double)y, 0.0, modelview, projection, viewport, &world_x, &world_y, &world_z); pn.x = (float)world_x; pn.y = (float)world_y; pn.z = (float)world_z; GLU.gluUnProject((double)x, (double)y, 1.0, modelview, projection, viewport, &world_x, &world_y, &world_z); pf.x = (float)world_x; pf.y = (float)world_y; pf.z = (float)world_z; ll.Insert(new LINE(pn, pf)); } }
public PO Map_to_Space(int x, int y) { util u1 = new util(); unsafe { double *modelview = stackalloc double[16]; double *projection = stackalloc double[16]; int * viewport = stackalloc int[4]; PO pf; double z; pf = new PO(); GLU.glGetDoublev(GLU.GL_MODELVIEW_MATRIX, modelview); GLU.glGetDoublev(GLU.GL_PROJECTION_MATRIX, projection); GLU.glGetIntegerv(GLU.GL_VIEWPORT, viewport); GLU.glReadPixels(x, y, 1, 1, GLU.GL_DEPTH_COMPONENT, GLU.GL_FLOAT, &z); double world_x, world_y, world_z; GLU.gluUnProject((double)x, (double)(viewport[3] - y - 1), 1, modelview, projection, viewport, &world_x, &world_y, &world_z); pf.x = (float)world_x; pf.y = (float)world_y; pf.z = 0; return(pf); } }