Skip to main content
gamedev.net
🔒 Locked

Please help...

Started by Glass_Knife Oct 30, 2002 at 8:41 PM 9 replies 750+ views
Original Post
Glass_Knife
Glass_Knife
I am new to openGL, but learning... Could anyone tell me if there is an easy way to draw a sphere with the top 1/3rd cut off? Or even cut in half. I need to make a model for my openGL class, and I could make it look really cool if I could do this, but I can''t figure out how. Please let me know if there is an easy way. Thanks I think, therfore I am. I think?
Mathematix
Mathematix
You''re unlikely to get help with homework unless you at least show proof of an effort, dude!

Peace out,
Mathematix.
zealouselixir
zealouselixir
SPHERE. Have fun formatting it. It''s not the standard parametric way, but it works.


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;

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


Peace,
ZE.

P.S. I''m only doing this because I wrote the code yesterday and it was open in the editor.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
Thunder_Hawk
Thunder_Hawk

void Draw_Sphere_Part (float fraction_missing, float cx, float cy, float cz)
{
float pi = 3.14159265359f;
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;

float x, y, z;
float srad;

glBegin(GL_POINTS);

while(phi <= ((1-fraction_missing)*2*pi-pi))
{
srad = cos(phi)*radius;

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

x += cx;
y += cy;
z += cz;
glVertex3f(x, y, z);
}

phi += stackheight;
}

glEnd();
}


I don't know if that works....do I get a cookie?

[EDIT] Sphere, not circle...hmmm, while this does make a sphere of points, the points can't be connected easily to form the sphere with polygons. Oh well, I don't know the parametric form (would it have 2 variables?) so I can't fix it....goodnight

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________


[edited by - Thunder_Hawk on October 30, 2002 11:20:23 PM]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
zealouselixir
zealouselixir
They can be connected rather easily; the modification is just stunningly redundant and slow. It''d be best to put the points in a vertex array and make a nice little index array to render it as a set of triangle strips...
[twitter]warrenm[/twitter]
zealouselixir
zealouselixir
Yes, as you can see, two variables (phi and theta, representing elevation and azimuth respectively) are required to calculate a point on a sphere. This translates to 2 loops. The formula used for the code I gave is

x = r cos(theta) cos(phi)
y = r cos(phi)
z = r sin(theta) cos(phi)

I could explain it, but I don''t have time...email me if you want more info, or search for (sphere coordinates azimuth) on Google, etc.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
Thunder_Hawk
Thunder_Hawk
I''ll have to check out the trig section of my Pre-Calc book (I really feel like we should have done this before, I mean I''m a junior taking the advanced math). What I was saying is that the points are made in circles here then go up. To draw the sphere properly they would need to be made in pairs of circles at a time (I''m not sure how the redundant points could be fixed by the vector array) hmmm... I guess I could fix it, nah too late. Sweet! My modifications truncated the sphere as I planned. Time to eat my cookie and go to bed...bye

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Thunder_Hawk
Thunder_Hawk
LOL ZE I never noticed your miscellaneous links before ¦þ
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
zealouselixir
zealouselixir
I only regret that I''m not able to maintain my signature like some. Several of the miscellaneous links are broken or irrelevant, and even my own website link is dead since the unfortunate demise of TotalIM. Ah, well. Maybe over Christmas break I''ll write a new one. Thanks for noticing though

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
Glass_Knife
Glass_Knife
Thanks to eveyone for the help. In class, we are just using the glutSolidSphere, and the quadrics. I didn''t know that it had to be drawn from scratch. I understand the trig stuff ( after playing with it for a while), and now I have a cool point sphere, but I can''t figure out how you would add in the normal stuff. Does that stuff have to be done by hand too?

I think, therfore I am.
I think?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.