Here, I'm trying to add ray-casting into a real 3D scene. As we know, in ray-casting, in order to cast the ray, we need to get the direction of ray. The first point in the ray is the start point of ray which I can get from glLookAt. The second point in the ray is each point in the screen. In the original CUDA ray-casting SDK, it gets the screen point in the Kernel Function by the code below:
uint x = blockIdx.x*blockDim.x + threadIdx.x;
uint y = blockIdx.y*blockDim.y + threadIdx.y;
(x,y) is the screen space coordinate right? So now I need to translate (x, y) into a world space coordinate. A nice guy told me use gluUnProject to do this job. Good thinking! However I cannot call OpenGL function in the CUDA kernel.
Maybe I can use a invertible matrix to do the translation. But I'm not sure about the right way. Is there anybody could give me a hint about how to translate screen coordinate to world coordinate in the CUDA kernel function?