🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Drawing a sphere

Started by
6 comments, last by bosco 23 years, 12 months ago
Hmm, I feel like an idiot for posting this, but math is as strong as my programming ( which is pretty weak.. ), but what I''d like to do is draw a sphere.. My own sphere.. using no routines other than like standard gl calls.. no utlilty or glut stuff.. Basically what I''m asking is what''s the best way to find the points on a sphere if you want a certain number of points total or what not.. I''ve thought of one way, and that''s using the sphere formula for every point in a cube that encloses said sphere, but this would seem to time consuming.. although if it were only at initilization it wouldn''t be all that bad.. Thanks for any help, bosco() - leader of the free world... or something..
--leader of the free world .. or something ..
Advertisement
So you want a sphere??.... ok

i want to explain how to do it but tomorrow i will have my phisics exam and its important (Sorry, but first me ).

Tomorrow at night you will get the awnser, bul let me tell you that your way its very expensive.

Another thing, you want the sphere in triangles or quads????

Cya tomorow

PROgrammer
there was a post about this a while ago. I think nes was asking a question about it. anyway, here''s the code that was in that post. to give you some ideas. I take no credit for this source.
    for (double lat = 0 ; lat < 180 ; lat += stepy){ double xlatrad = sin(lat) * XRadius; double zlatrad = sin(lat) * ZRadius; double y = cos(lat) * YRadius; for (double lng = 0 ; lng < 360 ; lng += stepx) { double x = sin(lng) * xlatrad ; double z = cos(lng) * zlatrad; 3dPlot(x,y,z); //plot pixel }}    

of course there''s also glutSolidSphere(), but I bet you already know that.

JoeMont001@aol.com | Polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Yeah yeah.. function calls, function calls.. I was never part of the HARD CORE demo movement in the early 90''s but I''ve done my share of assembly programming and if I don''t know how to do it, then I learn.. after that then I may use glutF*ckingSphere.. :p

But seriously.. Umm to Promag, I''d like it in triangles I suppose..

For anyone else interested there''s some descent info about this here ( as well as other great things ) :

http://www.faqs.org/faqs/graphics/algorithms-faq/


bosco()

funny''s cousin - not funny

--leader of the free world .. or something ..
Here's some sphere drawing code I found a while ago (I think it was on Paul Bourke's site somewhere):

    void CreateSphere(XYZ c,double r,int n){   int i,j;   double theta1,theta2,theta3;   XYZ e;   if (r < 0)      r = -r;   if (n < 0)      n = -n;   if (n < 1 // r <= 0) {      glBegin(GL_POINTS);      glVertex3f(c.x,c.y,c.z);      glEnd();      return;   }   for (j=0;j<n/2;j++) {      theta1 = j * TWOPI / n - PID2;      theta2 = (j + 1) * TWOPI / n - PID2;      glBegin(GL_QUAD_STRIP);      for (i=0;i<=n;i++) {         theta3 = i * TWOPI / n;         e.x = c.x + r * cos(theta2) * cos(theta3);         e.y = c.y + r * sin(theta2);         e.z = c.z + r * cos(theta2) * sin(theta3);         glNormal3f(e.x,e.y,e.z);         glTexCoord2f(i/(double)n,2*(j+1)/(double)n);         glVertex3f(e.x,e.y,e.z);         e.x = c.x + r * cos(theta1) * cos(theta3);         e.y = c.y + r * sin(theta1);         e.z = c.z + r * cos(theta1) * sin(theta3);         glNormal3f(e.x,e.y,e.z);         glTexCoord2f(i/(double)n,2*j/(double)n);         glVertex3f(e.x,e.y,e.z);      }      glEnd();   }}    

Hope that helps.

Morgan

Edited by - Morgan on July 5, 2000 9:49:17 PM
That does help out a bit.. It''s good to have a routine to see, but essientially I need to write one myself so I''ll understand it.. Thanks a lot though.. Also, what is TWOPI in the above code do you know?


thanks,

bosco()
--leader of the free world .. or something ..
The TWOPI refers to the constant PI times 2.
So the number would be 3.141592*2, or however many decimals of PI you use =).
Yeah, I''m not actually using that code either, just have it laying around. I''m basing my sphere generation code on it, but I''m building a model out of it so that rendering is faster (not calling a bunch of sin/cosine functions for every frame rendered and normals are precalculated). But it is nice to have something to look at while figuring it out

Morgan

This topic is closed to new replies.

Advertisement