PDA

View Full Version : opengl q



Tracygo
11-23-2003, 10:05 AM
is there anyone could tell me what is this "length argument"? And what does (Glfloat length) mean, I mean why not a number? Thanks a lot


//Joint part - consists of a Sphereand and a streched cube which is controled by the length argument//

void jointShape (GLfloat length)
{
glColor3f(0.0, 0.0, 1.0); //Sphere color
glPushMatrix ();//save position
glTranslatef (-length/2, 0.0, 0.0);//
glutSolidSphere(0.8,40, 40);
glTranslatef (length/2, 0.0, 0.0);
glColor3f(0.0, 1.0, 0.0); //cuboid color
glScalef (length, 1.0,1.0);//
glutSolidCube (1.0);
glPopMatrix ();

}

mikael_aronsson
11-23-2003, 01:03 PM
length is an argument that allows you to specify the size and or shape of the "thing" that is rendered, using a number would of course be ok, but by using an argument the code becomes a bit more flexible and it might be useful for more then one thing maybe....

Is this april fools day or what is going on ?

nexusone
11-23-2003, 05:42 PM
This is one of the useful things in programming, being able to create your own routines.

Let's say you have to use the same code three times, you could do it each time with a set number. But by making it a routine you write the lines of code only once.

exampe in code use:

jointShape ( 1.0 );

jointShape ( 1.1 );

jointShape ( 0.5 );

jointShape ( 1.8 );

Just saved from writing 9 lines for code for each of the above, so now we have only 13 and not 36 lines if we had used a fix number.