PDA

View Full Version : Texture coordinates for a torus



Brainer
02-12-2007, 06:09 AM
System: Windows XP SP1, Pentium D 805 2,66 GHz 2 GB RAM, GeForce 7600 GS
Compiler/IDE: Delphi 2007
Libraries/API: JEDI-SDL
---

Hello there! :)

I've found this code somewhere to render a torus:

procedure TTorus.Render;
var
I, J: Integer;
theta, phi, theta1: Single;
cosTheta, sinTheta: Single;
cosTheta1, sinTheta1: Single;
ringDelta, sideDelta: Single;
cosPhi, sinPhi, dist: Single;
begin
glTranslatef(FPos.X, FPos.Y, FPos.Z);
glRotatef(FAngle, FRot.X, FRot.Y, FRot.Z);
glScalef(FScale.X, FScale.Y, FScale.Z);

sideDelta := 2.0 * PI / FSides;
ringDelta := 2.0 * PI / FRings;
theta := 0.0;
cosTheta := 1.0;
sinTheta := 0.0;

for I := FRings -1 downto 0 do
begin
theta1 := theta + ringDelta;
cosTheta1 := Cos(theta1);
sinTheta1 := Sin(theta1);

glBegin(GL_QUAD_STRIP);
phi := 0.0;
for J := FSides downto 0 do
begin
phi := phi + sideDelta;
cosPhi := Cos(phi);
sinPhi := Sin(phi);
dist := FRadius + (FTubeRadius * cosPhi);

glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
//glTexCoord2f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi);
glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, FTubeRadius * sinPhi);

glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
//glTexCoord2f(cosTheta * cosPhi, -sinTheta * cosPhi);
glVertex3f(cosTheta * dist, -sinTheta * dist, FTubeRadius * sinPhi);
end;
glEnd();

theta := theta1;
cosTheta := cosTheta1;
sinTheta := sinTheta1;
end;
end;


I've got a problem with setting up the texture coordinates. As you can see, I've tried to do it before, but I couldn't make it. :( Can you help me?

Thanks in advance! :)