Sign in to follow this  
dan59314

Spherical Mapping problem

Recommended Posts

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: [img] http://dan59314.myweb.hinet.net/sphereMapping01.jpg [/img] Image 2: [img] http://dan59314.myweb.hinet.net/sphereMapping02.jpg [/img] 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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this