View Full Version : Spheres

orate!

10-22-2002, 04:34 PM

Erm ... sorry to ask such a stupid question but how can i generate sphere without using Toolkits like GLU oder GLUT ...

I also doesnt want to see the diffcult pages by paul bourke ... a easy explain is all i want !!!

I have a basic knowledge of trigonmetry so u can tell me ... but please explain easily ...

THX

BYE

Thanks for the Paul Bourke reference! I'd never heard of him before but his web page http://astronomy.swin.edu.au/~pbourke/

is most excellent. He discusses spheres here:

http://astronomy.swin.edu.au/~pbourke/geometry/sphere/

Sweet!

Btw, if that stuff seems to be over your head, review your spherical coordinates. http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by jmg (edited 10-22-2002).]

fringe

10-23-2002, 12:39 AM

Spheres are one of the easier shapes to do because they are symetric. First you have to decide which co-ordinates are on the surface of your shape (in this case a sphere). For a sphere this is all points a distance r away from the centre. You need some control over reaching each co-ordinate so we will use two angles theta and phi. Think of the center of the sphere this is just a circle. The phi variable is the angle from the x axis. If we were just drawing a circle we would draw:

x= r cos (phi) and

y= r sin (phi)

I would imagine using a loop to increment phi and draw from one bit of phi to the next.

However we have a sphere. Now if you think of a sphere it is just lots of circles but with different radi. The radius can be worked out with a bit of trig. Draw a semi-circle

|-

| \

| |

| /

|-

Mark an angle from the verticle to a point on te semi circle. Draw a horizontal line. This line is the circle in thelast bit and has a radius of sin (theta)

This circle is at a height of r cos theta

OK so now we have all our points:

x = r sin (theta) Cos (phi)

y = rsin (theta) Sin (phi)

z = r Cos (theta)

We now make two loops and draw triangle through all these points connecting them all.

glBegin(GL_Triangle_Strip)

for (int i=0;i<maxsegs;i++){

theta=Pi*i/maxsegs;

thetaplus=Pi*(i+1)/maxsegs;

for (int j=0;j<=maxsegs;j++){

phi=2*Pi*j/maxsegs;

glVertex3f(r*sin(theta)*cos(phi),r*sin(theta)*Sin( phi),r*cos(theta));

glVertex3f(r*sin(thetaplus)*cos(phi),r*sin(thetapl us)*Sin(phi),r*cos(thetaplus));

}

}

Hope that helps,

fringe

P.S. All code writtern without testing and source so there may be mistakes but as long as you understand the idea it should be fine

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.