An OpenGL Question

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

An OpenGL Question

Post #1by Rassilon » 24.08.2005, 01:39

I know there are some OpenGL gurus sitting in the shadows of these forums....so here it goes...

Can someone direct me to the right formula for plotting and positioning objects on the surface of a sphere...eg: billboard of a tree so its facing straight up and down...I thought at first that by using the sphere normals I could get this to work but I know Im going about it all wrong....

I am currently using glRotate to try to rotate the object to be straight to no avail....

These are the angle calculations I am using...

Code: Select all

angleX1 = RADTODEG(double(j) * PI / (double(n)/2));
angleX2 = RADTODEG(double(j+1) * PI / (double(n)/2));
angleY1 = RADTODEG(double(i) * TWOPI / double(n))-90;
angleY2 = RADTODEG(double(i+1) * TWOPI / double(n))-90;


This is within a for loop i and j subdivided by a level of display from 32 to 1024...That would be n of course....

Here is the code or buffer of the billboard I am placing using vertex buffers and glRotate...

Code: Select all

float obj_billboard_norm[12][3] = {0.7071, 0.0000, 0.7071,
      0.7071, 0.0000, 0.7071,0.7071, 0.0000, 0.7071,
      0.7071, 0.0000, 0.7071,0.7071, 0.0000, 0.7071,
      0.7071, 0.0000, 0.7071,-0.7071, 0.0000, 0.7071,
      -0.7071, 0.0000, 0.7071,-0.7071, 0.0000, 0.7071,
      -0.7071, 0.0000, 0.7071,-0.7071, 0.0000, 0.7071,
      -0.7071, 0.0000, 0.7071};

float obj_billboard_vert[12][3] = {-0.3536, 1.0000, 0.3536,
      -0.3536, 0.0000, 0.3536,0.3536, 1.0000, -0.3536,
      0.3536, 0.0000, -0.3536,0.3536, 1.0000, -0.3536,
      -0.3536, 0.0000, 0.3536,-0.3536, 1.0000, -0.3536,
      -0.3536, 0.0000, -0.3536,0.3536, 1.0000, 0.3536,
      0.3536, 0.0000, 0.3536,0.3536, 1.0000, 0.3536,
      -0.3536, 0.0000, -0.3536};

float obj_billboard_tex[12][3] = {0.9995, 0.9995,
      0.9995, 0.0005,0.0005, 0.9995,
      0.0005, 0.0005,0.0005, 0.9995,
      0.9995, 0.0005,0.0000, 1.0000,
      0.0000, 0.0000,1.0000, 1.0000,
      1.0000, 0.0000,1.0000, 1.0000,
      0.0000, 0.0000};


and

Code: Select all


void Sphere::drawTree(float radius, Vec3d pos, Vec3d rot)
{
   glPushMatrix();
   glTranslated(pos.x,pos.y,pos.z);
   glRotated(rot.x, 1.0, 0.0, 0.0);
   glRotated(rot.y, 0.0, 1.0, 0.0);
   glRotated(rot.z, 0.0, 0.0, 1.0);
   glEnable(GL_NORMALIZE);
   glScaled(radius, radius, radius);
   glEnableClientState(GL_NORMAL_ARRAY);
   glEnableClientState (GL_VERTEX_ARRAY);
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   glTexCoordPointer (2, GL_FLOAT, 0, obj_billboard_tex);
   glNormalPointer (GL_FLOAT, 0, obj_billboard_norm);
   glVertexPointer (3, GL_FLOAT, 0, obj_billboard_vert);
   glDrawArrays(GL_TRIANGLES, 0, 12);
   glDisableClientState (GL_VERTEX_ARRAY);
   glDisableClientState (GL_NORMAL_ARRAY);
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   glDisable(GL_NORMALIZE);
   glPopMatrix();
}
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Return to “Development”