# projection of a line in shpere

This topic is 4549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, i want to make a sphere out of n number of slices and m number of stacks or divisions. the general algorithm is for each division { //Draw a ring glBegin( GL_QUAD_STRIP); for each slice in the strip { specify two end points } glEnd(); } now how do i specify the two end points in the inner for loop? how do i calculate the projection of a point in a sphere on to the three axes ?i don't know the general formula

##### Share on other sites
/** * Generate the vertices for the sphere. * Called once from the constructor and then whenever the sphere is resized or if its number of * longitude or alitude lines is changed. */void createVertices(){	unsigned int vertex_num = 0;		// The index for the map of vertices	CVertex3d Vertex;	// Clear the vector of any vertices	vertex_buffer.clear();	for (float i=0; i<=360; i+=360/LongitudeLines)	{		for (float j=-90; j<=90; j+=180/AltitudeLines)		{			Vertex.setX( cos(i*(pi/180.0f))*Radius *cos(j*(pi/180.0f)) );	// Converted to radians			Vertex.setY( sin(i*(pi/180.0f))*Radius *cos(j*(pi/180.0f)) );	// Converted to radians			Vertex.setZ( sin(j*(pi/180.0f))*Radius );						// Converted to radians			// Vertex is created around 0,0,0 and then later, it is translated to its position			// insert into buffer			vertex_buffer.push_back(Vertex);			vertex_num++;		}	}}

I can't remember who gave it to me (someone on GD), so if it was you, come forward. [smile]

But, this should be fairly straightforward. It generates the points for a sphere and puts them into a buffer.

Hope I helped some.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013709
×