Original Post
Hi, I use following to convert Cartesian to Spherical system to generate texture coordinats for my sphere model, but error on some parts. Can someone help? Image 1:
Image 2:
procedure Cartesian2Spherical(const dx,dy,dz:GLFloat; var scRad, scPhi, scTheta:Glfloat); begin scRad:=sqrt(dx*dx + dy*dy + dz*dz); if (dy>0.0) then scPhi:=ArcCos(dy/scRad) else scPhi:=PI-ArcCos(-dy/scRad); if (dx=0.0) and (dz>0.0) then scTheta:=PIdiv2; if (dx=0.0) and (dz<0.0) then scTheta:=PI+PIdiv2; if (dx>0.0) and (dz=0.0) then scTheta:=0.0; if (dx<0.0) and (dz=0.0) then scTheta:=PI; if (dx<>0.0) and (dy<>0.0) then begin if (dx>0.0) and (dz>0.0) then ang :=0.0; if (dx<0.0) and (dz>0.0) then ang :=PI; if (dx<0.0) and (dz<0.0) then ang :=PI; if (dx>0.0) and (dz<0.0) then ang :=PI2; scTheta:=ArcTan(dz/dx)+ang; end; end; texturecoord.s := scTheta / _2PI; texturecoord.t := (PI-scPhi) / PI; Thanks a lot, Daniel
Image 2:
procedure Cartesian2Spherical(const dx,dy,dz:GLFloat; var scRad, scPhi, scTheta:Glfloat); begin scRad:=sqrt(dx*dx + dy*dy + dz*dz); if (dy>0.0) then scPhi:=ArcCos(dy/scRad) else scPhi:=PI-ArcCos(-dy/scRad); if (dx=0.0) and (dz>0.0) then scTheta:=PIdiv2; if (dx=0.0) and (dz<0.0) then scTheta:=PI+PIdiv2; if (dx>0.0) and (dz=0.0) then scTheta:=0.0; if (dx<0.0) and (dz=0.0) then scTheta:=PI; if (dx<>0.0) and (dy<>0.0) then begin if (dx>0.0) and (dz>0.0) then ang :=0.0; if (dx<0.0) and (dz>0.0) then ang :=PI; if (dx<0.0) and (dz<0.0) then ang :=PI; if (dx>0.0) and (dz<0.0) then ang :=PI2; scTheta:=ArcTan(dz/dx)+ang; end; end; texturecoord.s := scTheta / _2PI; texturecoord.t := (PI-scPhi) / PI; Thanks a lot, Daniel