PDA

View Full Version : Meaning of one command in the function of OpenGL



openglam
02-23-2011, 02:59 AM
Dear All,
I am working on the ex about opengl, I was told to use glutSolidCube to write a function to generate boxes with different dimensions, i wanna know why the answer needs to do some sort of translation about y axis in 0.5 (as indicated by the "?").
http://i102.photobucket.com/albums/m112/ihmcjacky/opengl.jpg
Thanks for all your help!

ravage
02-23-2011, 07:15 AM
It doesn't have to. It may be an example. I would change it to:


void box(float x, float y, float z, float l=1.0, float w=1.0, float h=1.0)
{
glPushMatrix();

glScalef(l,w,h);
glTranslatef(x, y, z);
glutSolidCube(1);

glPopMatrix();
}

Alfonse Reinheart
02-23-2011, 08:58 AM
It doesn't have to. It may be an example. I would change it to:

That does the transformations in the wrong order (http://www.arcsynthesis.org/gltut/Positioning/Tut06%20Fun%20with%20Matrices.html). The XYZ position is supposed to be a world-space position, yes? Then it goes on the left (before) the scale.

openglam
02-23-2011, 08:01 PM
That means I can ignore the 0.5 translation or?

And is my thinking follow the order from the bottom of the program? i.e. Actually I first draw a solid cube, and do the translation and finally scale the cube with different dimension?