PDA

View Full Version : draw object in 3 dimensions with openGL C++

21did21
04-07-2012, 12:30 PM
Hello all,

it's been a while since I have not done C + + and a fortiori the openGL. In the past i made sphere but now I try to do several things (in different coordinates) with a little more complex forms.

=> Example : I will like to start by making several ellipsoids with differents directions orientation.

the problem is that I do not know how to do this, it sounds complicated to me, no ...?

A +

ps: this is my code for spheres, how i can modify them to have ellipsoides ?

for ( int k = 0 ; k < 400 ; ++k )
{
params.push_back(sphere);
}
//--------------------------------tirage au sort des coordonnées-------------------------------------
//on initialise le temps
qsrand(time(NULL));
//Et dans la boucle on utilise tirage entre -5000 et +5000 puis en divise par 1000
float c1=0.0;
float c2=0.0;
float c3=0.0;
//---------------------------------------------------------------------------------------------------
int e=0;
for ( int k = 0 ; k < globalNb ; ++k )
{
for ( int i = 0 ; i < 200 ; ++i )
{
c1 =((qrand() % (5000-(-5000)+1)) + (-5000))/10000.0;
c2 =((qrand() % (5000-(-5000)+1)) + (-5000))/10000.0;
c3 =((qrand() % (5000-(-5000)+1)) + (-5000))/10000.0;

//tracer de la sphere
glPushMatrix( );//save axis system
glTranslatef(c1,c2,c3);
gluSphere(params[e],0.0001*i,10,10);
glPopMatrix( ); //load the saved matrix
e=e+1;
}
}

tonyo_au
04-07-2012, 08:24 PM
Look to add glRotate and glScale to the glTranslate

21did21
04-08-2012, 02:55 AM
thanks a lot for your help !

=> if i understand i have to put at the end of my code something like this ?

glPushMatrix( );//save axis system
glTranslatef(c1,c2,c3);
glScalef(myElongationForEllipse,1,1);
glRotated(90,0,0,1);
gluSphere(params[e],0.0001*i,10,10);
glPopMatrix( ); //load the saved matrix

tonyo_au
04-08-2012, 10:27 AM
Just remember the order of glTranslatef, glScalef, glRotated is important as you get different effect depending on the order you use. (I always get mine wrong!!)