gluSphere

Started by
2 comments, last by rugal 21 years, 2 months ago
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
Advertisement
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.//
miscellaneous links


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

[twitter]warrenm[/twitter]

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?
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.//
miscellaneous links

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement