Archived

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

gluSphere

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

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 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;  // azimuthfloat phi = -pi;    // elevation float stackheight = 2*pi/stacks;float slicewidth  = 2*pi/slices; vector3d cur;float srad; glBegin(GL_POINTS); 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;		glVertex3fv(cur.v);	} 	phi += stackheight;}  glEnd();

Later,
ZE.

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

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

Share on other sites
Hi
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 on other sites
Oh, sorry. Heh.

One way to do that:

float ViewMat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, ViewMat);
CVector3 CurPos(ViewMat[12], ViewMat[13], ViewMat[14];

I *think* those are the correct matrix elements.

Later,
ZE.

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

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• Who's Online (See full list)

There are no registered users currently online

×