Jump to content
  • Advertisement


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


rendering a sphere

This topic is 5935 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

id like to write my own sphere rendering function (gluSphere() doesnt give me the ability to do what i want or i havnt figured out to do it using it heh). basically im not too sure how to go about rendering it...getting the shperical (sp) shape. if you could point me to any sites or information id be most grateful. thanks in advanced

Share this post

Link to post
Share on other sites
I did what you are trying to do right now. here is what I did. I made a circle that was lying lat on the z axis (What i mean i i just made y into z), by using the equations
z = sin(a)

a = a variable that goes from 0 to 360

i stored the points in an array and then took an equation to rotate points around the z axis. I rotated these points and stored the new points in another array. i did this a couple times and got my sphere. hope that helps the z-rotation equation is:


[edited by - tHiSiSbOb on July 15, 2002 3:55:49 PM]

Share this post

Link to post
Share on other sites
tHiSiSbOb almost has the correct sphere generation code, but it can be done without forming a 2d sphere and rotating it.

if you search for "sperical coordinates" you should find it.


i think i went overboard with my custom sphere routine

i basically used the technique of splitting the faces of an icosahedron recusively, this gives you a perfect sphere with all the tri's the same size. To do the splitting i used a Quadtree

[edited by - Marvin on July 16, 2002 3:22:30 AM]

Share this post

Link to post
Share on other sites
Hi Marvin!

Looks good...could you give me some specifics on how you did that?


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook

Share this post

Link to post
Share on other sites
this is what i use:


void draw_sphere(double r, int n=16)
int i,j;
double theta1,theta2,theta3;
double ex, ey, ez;
if (r < 0)
r = -r;
if (n < 0)
n = -n;
if (n < 1 || r <= 0) {
for (j=0;j<n/2;j++) {
theta1 = j * M_PI*2 / n - M_PI/2;
theta2 = (j + 1) * M_PI*2 / n - M_PI/2;
for (i=0;i<=n;i++) {
theta3 = i * M_PI*2 / n;
ex = r * cos(theta2) * cos(theta3);
ey = r * sin(theta2);
ez = r * cos(theta2) * sin(theta3);
ex = r * cos(theta1) * cos(theta3);
ey = r * sin(theta1);
ez = r * cos(theta1) * sin(theta3);

The first argument is the radius, second argument is how smooth the sphere should be(the higher the smoother). Make sure that M_PI is defined

#define M_PI 3.14159

This is modified code from someone on one of gamedev's forums I think.

[edited by - wolfman8k on July 17, 2002 1:10:39 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!