Kugel
Aus DGL Wiki
Port von [1]
procedure CreateSphere(c: TVector3f; r: Single; n: Integer); const TWOPI = PI*2; PID2 = PI/2; var i,j: Integer; theta1,theta2,theta3: Single; e,p:TVector3f; begin if (r < 0) then r := -r; if (n < 0) then n := -n; if (n < 4) or (r <= 0) then begin glBegin(GL_POINTS); glVertex3f(c[0],c[1],c[2]); glEnd; exit; end; for j:=0 to n div 2 do begin theta1 := j * TWOPI / n - PID2; theta2 := (j + 1) * TWOPI / n - PID2; glBegin(GL_QUAD_STRIP); for i:=0 to n do begin theta3 := i * TWOPI / n; e[0] := cos(theta2) * cos(theta3); e[1] := sin(theta2); e[2] := cos(theta2) * sin(theta3); p[0] := c[0] + r * e[0]; p[1] := c[1] + r * e[1]; p[2] := c[2] + r * e[2]; glNormal3f(e[0],e[1],e[2]); glTexCoord2f(i/n,2*(j+1)/n); glVertex3f(p[0],p[1],p[2]); e[0] := cos(theta1) * cos(theta3); e[1] := sin(theta1); e[2] := cos(theta1) * sin(theta3); p[0] := c[0] + r * e[0]; p[1] := c[1] + r * e[1]; p[2] := c[2] + r * e[2]; glNormal3f(e[0],e[1],e[2]); glTexCoord2f(i/n,2*j/n); glVertex3f(p[0],p[1],p[2]); end; glEnd; end; end;