I am programming a raycasting algorithm in order to pick sphere from my opengl application. I ran into some problems. The direction of my rays are off and I am incapable of figuring out why.
The setup: The camera is initialised at the world positions 1,0,0 the up-vector is 0,1,0 and the right vector is 0,0,-1. It is possible to move the camera with an arcball algorithm. In order to cast the ray, i go from the screen space into the view space, which works fine.
ray_origin[0] = screen_coordinates[0]/d
ray_origin[1] = -screen_coordinates[1]/d * aspect_ratio
ray_origin[2] = -1.0
The problems comes, when I multiply the ray_origin with the inverse view_matrix. When is start moving the camera, the calculated directions are off. for instance the ray should be pointing toward -y but is point toward z and so on.
I hope the error is obvious! Thanks in advance.