I'am creating my first ray tracing program in C and I'am currently trying to rotate the camera. Basically , change the direction of the ray origin.
I already have a ray direction, which is a vector and I want to apply a rotation matrix to this Vector.
void render(void)
{
t_Color color;
int x;
int y;
t_Vector d;
x = ((canvas()->width / 2) * -1);
y = (canvas()->height / 2);
while (--y >= (canvas()->height / 2) * -1)
{
while (++x <= (canvas()->width / 2))
{
d = canvas_to_viewport(x, y);
color = trace_ray(d, 1, INT_MAX);
put_pixel(x, y, color);
}
x = ((canvas()->width / 2) * -1);
}
}
What I want to do is basically, change this line :
// d represents the ray direction
d = canvas_to_viewport(x, y);
to
// d represents the ray direction after rotating
d = rotation_matrix * canvas_to_viewport(x, y);
My program will receive some input in the form of :
3d normalized orientation vector. In range [-1,1] for each x,y,z axis:
0.0, 0.0, 1.0
Those coordinates should indicate the orientation for my camera. I must admit linear algebra is not my strongest point, so I would like to know how can I convert those orientation coordinates into a rotation matrix and how to multiply it by a vector to get another vector , hopefully, indicating the new direction.