   texturing on sphere
  hello there,i've been trying to write my first ray tracer and i have come to the point of texture mapping. i have a sphere to cover with a checkerboard texture and im stuck at one point.i know the intersection point between the ray and the sphere and im trying to calculate u and v, the texture coordinates. im using a frame size of 300x300 and 0,0,0 point is the left-most bottom pixel of the frame.im trying to find out an exact formula for u and v but im desperate, i can't find a working one..can anyone help please?thanks..   
  It depends on your texture mapping scheme.  I'll describe the usual "latitude-longitude" projection here.Say your sphere is defined by,Position: c = (cx, cy, cz)Radius: rOrientation: R (rotation matrix)and you've found a point p on the sphere using a ray-sphere intersection test.  Then u,v coordinates for p can be found by1. Computing d = R-1(p-c).2. Converting d to spherical coordinates (r, theta, phi).The u,v coordinates are (theta,phi).More on step 2: It's  done using a two-argument arctangent function.  Google "spherical coordinates" and you'll figure it out.   ;  did you try with this formula..int i;for( i = 0; i < numOfVertices; i++ ){   vertex->u = vertex->nx / (sqrt(vertex->nx*vertex->nx + vertex->ny*vertex->ny + vertex->nz*vertex->nz));   vertex->v = vertex->ny / (sqrt(vertex->nx*vertex->nx + vertex->ny*vertex->ny + vertex->nz*vertex->nz));   vertex++;}where u,v are texture coordinates andnx,ny,nz are normals of each vertex   