Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :)
Posted
Updated 4-Sep-10 12:27pm
v4
Comments
AspDotNetDev 4-Sep-10 18:29pm    
I added PRE tags with the lang attribute set to "text". That gives you a fixed-width font so your "images" (as you call them) line up.

1 solution

still not working...
The fov is 360, so a complete sphere.

the i should be like a X, the triangles in the sides lighter and the ones at the top darker, in gradient. j like a horizontal bar, dark at the center and lit at the top and bottom. k more complicated:
00000
01010
14141
01010
00000

can you help with this?

the ray cast result is something like 4 circles, there can be seen the same fragment of the scene in all of them, but with different orientations (mirrored, rotated). As the position changes some spheres grow, other deflate until their position changes, they touch one another and at the intersection, another part of the scene can be seen.
 
Share this answer
 
Comments
Mihai Zaharescu 6-Sep-10 14:33pm    
should I have improved the question? Sorry, I'm new here...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900