tags:

views:

179

answers:

2

Hi,

Currently I am developing an application in Jogl(My first application actually). Frist I have to load model into the canvas from a .obj file.(I manage to do so).

Next is I have to use the mouse dragged event to draw stroke on the same canvans and it the stroke must be in front of the teapot.(I use GL.GL_LINE_STRIP)and (glu.gluUnproject to get the coordinates to draw on)

Till this point I am having problems. (The model is just a rod laying horitontally on the x axis)

The coordinates of the model that is loaded does not seems the same as the mu mouse cursor point. For example: I use mouse click to determine where my cursor is at and also I click at the end of my model(a rod).This returns mi the X value of 0.37599047216147075. Then I try to look for the Maximum vertex X value of the rod model(should be the vertex at the most right hand side of the rod). it returns me a 1.xxx value... which is no where close to my mouse cursor value. And the maximum value I can click is just only 0.6xxx. Any idea why is this so?

A: 

You need to look into how to transform the 2D "view space" coordinate given with the mouse event, into a 3D "world space" coordinate that makes sense to compare to your model data.

This thread might be helpful.

unwind
A: 

Well I tried using glu.gluUnproject but I am not sure what should the z value be.

public void calObjectCoor(GL gl, float mousex, float mousey, float z) {

    float x = mousex, y = mousey;
    gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
    gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
    gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);

    /* note viewport[3] is height of window in pixels */
    realy = viewport[3] - (int) y ;


    glu.gluUnProject((double) x, (double) realy, z, //
            mvmatrix, 0,
            projmatrix, 0,
            viewport, 0,
            wcoord, 0);
}
ken