Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Coding a sphere?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Taboo Builder   Members   -  Reputation: 1034

Like
Likes
Like

Posted 22 October 2001 - 08:18 PM

I''m coding a this game and I need to code a sphere in format: X,Y,Z X,Y,Z X,Y,Z (in textfile) but how to create this ball?

Sponsor:

#2 Obelix   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 October 2001 - 11:10 PM

Download the NeHe tutorial about quadratics.

#3 masonium   Members   -  Reputation: 118

Like
Likes
Like

Posted 23 October 2001 - 01:28 PM

Here''s the function that I use. It''s optimized for triangle strips. It generates normals and texture coordinates.

  
// draws a sphere with tex coords

// radius - radius

// lat_step - number of horizontal sections

// long_step - number of vertical sections

// draw_type - how the sphere is to be rendered

void DrawSphere(double radius, int lat_step, int long_step, bool lighting, int draw_type)
{
double DEGTORAD = 0.0174532925199432;
glPushMatrix();
glBegin(draw_type);

for (double i = 0; i < 180; i += 180/lat_step)
{
glTexCoord2d(0, i/180);
glVertex3d(radius * sin(i * DEGTORAD),
cos(i * DEGTORAD) * radius, 0.0f);

glTexCoord2d(0, (i + 180/lat_step)/180);
glVertex3d(radius * sin((i + 180/lat_step) * DEGTORAD),
cos((i + 180/lat_step) * DEGTORAD) * radius, 0.0f);
for (double j = 0; j < 360; j += 360/long_step)
{
if (lighting)
glNormal3d(cos(DEGTORAD * (j + 360/(long_step * 2))) * sin((i + 180/(lat_step * 2)) * DEGTORAD),
cos((i + 180/(lat_step * 2)) * DEGTORAD),
-sin(DEGTORAD * (j + 360/(long_step * 2))) * sin((i + 180/(lat_step * 2)) * DEGTORAD));

glTexCoord2d((j + 360/long_step)/360, i/180);
glVertex3d(cos(DEGTORAD * (j + 360/long_step)) * radius * sin(i * DEGTORAD),
cos(i * DEGTORAD) * radius,
-sin(DEGTORAD * (j + 360/long_step)) * radius * sin(i * DEGTORAD));

glTexCoord2d((j + 360/long_step)/360, (i + 180/lat_step)/180);
glVertex3d(cos(DEGTORAD * (j + 360/long_step)) * radius * sin((i + 180/lat_step) * DEGTORAD),
cos((i + 180/lat_step) * DEGTORAD) * radius,
-sin(DEGTORAD * (j + 360/long_step)) * radius * sin((i + 180/lat_step) * DEGTORAD));
}
}

glEnd();
glPopMatrix();
}


#4 Taboo Builder   Members   -  Reputation: 1034

Like
Likes
Like

Posted 23 October 2001 - 08:04 PM

Thanks!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS