Sign in to follow this  

projection of a line in shpere

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

This topic is 4213 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this