Clicking a line

I have a plot that is 3-dimensional. I start the plot out by having it appear you are above the plot looking down on it so all the lines of data appear to be flat along the x and y axes. I then make it possible to rotate about the x-axis so it appears the user is now standing in front of the object and looking at it. An example of this is if I am in a helicopter over a mountain range, I do not see which is higher, just where the mountains lie. Then when I get to the ground I suddenly see all the peaks and valleys of the mountains. This is how my data appears on the screen when I rotate it about the x-axis.

The problem I am having is I allow the user to click on one of these lines with the mouse. I am capturing the mouse’s coordinates and converting them to the ortho coordinates and then looping through my lines to see if the user clicked on a line and if so I am changing its color and doing other things with it. This code is working fine when I have no rotation about the x-axis. But once I add rotation into the picture, my line grabbing is off. My code snippet looks like this:

          for( int point = 0 ; point < numPoints ; point++ )
            {
               // If this is true, we have found a selection
               double xData;
               double yData;

               if( ps->getDataMode( ) == PointSet::VECTOR_DATA )
               {
                  xData = ps->x->at( point );
                  yData = ps->y->at( point );
               }
               else if( ps->getDataMode( ) == PointSet::POINTER_DATA )
               {
                  xData = ps->xData[point];
                  yData = ps->yData[point];
               }
               
               double xWaver = ( mCurrentXMax - mCurrentXMin ) * 0.02;
               double yWaver = ( mCurrentYMax - mCurrentYMin ) * 0.02 - mDataLayer->getXRotation( );
               if( ( xData > x - xWaver && xData < x + xWaver ) && 
                   ( yData > y - yWaver && yData < y + yWaver ) )
               {
                  foundSweep = true;
                  break;
               } // end if( ps->x->at( point ) == x && ps->y->at( point ) == y )
            } // end for( int point = 0 ; point < numPoints && foundSweep == false ; point++ )
            if( foundSweep == true )
            {
               break;
            }
         } // end for( int sets = 0 ; sets < numPointSets && foundSweep == false ; sets++ ) 

I am creating a “waver” so I basically say if the data falls into the mouseclick +/- a waver amount, I must have clicked on it. But I don’t know how to account for the rotation in the x-axis. This stretches things out on the y-axis to the viewer but messes up my grabbing. When a line appeared to run about y = 34, with the rotation, the line appears to be on some spots at y = 34 to y = 36 because of the peaks rising up and the low portions staying low.

Does anybody have an idea how I can account for the rotation to allow almost flawless clicking of the lines in my plot? Thanks for any help you have and please let me know if I can provide any more information that would assist you in helping me resolve this.

I have decided that I don’t want to actually rotate my grid and axis labels but want to keep the lines in the spot on the y-axis where they occur.

So if my grid goes from ymin == 28.0 and ymax == 38.0, then the line I have at y == 33.0 will always appear to be at 33.0. Right now, with using the glRotated( ) call, the line at y == 33.0 eventually rises all the way to y == 35.0, which is not what I want.

What I want is to start seeing a profile of this line so I can start to see the rises and dips in the line while not having to move the grid around. So it’s almost like I need to translate the viewport containing my data (I have numerous viewports for the data, labels, axes tick marks, etc.) so that it goes back down to its proper spot.

Does anyone have any idea of what I am trying to ask here and if so, do you have any ideas on how to solve this problem? Thanks!

I understand the need and it is very common need when you want to interact.

From your code it looks like that you are working with certain space orientation in mind - specifically object space where you have place your objects. Thus it would not work if you perform rotation, translation or may be even scaling.

You can look into gluUnproject command (from GLU library - helper library for GL) which will convert screen space (window) coordinate to OpenGL object-space coordinate.

Check some basic details at FAQ:
http://www.opengl.org/resources/faq/technical/glu.htm

NeHe has an article explaning usage of the calls.
http://nehe.gamedev.net/data/articles/article.asp?article=13

Hope it helps you.
Thx
Ketan

Thanks I will look into implementing this and see if I can get it to help me.

I finally have gotten time to look back into this but I am having one big problem. Is there a great place to get the GLU library from? I searched my harddrive and I do not have it. I am running Visual Studios 2003 and have not tried using any GLU or GLUT calls as I am using Qt to do my windowing. Thanks!

The GLU project.c (contains an implementation of gluUnProject):
http://oss.sgi.com/cgi-bin/cvsweb.cgi/pr…pe=text%2Fplain

The GLU source tree:
http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/gfx/lib/glu/

I found it was embedded into my Visual Studio include directories but for some reason, Windows search couldn’t find it. I guess I should get something better like Google Desktop. Thanks for the links though. I am playing around with gluUnProject now!

I am having some problems with gluUnProject. It is working fine when I look at the object overhead with no rotation about the x-axis. But once I rotate the plot about the x-axis so I can see the z-values rise, the gluUnProject doesn’t work correctly.

If I click on a spot before rotating, I may get these returned values:

winX = 499
winY = 196
x = -6.58282
y = 34.0597
z = 8.39231

After rotating, I get these values:

winX = 500
winY = 197
x = -5.15038
y = 34.0324
z = 8.39231

I should also add that at this point, with the overhead my view, my x-values range from -2000 to 2000 and my y-values range from 29-38. After I rotate some, why do my returned y values appear almost identical? Shouldn’t at least the y-value change upon rotating the image? Thanks again for your help!

Edit:
The amount of rotation I normally have is between 0 and -3 degrees. I don’t need much rotation in order to see enough of a profile of my lines. I have enough that it goes from looking like a field of straight lines to looking like a mountain range with the peaks all down the middle. I also have a 2-D grid that I run around on the x and y axes and that by adding around -0.8 degrees of rotation to my x-axis, a flat line that lied on y = 34 now looks like a mountain running from 34.75 <= y <= 36.0. Thanks again!

I found a way to manipulate my data so I don’t have to worry about this anymore. But if anybody has any solutions, I would still love to hear them for future knowledge. Thanks!