Аппроксимация сферы треугольниками
Автор: Dmitry Pryadkin
procedure CreateSphere(var mlist: glUint; CX, CY, CZ, Radius : glFloat; N : Integer); var I, J : Integer; theta1,theta2,theta3 : glFloat; X, Y, Z, px, py, pz : glFloat; begin mlist :=glGenLists( 1); glNewList( mlist, GL_COMPILE); if Radius < 0 then Radius :=-Radius; if n < 0 then n := -n; if ( n < 4) OR ( Radius <= 0) then begin glBegin( GL_POINTS); glVertex3f( CX, CY, CZ); glEnd( ); exit; end; for J :=0 to N DIV 2 -1 do begin theta1 := J*2*PI/N - PI/2; theta2 := ( J+1)*2*PI/n - PI/2; glBegin( GL_QUAD_STRIP); For I :=0 to N do begin theta3 := i*2*PI/N; x := cos( theta2) * cos( theta3); y := sin( theta2); z := cos( theta2) * sin( theta3); px := CX + Radius*x; py := CY + Radius*y; pz := CZ + Radius*z; glTexCoord2f( 1-I/n, 2*( J+1)/n); glVertex3f( px,py,pz); X := cos( theta1) * cos( theta3); Y := sin( theta1); Z := cos( theta1) * sin( theta3); px := CX + Radius*X; py := CY + Radius*Y; pz := CZ + Radius*Z; glTexCoord2f( 1-i/n, 2*j/n); glVertex3f( px,py,pz); end; glEnd( ); end; glEndList( ); end;
29 марта 2004