Originally posted by Robbo:
More information required, including the values of your unproject point etc. and the code that is causing the trouble…
I give you the more information I can:
My GLAnimCanvas (Java) has a size of 900*600 and he is incerted in a JPanel of the same size. The user will click everywhere on this GLAnimCanvas that will generate an event. I pick up from this event the position where the user clicked for example 400-300. Then the Zone method is called it will make the convertion:
/***************************************/
public void mousePressed(MouseEvent e) {
Pos_X_Dep = e.getX();
Pos_Y_Dep = e.getY();
Canvas.Zone(Pos_X_Dep, Pos_Y_Dep);
}
}
/***************************************/
public void Zone(int X, int Y){
gl.glGetIntegerv(GL_VIEWPORT, viewport );
gl.glGetDoublev(GL_MODELVIEW_MATRIX,
mvmatrix);
gl.glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
glu.gluUnProject((double)X,(double)Y,0.0,mvmatrix,projmatrix,viewport,x,y,z));
}
/**************************************/
The method Zone below should make the conversion but it failed.
I initialised the GLAnimCanvas like this:
//
gl.glViewport(0,0,width,height); //width et height size of the GLAnimCanvas which is size of the JPanel
gl.glMatrixMode(GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(Angle_View_Degree, width/height, 0.0f, 10.0f);
gl.glMatrixMode(GL_MODELVIEW);
gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl.glLoadIdentity();
//
I draw many rectangles in my GLAnimcanvas they represent a pipeline. For seeing all the pipeline, I calculate an ideal Z position and I use glTranslated for setting the new position. The user can also drag with the mouse to move the scene. I also use glTanslated:
/**************************************/
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl.glTranslated(X_Value,Y_Value,Z_Value);
// I change the value of the variables X Y and Z to see the new view of the scene
for (int i=0 ; i < Pipe_Values.size();i++){// For each part of the pipe
pipe = (Pipe)Pipe_Values.get(i);
// Take the pipe
Lenght = (float)pipe.getLenght();
// Take his lenght
Angle = (float)(pipe.getAngle());//*180/Math.PI);
// Take his angle
gl.glRotatef (Angle, 0.0f,0.0f,1.0f); // Rotate the direction of the pipe depending the angle value
gl.glMatrixMode(GL_MODELVIEW);
gl.glBegin(GL_QUADS); // Draw a quad
gl.glColor4f(0.75f,0.0f,0.0f,0.9f); gl.glVertex3f(0.0f,(float)(-Diameter/21.2),0.0f); gl.glVertex3f(Lenght,(float)(-Diameter/21.2),0.0f); gl.glVertex3f(Lenght,(float)(Diameter/21.2),0.0f); gl.glVertex3f(0.0f,(float)(Diameter/21.2),0.0f); gl.glEnd(); // End of the quad
gl.glTranslated Lenght+3*Diameter/2,0.0f,0.0f); // Move the cursor to the next pipe to draw
gl.glRotatef (-Angle,0.0f,0.0f,1.0f); // Reinitialise the angle to 0
gl.glFlush();
}
gl.glLoadIdentity();
/**************************************/
I hope i have the most complete I could and wish you can help me Robbo…
Thanks in advance
Mat