Jump to content
  • Advertisement
Sign in to follow this  
magneeto

projection of a line in shpere

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

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 this post


Link to post
Share on other sites
Advertisement
Maybe this might help you:

/**
* 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!