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();
}