|
Post by grumpyrobot on Jan 16, 2021 22:59:02 GMT
Implementing the raytracer in C as a school project.
The project requires the camera settings to be input through a text file, which is parsed and used by the program. The camera receives parameters for it's position in space as X Y Z coordinates, camera orientation as normalized vector coordinates, and field of vision as a double.
When the camera orientation values are 0, X, 0 i.e. only defining orientation on the Y axis, the true_up value in the view_transform function ends up being zero, which leads the camera transformation matrix to be a singular matrix i.e. a matrix that cannot be inverted. As the program relies on inverting matrixes to be able to cast rays, it ends up crashing. My question is, what should I do with this case of having a value that results in a singular matrix with a determinant of zero?
My invert_matrix function:t_matrix invert_matrix(t_matrix mat) { t_matrix new; t_matrix transp; double det; size_t i; size_t j;
new = create_matrix(mat.row, mat.col); det = det_4x4(mat); i = 0; while (i < mat.row) { j = 0; while (j < mat.col) { new.matrix[i][j] = cofactor_4x4(mat, i, j); j++; } i++; } transp = transpose_matrix(new); free_matrix(new); new = scalar_matrix(transp, 1 / det); free_matrix(transp); return (new); } My view_transform function:
t_matrix view_transform(t_tuple from, t_tuple to, t_tuple up) { t_tuple forward; t_tuple up_normal; t_tuple left; t_tuple true_up;
forward = normalize_v(subtract_tuple(to, from)); up_normal = normalize_v(up); left = cross_product(forward, up_normal); true_up = cross_product(left, forward); return (calculate_orientation(left, true_up, forward, from)); } Thanks!
|
|
|
Post by pacellie on Jan 17, 2021 20:51:58 GMT
I assume you have this problem for a matrix constructed by calling `view_transform((0, y, 0), (0, 0, 0), (0, 1, 0))`. If that is the case then you need to change your `up` vector. Since the camera is looking straight down, `up` with respect to the camera would be either `(1, 0, 0)` or `(0, 0, 1)` or some linear combination.
|
|
|
Post by elorchi on Jan 18, 2021 9:10:23 GMT
Hello i think you are one of 42 students cause i am in the same project as you i think the solution is to test if the up vector and the calculated forward vector are perpendicular if so you ll need too change the up. to be (1,1,0) or something like that this is my login if you want to contact me eel-orch
|
|