I have got a sphere in my world space. I don't understand how can i find my sphere using my X and Y on my screen, because i don't understand what the value Z of my ray assuming the fact that we use world coordinate system.
Raytracing is an algorithm, that is a recipe, or series of steps to achieve a result, like so:
For each pixel in final image, loop 1. Convert pixel direction (x0, y0, 1) to world space direction (x1,y1,z1) using inverse view transform 2. using the new ray direction, perform collision detection 3. sort the list of hits in ascending order, and choose the lowest distance. 4. get information (colour etc) from the hit data. 5. If (lighting) do lighting calculations #optional 6. while (reflectionsEnabled AND rayCount < maxRays) loop #optional 6a. compute reflected ray 6b. repeat steps 2-5 and add to result 6c. Increment rayCount. end while loop 7. while (refractionsEnabled) loop #optional 7a. Compute refracted ray. 7b. repeat steps 2-6 and add to result end while loop assign result to image at coordinates (x0,y0) end for loop
Ignore steps 5-7 until you are ready for them, but remember that a good raytracer should be able to do them.
This algorithm requires a change of coordinate system (view space to world space). To do this, you need to know a little matrix mathematics, in particular, homogeneous coordinate systems and affine transformations. A little vector mathematics wouldn't hurt either.
You will have to generate a view space transform, then compute the inverse of it (fortunately only once for a frame), and use that to transform your (x * y) parallel ray directions into world space.
You will then need a starting point in world space for each of your rays.
You then compute a ray of [max ray distance] length, and use it to compute ray vs sphere collision detection. In your case, a single sphere, once you have worked out if you have a hit or not, you can do the colouring of the pixel.
If you want to do fancier stuff, you will need the collision normal vector, distance from the origin point, light direction etc, in order to perform realistic lighting, but don't worry about that for now.
You don't "find" the sphere, as you are not looking for it. If a ray hits it, then you update the pixel with it's colour. If not, leave the pixel black.