mouse event listener on a GLJPanel

Hello,

I am using a JInternalFrame to hold a GLJPanel. In this GLPanel is a plotted graph. I have implemented recenetring capabilities within the GLJPanel. When the user clicks a location in the graph it recenters around that point. I use a mouse event ‘e’ and use e.getX() and e.getY() to get the location clicked. Then I do the proper calculations on variable translateX_ and translateY_ to perform this recentering. The problem is it does not recentering exactly. Now I know my calculations are correct. A description of the problem is as I click further away from the actual center on the graph, the worse the recentering is. So if I click relatively close to the actual center, it recenters fine. So it is a affect by how far in the x and y plane I click from the actual. In this GLJPanel I also have two GLJPanels that are the X and Y axis. I know the dimension of these and this affects my plotting. I need to offset the widths of the axis when computing the coordinates to plot of the actual graph. I was wondering if anyone knew any reason why as I click further and further away from the graph, does worse my recentering is. Could it be a problem with the units, (mouse event click reading vs. GLJPanel dimensions. Please does anyone have any ideas what I can tlook into myself to fix this problem.

Confesor

You’re working in 3D when using the GLJPanel and there is no unit scale enforced by JOGL. You can set up an orthographic view so that the 3D coordinates are equal to the pixel values using (I believe) glOrtho(0, width, 0, height, near, far) and glViewport(0, 0, width, height). Also keep in mind that OpenGL’s (X, Y) origin is at the lower-left of the window while the AWT’s is at the upper-left. Using this you should be able to compute the appropriate distance to translate your model for recentering.

I am aware that OpenGL and AWT have different X Y origins and have done the proper conversion. This is what my init() looks like, I do use an orthographic view.


public void init (GLDrawable drawable)
	{
            gl =  drawable.getGL();
            glu = drawable.getGLU();
            
            //clear the background color to white
            gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            gl.glShadeModel(GL.GL_SMOOTH);
                
            // Set viewing area
            gl.glViewport((init_width_/13), (init_height_/13), init_width_, init_height_); 
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();
            glu.gluOrtho2D(init_width_/13, init_width_, init_height_/13, init_height_);

Does this seem right with the gluOrtho and the viewport?

The division by 13 of the width and height look suspicious. It seems to me that those should be 0. However, depending on your centering algorithm they might be correct. Do you have a small test case you could post?