Advertisement
Guest User

Untitled

a guest
May 23rd, 2012
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. private void createMouseRay(GL2 gl, int x, int y) {
  2.  
  3.     int viewport[] = new int[4];
  4.     double modelview[] = new double[16];
  5.     double projection[] = new double[16];
  6.     double rayStartPos[] = new double[4];
  7.     double rayEndPos[] = new double[4];
  8.  
  9.     gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelview, 0);
  10.     gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection, 0);
  11.     gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0);
  12.  
  13.     int vpheight = viewport[3];
  14.  
  15.     int wx = x;
  16.     int wy = vpheight - y;
  17.  
  18.     GLU.createGLU(gl).gluUnProject(wx, wy, 0.0,
  19.             modelview, 0,
  20.             projection, 0,
  21.             viewport, 0,
  22.             rayStartPos, 0);
  23.     GLU.createGLU(gl).gluUnProject(wx, wy, 1.0,
  24.             modelview, 0,
  25.             projection, 0,
  26.             viewport, 0,
  27.             rayEndPos, 0);
  28.  
  29.     mouseRayStart = new Vector3(rayStartPos[0], rayStartPos[1], rayStartPos[2]);
  30.     mouseRayEnd = new Vector3(rayEndPos[0], rayEndPos[1], rayEndPos[2]);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement