View Full Version : misunderstanding transform

01-26-2004, 11:18 AM
I am having trouble displaying data, and must be misunderstanding something about transforms

I want to graph values between xmin,xmax,ymin,ymax
glOrtho should do it.
If I use glOrtho(0,1,0,1)
and plot values within those ranges, it works.

If I want to translate to arbitrary scale, I try:
glScaled(1/deltaX, 1/deltaY, 1);

and get nothing. Thinking I had slipped a gasket, I tried reversing the two, but that's wrong too. I also tried eliminating the translate and scale, and changing the observer to:
gluOrtho2D(xMin, xMax, yMin, yMax);

So first, any help on this specific problem would be greatly appreciated. Second, in order to debug problems in the future, I'd like a routine that takes a point x,y,z and performs the translation done by the current opengl transform. Is there any way to extract the current state of the matrix, multiply on my x,y,z value, so I can print the results?


double xMin = -74;
double yMin = 38;
double xMax = -70;
double yMax = 42;
gluOrtho2D(0, 1, 0, 1);
//gluOrtho2D(xMin, xMax, yMin, yMax);
glScaled(0.05, 0.9, 1);
scale->generateLegend(white, medFont, 19.0, 7, 24.0);

#if 0
glVertex2f(0, 0);
glVertex2f(1, 0);
glVertex2f(1, 1);
glVertex2f(0, 1);
cout << xMin << "," << yMin << "\t" <<
xMax << "," << yMax << "\n";
double deltaX = xMax - xMin;
double deltaY = yMax - yMin;
double centerX = (xMax + xMin)/2;
double centerY = (yMax + yMin)/2;
glScaled(1/deltaX, 1/deltaY, 1);
glVertex2f(xMin, yMin);
glVertex2f(xMax, yMin);
glVertex2f(xMax, yMax);
glVertex2f(xMin, yMax);

01-27-2004, 04:27 AM
Hmm, first of all I think you've lost something in glOrtho. You're only giving it 4 params while there's six.

void glOrtho(GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble near,
GLdouble far)

The near and far have to do with the distance of front and rear plane of the viewing frustum in relation to the center of projection (if this sounds jibberish get a good book). I think by default the near and far are set to -1,1 for glOrtho (not so for glFrustum). So when you are translating in the z-axis -1 you put your objects out of the viewing frustum. Try increasing the far value and see what happens.
As for getting the current state of the matrix use glGet*. See the documentation for what parameter to pass to it. It's something like GL_MODELVIEW_MATRIX. Be carefull because the internal represantation of it is not 4x4 but 1x16.

[This message has been edited by moucard (edited 01-27-2004).]

01-27-2004, 05:06 AM
gluOrtho2D does not take a front and back option. I also tried the code with a transform of:

glTranslated(-xMin,-yMin, 0);

and that made no difference.
I did change the call on your suggestion to:


and that doesn't seem to have anything to do with it.

Help, anyone?

[This message has been edited by dovkruger (edited 01-27-2004).]

01-27-2004, 09:14 AM
After looking it up, yes gluOrtho2D takes 4 parameters and the near far values are -1,1 by default. You can't alter them using gluOrtho2D. Try a search on google on gluOrtho2D.
Furthermore after studying your code for a bit I noticed the following thing. (I could be wrong because I don't have a computer right now to check my theory.) You call to glOrtho2D(xMin, xMax, yMin, yMax) right? So your world coordinate window is: bottom left: -74, 38, bottom right: 70, 38, top right: 70, 42, top left: -74, 42. Then, near the bottom of your code, you translate with: glTranslatef(-xMin, -yMin, -1). But that would make the center of your world coordinates in point 74, -38 which is a bit way out of the viewing frustum. So I think what you want to translate to is glTranslatef(xMin, yMin); Also just to be on the safe side try playing with the z value if you still have a problem. Try 0.5 for example and also maybe give it -0.5 if you still have a problem.Although in the end I think what your are trying to do could be achieved without a call to glScalef. If you make your world coordinate window smaller (the frustum) but still render it to the same sized window the object will appear larger. Hope that helps http://www.opengl.org/discussion_boards/ubb/smile.gif

PS: Supposing that your function draws the data on the upper right axis (the positive) If you draw your data along the negative x-axis I'm wrong.

PS2 (Not the console!) What I'm trying to say is the data that you draw (the vertices) must have their coordinates (after the transformations) inside the viewing frustum. Else they're culled.
[This message has been edited by moucard (edited 01-27-2004).]

[This message has been edited by moucard (edited 01-27-2004).]

01-27-2004, 02:17 PM
Thanks, I'm pretty sure what happened is a combination.

glOrtho with 6 parameters works, provided that yes, the translate is out of there.

I suspect that if I switched back to:

glScaled(1/deltaX, 1/deltaY, 1);

That should work as well.

Incidentally, you don't have to tell a C programmer to use 4 or 6 parameters and/or look it up on google, it literally couldn't have compiled if I called it with the incorrect number of arguments.