Hello All,
I’m working on drawing a dynamic line for a sample JOGL application. In my application there are a number of boxes, once one is selected you are able to draw line from that box that follows the mouse point anywhere on screen. The problem I am having is that whenever I rotate the screen my line starts plotting odd coordinates. Im sure there is something im not taking into account once I rotate but I could use some help determining what that is. Sample code below. Im using gluUnProject to convert my coordinates
int[] viewport = new int[4];
openGLContext.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
double mvmatrix[] = new double[16];
openGLContext.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
double projmatrix[] = new double[16];
openGLContext.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
double wcoord[] = new double[4];
glUtilities.gluUnProject((double) mousePoint.x, (double) mousePoint.y, 0.0, //take the current mouse points and convert them to opengl coordinates
mvmatrix, 0,
projmatrix, 0,
viewport, 0,
wcoord, 0);
drawConnection(wcoord[0]wcoord[2] ,wcoord[1] -wcoord[2],wcoord[2]); //pass in the converted mouse coordinates, multiplied by the depth, seems to only work if i multiply by the Z value
public void drawConnection (double x, double y, double z){
openGLAdapter.glPushMatrix();
openGLAdapter.glColor3f(0.5f, 0.0f, 1.0f);
openGLAdapter.glLineWidth(2.0f);
openGLAdapter.glRotated( x, 1.0,0.0, 0.0 );
openGLAdapter.glRotated( y, 0.0,1.0, 0.0 );
openGLAdapter.glBegin(GL.GL_LINES); //begin drawing connection line starting at the x,y coordinates of the selected box
if(selectedNode!= null && (x != 0 && y != 0)){
openGLAdapter.glVertex3d( selectedNode.x, selectedNode.y, selectedNode.z);
System.out.println("targetNode x and y " + selectedNode.x + " " + selectedNode.y);
openGLAdapter.glVertex3d(x,y, 0.0f); //the ending point of the connection line is equal to the current mouse position
System.out.println("line draw end point " + x + " " + y);
}
openGLAdapter.glEnd();
openGLAdapter.glLineWidth(1.0f);
openGLAdapter.glPopMatrix();
}