kev

06-08-2000, 02:00 AM

Hello,

This has been driving me nuts for ages. I have a routine to draw a torus(or n degrees of it) but i cant work out how to generate normals for it.

Please can someone give me some help..

oh - and please dont say - 'just trace a ray' because i'm not all that sure what it means :(

here is the code for my routine (which i'm sure could be a bit more efficient...any advice welcome)

void CGLtoralSweep::Draw(float R, float r, int numr, int numR, float Sweep, GLenum mode)

{

/* dA1 = change in ang1

* dA2 = change in ang2

*/

float ang1,ang2;

float dA1 = 360/(numR*(360/Sweep));

float dA2 = 360/numr;

Sweep = Sweep/dA1;

numr++;

numR++;

for(int j=0;j<Sweep;j++)

{

glBegin(GL_LINES);

for(int i=0;i<=numr;i++)

{

ang1 = (j*dA1) * (PI/180);

for(int p=0;p<2;p++)

{

ang2 = (i*dA2) * (PI/180);

glColor3f(1.0,0.0,0.0);

float z = (R + r*cos(ang2))* cos(ang1);

float y = (R + r*cos(ang2))* sin(ang1);

float x = r*sin(ang2);

glVertex3f(x,y,z);

ang1 = ang1 + (dA1 * (PI/180));

}

}

glEnd();

}

}

thanks,

kev.

This has been driving me nuts for ages. I have a routine to draw a torus(or n degrees of it) but i cant work out how to generate normals for it.

Please can someone give me some help..

oh - and please dont say - 'just trace a ray' because i'm not all that sure what it means :(

here is the code for my routine (which i'm sure could be a bit more efficient...any advice welcome)

void CGLtoralSweep::Draw(float R, float r, int numr, int numR, float Sweep, GLenum mode)

{

/* dA1 = change in ang1

* dA2 = change in ang2

*/

float ang1,ang2;

float dA1 = 360/(numR*(360/Sweep));

float dA2 = 360/numr;

Sweep = Sweep/dA1;

numr++;

numR++;

for(int j=0;j<Sweep;j++)

{

glBegin(GL_LINES);

for(int i=0;i<=numr;i++)

{

ang1 = (j*dA1) * (PI/180);

for(int p=0;p<2;p++)

{

ang2 = (i*dA2) * (PI/180);

glColor3f(1.0,0.0,0.0);

float z = (R + r*cos(ang2))* cos(ang1);

float y = (R + r*cos(ang2))* sin(ang1);

float x = r*sin(ang2);

glVertex3f(x,y,z);

ang1 = ang1 + (dA1 * (PI/180));

}

}

glEnd();

}

}

thanks,

kev.