• Advertisement


This topic is now archived and is closed to further replies.


This topic is 5497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I was wondering, when you draw a sphere, the way it''ll work is that OpenGL draws it around the coordinates of the sphere center. My question is can you explicitly work out those coordinates for the sphere center? If so How? Thanks

Share this post

Link to post
Share on other sites
I think I know what you're asking. Basically you wanna know how to draw a sphere around a centerpoint manually. Here goes...

Polar coordinates or 3D trig. It all eventually breaks down the same. Here's the code for a sphere:

float pi = 3.14159265359f;
vector3d center = {0.0f, 0.0f, -5.0f};

float stacks = 55.0f;
float slices = 55.0f;
float radius = 1.5f;

float theta = 0.0f; // azimuth
float phi = -pi; // elevation

float stackheight = 2*pi/stacks;
float slicewidth = 2*pi/slices;

vector3d cur;
float srad;


while(phi <= pi)
srad = cos(phi)*radius;

cur.y = sin(phi)*radius;
for(theta = 0; theta <= 2*pi; theta+=slicewidth)
cur.x = cos(theta)*srad;
cur.z = sin(theta)*srad;

cur.x += center.x;
cur.y += center.y;
cur.z += center.z;

phi += stackheight;



//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[edited by - zealouselixir on February 6, 2003 8:32:33 PM]

Share this post

Link to post
Share on other sites
Thanks for that, but it''s not what I want. Basically, what I want is the ''current position''. When you code, you do various translations and rotations. For example, gltranslate(1,0,0) moves the currentposition to (1,0,0) and would draw the sphere there(1 unit across from the origin). If you then do translate(0,10,0) and then drew, the sphere would appear 10 units higher.

The obvious thing is to just keep track with variables. However with a hierarchy, it becomes complicated to do that, especially with rotations. What I want is, can you extrapolate the current coordinates?

Share this post

Link to post
Share on other sites

  • Advertisement