Original Post
Hi guys,
I had a look about 15 pages back and could not find any help, also the search engine is under repairs so apologies if this has been answered previously.
I can put a provided texture on a cube but cannot get my head around how to load and wrap a bitmap texture around a torus.
From the tuts I have looked at the co-ords will be dynamically generated.
Solutions/hints in general will be gratly appreciated, solutions/hints in GL4Java will be forever immortalised. ;-)
My Torus code is below.
void torus(float A, float B, float C, float D, int nsides, int rings){
int i,j;
float u; //u is angle of rotation around z-axis
float v; //v is the angle parameter for an ellipse
float du, dv; //size of the increment of u and v
float cosu, sinu;
float cosudu, sinudu; //cosudv = cos(u+du)
float cosv, sinv;
float cosvdv, sinvdv;
du = 2.0f * M_PI / nsides;
dv = 2.0f * M_PI / rings;
//loops to go here
//outer loop iterates over u
u = -M_PI;
for (i = nsides - 1; i >= 0; i--) {
cosu = (float)Math.cos(u);
sinu = (float)Math.sin(u);
cosudu = (float)Math.cos(u+du);
sinudu = (float)Math.sin(u+du);
//the inner loop iterates over v
v = -M_PI/2;
for (j = rings; j >= 0; j--) {
cosv = (float)Math.cos(v);
sinv = (float)Math.sin(v);
cosvdv = (float)Math.cos(v+dv);
sinvdv = (float)Math.sin(v+dv);
//vertices will be evaluated here
gl.glBegin( GL_QUADS );
gl.glNormal3f((D + A*cosv)*cosv*cosu, (D + A*cosv)*cosv*sinu, (D + A*cosv)*sinv);
gl.glVertex3f((D+A*cosv)*cosu, (D+A*cosv)*sinu, A*sinv);
gl.glVertex3f((D+A*cosv)*cosudu, (D+A*cosv)*sinudu, A*sinv);
gl.glVertex3f((D+A*cosvdv)*cosudu, (D+A*cosvdv)*sinudu, A*sinvdv);
gl.glVertex3f((D+A*cosvdv)*cosu, (D+A*cosvdv)*sinu, A*sinvdv);
gl.glEnd();
v += dv;
}
u += du;
}
}
Cheers and Thanks.