Hi there:)
A camera angle is given and it is asked to calculate the direction of the rays coming out of each pixel (ray casting algorithm). The ray at the middle of the screen has the same direction as the camera and as the rays go toward the extremities of the screen, they spread out (they form something like a pyramid).
The direction of the rays should be in cartesian coordinates, versors i, j, k.
So far:
the angle that has to be added to each ray, on top of the camera angle:
ray_angle.x = Camera.fov * i/height - Camera.fov/2;
ray_angle.y = Camera.fov * j/width - Camera.fov/2;
fov=field of view of the camera (angle at the tip of the pyramid)
ray_angle.x = ray_angle.x + Camera.rotx;
ray_angle.y = ray_angle.z + Camera.roty;
and the change to i,j,k:
ray_direction.i=sin(ray_angle.x)*cos(ray_angle.y);
ray_direction.j=sin(ray_angle.x)*sin(ray_angle.y);
ray_direction.k=cos(ray_angle.x);
and that doesn't work at all...
the directions converted in images look like this:
i:
---------------]
-`````````````-]
*-```````````-*]
-``````-``````-]
``````-*-``````]
```````-```````]
---------------]
j:
---------------]
``-````````````]
`-*-```````````]
``-```````-````]
`````````-*-```]
``````````-````]
---------------]
k:
---------------]
```````````````]
-`-`-`-`-`-`-`-]
*`*`*`*`*`*`*`*]
-`-`-`-`-`-`-`-]
```````````````]
---------------]
-*- = greater values for the ray emerging from the respective pixels. The images are in gradients.
Can you help me with this? I'm not to good at maths.
Thank you :)