I found code to draw my torus but it does light it and I am having some problems with my normals. Can somebody help me out or suggest another torus equation.

here’s the code:

var

i, j, k: integer;

s, t, x, y, z, twopi: double;

numc,numt:integer;

begin

numc:=64;numt:=64;

twopi := 2 * 3.14159;

for i := 0 to numc do

begin

for j := 0 to numt do

begin

for k := 1 downto 0 do

begin

s := (i + k) mod numc + 0.5;

t := j mod numt;

theTorus[i][j][k][0] := (1+(1-0.75)*cos(s*twopi/numc))*cos(t*twopi/numt);

theTorus[i][j][k][1] := (1+(1-0.75)*cos(s*twopi/numc))*sin(t*twopi/numt);

theTorus[i][j][k][2] := (1-0.75) * sin(s * twopi / numc);

```
end;
end;
end;
```

creates a torus with 64 sections and 64pieces to each section.

here’s the normal stuff:

procedure calcNormal(x,y,z:integer);

var

p1: array [0…2] of Double;

p2: array [0…2] of Double;

v1: array [0…2] of Double;

v2: array [0…2] of Double;

normal: array [0…2] of Double;

begin

//calc point 1

p1[0] := theTorus[x+1][y][z][0];

p1[1] := theTorus[x+1][y][z][1];

p1[2] := theTorus[x+1][y][z][2];

```
//calc point 2
p2[0] := theTorus[x][y+1][z][0];
p2[1] := theTorus[x][y+1][z][1];
p2[2] := theTorus[x][y+1][z][2];
//calc v1
v1[0]:=(p1[0]-theTorus[x][y][z][0]);
v1[1]:=(p1[1]-theTorus[x][y][z][1]);
v1[2]:=(p1[2]-theTorus[x][y][z][2]);
//calc v2
v2[0]:=(p2[0]-theTorus[x][y][z][0]);
v2[1]:=(p2[1]-theTorus[x][y][z][1]);
v2[2]:=(p2[2]-theTorus[x][y][z][2]);
//calc normal
normal[0] := (v1[1]*v2[2])-(v1[2]*v2[1]);
normal[1] := (v1[0]*v2[2])-(v1[2]*v2[0]);
normal[2] := (v1[0]*v2[1])-(v1[1]*v2[0]);
//set normal
glNormal3fv(@normal);
end;
```

Any assistance would be greatly appreciated