In article <48***********************@news.sunsite.dk>,
af*@asd.com
says...
[ ... ]
Ok but how would you generate the data for a wireframe model of a sphere
from C++?
It depends on the exact sort of wire-frame you want. Obvious choices are
latitude-like lines, longitude-like lines, or both. Here's a bit of code
to generate some points that approximate a wire-frame (i.e. the points
are close together, but not really connected).
double d2r(double degrees) {
const double conversion = 3.1416f/180.0f;
return degrees * conversion;
}
void Sphere(double radius) {
for (int latitude=-90; latitude<90; latitude++) {
double current_radius = cos(d2r(latitude)) * radius;
double z = sin(d2r(latitude)) * radius;
// Every 10 degrees of latitude, draw a longitude line.
// Otherwise, draw a point every 10 degrees of longitude.
int increment = latitude % 10 ? 10 : 1;
for (int longitude=0; longitude<360; longitude+=increment) {
double x = cos(d2r(longitude))*current_radius;
double y = sin(d2r(longitude))*current_radius;
// (x,y,z) is a point in the wireframe
}
}
}
--
Later,
Jerry.
The universe is a figment of its own imagination.