Graphics assignment 6 part 1 is almost finished.

parent 1596b66a
/* Computer Graphics, Assignment, Ray-tracing 1
*
* Student name ....
* Student email ...
* Collegekaart ....
* Student name .... Sander van Veen, Taddeüs Kroes
* Student email ... sander@vo20.nl, taddeuskroes@gmail.com
* Collegekaart .... 6167969,
* Date ............
* Comments ........
*
*
* (always fill in these fields before submitting!!)
*/
#include <sys/time.h>
......@@ -167,7 +164,8 @@ ray_trace(void)
// Compute camera coordinate system from camera position
// and look-at point
up_vector = v3_create(0, 0, 1);
forward_vector = v3_normalize(v3_subtract(scene_camera_lookat, scene_camera_position));
forward_vector = v3_normalize(v3_subtract(scene_camera_lookat,
scene_camera_position));
right_vector = v3_normalize(v3_crossprod(forward_vector, up_vector));
up_vector = v3_crossprod(right_vector, forward_vector);
......@@ -175,26 +173,69 @@ ray_trace(void)
// and image aspect ratio. This is the size of the plane at distance
// of one unit from the camera position.
image_plane_height = 2.0 * tan(0.5*VFOV/180*M_PI);
image_plane_width = image_plane_height * (1.0 * framebuffer_width / framebuffer_height);
image_plane_width = image_plane_height * (1.0 * framebuffer_width
/ framebuffer_height);
float l = image_plane_width * .5f, // measured from e along right_vector
r = -l,
b = image_plane_height * .5f, // measured from e along up_vector
t = -b;
float u, v;
// ...
// ...
// ...
float frame_height_div = 1.0 / framebuffer_height,
frame_width_div = 1.0 / framebuffer_width;
up_vector = v3_normalize(up_vector);
vec3 ray_o = scene_camera_position,
ray_d = forward_vector;
// e = scene_camera_position;
// e = v3_subtract(scene_camera_lookat, scene_camera_position);
// Loop over all pixels in the framebuffer
for (j = 0; j < framebuffer_height; j++)
for( j = 0; j < framebuffer_height; j++ )
{
for (i = 0; i < framebuffer_width; i++)
for( i = 0; i < framebuffer_width; i++ )
{
// ...
// ...
// ...
// compute viewing ray
//u = l + (r - l) * (i + 0.5) * frame_width_div;
//v = b + (t - b) * (j + 0.5) * frame_height_div;
// One unit distance, adjust to plane center and normalize
ray_d = v3_normalize(v3_create(
((i + .5f) * frame_width_div) + r,
((framebuffer_height - j + .5f) * frame_height_div) + t,
1.f
));
ray_d = v3_create(
right_vector.x * ray_d.x + up_vector.x * ray_d.y
+ forward_vector.x * ray_d.z,
right_vector.y * ray_d.x + up_vector.y * ray_d.y
+ forward_vector.y * ray_d.z,
right_vector.z * ray_d.x + up_vector.z * ray_d.y
+ forward_vector.z * ray_d.z
);
//ray_d = v3_normalize(v3_add(
// ray_o,
// v3_add(v3_multiply(right_vector, u), v3_multiply(up_vector, v))
//));
//if( i == 0 && j < 20 )
// printf("d: [%f, %f, %f]\n", ray_d.x, ray_d.y, ray_d.z);
//ray_origin = v3_add(e, v3_add(v3_multiply(right_vector, u),
// v3_multiply(up_vector, v)));
color = ray_color(0, ray_o, ray_d);
// Output pixel color
put_pixel(i, j, color.x, color.y, color.z);
}
sprintf(buf, "Ray-tracing ::: %.0f%% done", 100.0*j/framebuffer_height);
sprintf(buf, "Ray-tracing ::: %.0f%% done",
100.0 * j / framebuffer_height);
glutSetWindowTitle(buf);
}
......@@ -522,7 +563,6 @@ motion_func(int x, int y)
}
}
int
main(int argc, char **argv)
{
......
This diff is collapsed.
ply
format ascii 1.0
comment Created by Blender3D 247 - www.blender.org, source file: rt3.blend
element vertex 33
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 16
property list uchar uint vertex_indices
end_header
0.617256 -0.000000 0.662460 0.838717 0.347408 0.419359
0.436466 0.436466 0.662460 0.838717 0.347408 0.419359
0.000000 0.000000 1.896971 0.838717 0.347408 0.419359
0.000000 0.000000 1.896971 0.838717 -0.347408 0.419359
0.436466 -0.436466 0.662460 0.838717 -0.347408 0.419359
0.617256 -0.000000 0.662460 0.838717 -0.347408 0.419359
0.000000 0.000000 1.896971 0.347408 -0.838717 0.419359
-0.000000 -0.617256 0.662460 0.347408 -0.838717 0.419359
0.436466 -0.436466 0.662460 0.347408 -0.838717 0.419359
0.000000 0.000000 1.896971 -0.347408 -0.838717 0.419359
-0.436466 -0.436465 0.662460 -0.347408 -0.838717 0.419359
-0.000000 -0.617256 0.662460 -0.347408 -0.838717 0.419359
0.000000 0.000000 1.896971 -0.838717 -0.347408 0.419359
-0.617256 0.000000 0.662460 -0.838717 -0.347408 0.419359
-0.436466 -0.436465 0.662460 -0.838717 -0.347408 0.419359
0.000000 0.000000 1.896971 -0.838717 0.347408 0.419358
-0.436466 0.436465 0.662460 -0.838717 0.347408 0.419358
-0.617256 0.000000 0.662460 -0.838717 0.347408 0.419358
0.000000 0.000000 1.896971 -0.347408 0.838717 0.419359
-0.000000 0.617256 0.662460 -0.347408 0.838717 0.419359
-0.436466 0.436465 0.662460 -0.347408 0.838717 0.419359
0.000000 0.000000 1.896971 0.347408 0.838717 0.419358
0.436466 0.436466 0.662460 0.347408 0.838717 0.419358
-0.000000 0.617256 0.662460 0.347408 0.838717 0.419358
0.000000 0.000000 0.662460 -0.000000 0.000000 -1.000000
0.436466 0.436466 0.662460 -0.000000 0.000000 -1.000000
0.617256 -0.000000 0.662460 -0.000000 0.000000 -1.000000
0.436466 -0.436466 0.662460 0.000000 0.000000 -1.000000
-0.000000 -0.617256 0.662460 0.000000 0.000000 -1.000000
-0.436466 -0.436465 0.662460 0.000000 0.000000 -1.000000
-0.617256 0.000000 0.662460 0.000000 0.000000 -1.000000
-0.436466 0.436465 0.662460 0.000000 -0.000000 -1.000000
-0.000000 0.617256 0.662460 0.000000 -0.000000 -1.000000
3 0 1 2
3 3 4 5
3 6 7 8
3 9 10 11
3 12 13 14
3 15 16 17
3 18 19 20
3 21 22 23
3 24 25 26
3 24 26 27
3 24 27 28
3 24 28 29
3 24 29 30
3 24 30 31
3 24 31 32
3 32 25 24
This diff is collapsed.
ply
format ascii 1.0
comment Created by Blender3D 246 - www.blender.org, source file: rt3.blend
element vertex 28
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 10
property list uchar uint vertex_indices
end_header
-0.335900 -0.208247 0.711887 -0.392166 0.919895 0.000001
-0.335901 -0.208247 0.000000 -0.392166 0.919895 0.000001
-0.990118 -0.487150 0.000000 -0.392166 0.919895 0.000001
-0.335900 -0.208247 0.711887 -0.392166 0.919894 0.000001
-0.990118 -0.487150 0.000000 -0.392166 0.919894 0.000001
-0.990118 -0.487151 0.711887 -0.392166 0.919894 0.000001
-0.711214 -1.141368 0.000000 -0.919895 -0.392166 -0.000001
-0.711215 -1.141368 0.711887 -0.919895 -0.392166 -0.000001
-0.990118 -0.487151 0.711887 -0.919895 -0.392166 -0.000001
-0.711214 -1.141368 0.000000 -0.919894 -0.392166 -0.000001
-0.990118 -0.487151 0.711887 -0.919894 -0.392166 -0.000001
-0.990118 -0.487150 0.000000 -0.919894 -0.392166 -0.000001
-0.056997 -0.862464 0.000000 0.392167 -0.919894 -0.000001
-0.056997 -0.862465 0.711887 0.392167 -0.919894 -0.000001
-0.711214 -1.141368 0.000000 0.392167 -0.919894 -0.000001
-0.056997 -0.862465 0.711887 0.392165 -0.919895 0.000001
-0.711215 -1.141368 0.711887 0.392165 -0.919895 0.000001
-0.711214 -1.141368 0.000000 0.392165 -0.919895 0.000001
-0.335901 -0.208247 0.000000 0.919894 0.392167 -0.000001
-0.335900 -0.208247 0.711887 0.919894 0.392167 -0.000001
-0.056997 -0.862464 0.000000 0.919894 0.392167 -0.000001
-0.335900 -0.208247 0.711887 0.919895 0.392165 0.000001
-0.056997 -0.862465 0.711887 0.919895 0.392165 0.000001
-0.056997 -0.862464 0.000000 0.919895 0.392165 0.000001
-0.335900 -0.208247 0.711887 0.000000 -0.000000 1.000000
-0.990118 -0.487151 0.711887 0.000000 -0.000000 1.000000
-0.711215 -1.141368 0.711887 0.000000 -0.000000 1.000000
-0.056997 -0.862465 0.711887 0.000000 -0.000000 1.000000
3 0 1 2
3 3 4 5
3 6 7 8
3 9 10 11
3 12 13 14
3 15 16 17
3 18 19 20
3 21 22 23
3 24 25 26
3 24 26 27
This source diff could not be displayed because it is too large. You can view the blob instead.
ply
format ascii 1.0
comment Created by Blender3D 246 - www.blender.org, source file: rt3.blend
element vertex 34
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 16
property list uchar uint vertex_indices
end_header
1.526115 1.526115 0.000000 0.000000 -0.000000 1.000000
-1.526115 -1.526115 0.000000 0.000000 -0.000000 1.000000
1.526115 -1.526115 0.000000 0.000000 -0.000000 1.000000
-1.526115 1.526116 0.000000 -0.000000 0.000000 1.000000
1.526115 1.526115 0.000000 0.000000 0.000000 0.000000
1.526115 -1.526115 0.000000 0.000000 0.000000 0.000000
1.526115 -1.526115 0.000000 0.000000 0.000000 0.000000
1.526115 1.526115 0.000000 0.000000 0.000000 0.000000
-1.526115 1.526116 0.000000 0.000000 0.000000 0.000000
-1.526115 1.526116 0.000000 0.000000 0.000000 0.000000
-1.526115 -1.526115 0.000000 0.000000 0.000000 0.000000
-1.526115 -1.526115 0.000000 0.000000 0.000000 0.000000
-1.526115 -1.526115 0.000000 -0.867699 0.000000 0.497089
-1.526115 1.526116 0.000000 -0.867699 0.000000 0.497089
-1.868441 1.868442 -0.597550 -0.867699 0.000000 0.497089
-1.868441 -1.868441 -0.597550 -0.867699 0.000000 0.497089
1.526115 -1.526115 0.000000 0.000000 -0.867699 0.497090
-1.526115 -1.526115 0.000000 0.000000 -0.867699 0.497090
-1.868441 -1.868441 -0.597550 0.000000 -0.867699 0.497090
1.526115 -1.526115 0.000000 0.000000 -0.867699 0.497089
-1.868441 -1.868441 -0.597550 0.000000 -0.867699 0.497089
1.868441 -1.868441 -0.597550 0.000000 -0.867699 0.497089
-1.526115 1.526116 0.000000 0.000000 0.867699 0.497089
1.526115 1.526115 0.000000 0.000000 0.867699 0.497089
1.868441 1.868441 -0.597550 0.000000 0.867699 0.497089
-1.868441 1.868442 -0.597550 0.000000 0.867699 0.497089
1.526115 1.526115 0.000000 0.867699 -0.000000 0.497089
1.526115 -1.526115 0.000000 0.867699 -0.000000 0.497089
1.868441 -1.868441 -0.597550 0.867699 -0.000000 0.497089
1.868441 1.868441 -0.597550 0.867699 0.000000 0.497089
1.868441 1.868441 -0.597550 0.000000 0.000000 -1.000000
-1.868441 -1.868441 -0.597550 0.000000 0.000000 -1.000000
-1.868441 1.868442 -0.597550 0.000000 0.000000 -1.000000
1.868441 -1.868441 -0.597550 0.000000 0.000000 -1.000000
3 0 1 2
3 0 3 1
4 4 5 6 7
4 8 4 7 9
4 5 10 11 6
4 10 8 9 11
3 12 13 14
3 12 14 15
3 16 17 18
3 19 20 21
3 22 23 24
3 22 24 25
3 26 27 28
3 26 28 29
3 30 31 32
3 30 33 31
This diff is collapsed.
ply
format ascii 1.0
comment Created by Blender3D 246 - www.blender.org, source file:
element vertex 60
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 20
property list uchar uint vertex_indices
end_header
-0.276385 -0.850640 -0.447215 0.187597 -0.577354 -0.794651
0.000000 0.000000 -1.000000 0.187597 -0.577354 -0.794651
0.723600 -0.525720 -0.447215 0.187597 -0.577354 -0.794651
0.723600 -0.525720 -0.447215 0.607065 0.000000 -0.794652
0.000000 0.000000 -1.000000 0.607065 0.000000 -0.794652
0.723600 0.525720 -0.447215 0.607065 0.000000 -0.794652
-0.894425 0.000000 -0.447215 -0.491122 -0.356829 -0.794652
0.000000 0.000000 -1.000000 -0.491122 -0.356829 -0.794652
-0.276385 -0.850640 -0.447215 -0.491122 -0.356829 -0.794652
-0.276385 0.850640 -0.447215 -0.491122 0.356829 -0.794652
0.000000 0.000000 -1.000000 -0.491122 0.356829 -0.794652
-0.894425 0.000000 -0.447215 -0.491122 0.356829 -0.794652
0.723600 0.525720 -0.447215 0.187597 0.577354 -0.794651
0.000000 0.000000 -1.000000 0.187597 0.577354 -0.794651
-0.276385 0.850640 -0.447215 0.187597 0.577354 -0.794651
0.723600 -0.525720 -0.447215 0.982246 0.000000 -0.187597
0.723600 0.525720 -0.447215 0.982246 0.000000 -0.187597
0.894425 0.000000 0.447215 0.982246 0.000000 -0.187597
-0.276385 -0.850640 -0.447215 0.303536 -0.934172 -0.187589
0.723600 -0.525720 -0.447215 0.303536 -0.934172 -0.187589
0.276385 -0.850640 0.447215 0.303536 -0.934172 -0.187589
-0.894425 0.000000 -0.447215 -0.794649 -0.577359 -0.187587
-0.276385 -0.850640 -0.447215 -0.794649 -0.577359 -0.187587
-0.723600 -0.525720 0.447215 -0.794649 -0.577359 -0.187587
-0.276385 0.850640 -0.447215 -0.794649 0.577359 -0.187587
-0.894425 0.000000 -0.447215 -0.794649 0.577359 -0.187587
-0.723600 0.525720 0.447215 -0.794649 0.577359 -0.187587
0.723600 0.525720 -0.447215 0.303536 0.934172 -0.187589
-0.276385 0.850640 -0.447215 0.303536 0.934172 -0.187589
0.276385 0.850640 0.447215 0.303536 0.934172 -0.187589
0.894425 0.000000 0.447215 0.794649 -0.577359 0.187587
0.276385 -0.850640 0.447215 0.794649 -0.577359 0.187587
0.723600 -0.525720 -0.447215 0.794649 -0.577359 0.187587
0.276385 -0.850640 0.447215 -0.303536 -0.934172 0.187589
-0.723600 -0.525720 0.447215 -0.303536 -0.934172 0.187589
-0.276385 -0.850640 -0.447215 -0.303536 -0.934172 0.187589
-0.723600 -0.525720 0.447215 -0.982246 0.000000 0.187597
-0.723600 0.525720 0.447215 -0.982246 0.000000 0.187597
-0.894425 0.000000 -0.447215 -0.982246 0.000000 0.187597
-0.723600 0.525720 0.447215 -0.303536 0.934172 0.187589
0.276385 0.850640 0.447215 -0.303536 0.934172 0.187589
-0.276385 0.850640 -0.447215 -0.303536 0.934172 0.187589
0.276385 0.850640 0.447215 0.794649 0.577359 0.187587
0.894425 0.000000 0.447215 0.794649 0.577359 0.187587
0.723600 0.525720 -0.447215 0.794649 0.577359 0.187587
0.276385 -0.850640 0.447215 0.491122 -0.356829 0.794652
0.894425 0.000000 0.447215 0.491122 -0.356829 0.794652
0.000000 0.000000 1.000000 0.491122 -0.356829 0.794652
-0.723600 -0.525720 0.447215 -0.187597 -0.577354 0.794651
0.276385 -0.850640 0.447215 -0.187597 -0.577354 0.794651
0.000000 0.000000 1.000000 -0.187597 -0.577354 0.794651
-0.723600 0.525720 0.447215 -0.607065 0.000000 0.794652
-0.723600 -0.525720 0.447215 -0.607065 0.000000 0.794652
0.000000 0.000000 1.000000 -0.607065 0.000000 0.794652
0.276385 0.850640 0.447215 -0.187597 0.577354 0.794651
-0.723600 0.525720 0.447215 -0.187597 0.577354 0.794651
0.000000 0.000000 1.000000 -0.187597 0.577354 0.794651
0.894425 0.000000 0.447215 0.491122 0.356829 0.794652
0.276385 0.850640 0.447215 0.491122 0.356829 0.794652
0.000000 0.000000 1.000000 0.491122 0.356829 0.794652
3 0 1 2
3 3 4 5
3 6 7 8
3 9 10 11
3 12 13 14
3 15 16 17
3 18 19 20
3 21 22 23
3 24 25 26
3 27 28 29
3 30 31 32
3 33 34 35
3 36 37 38
3 39 40 41
3 42 43 44
3 45 46 47
3 48 49 50
3 51 52 53
3 54 55 56
3 57 58 59
ply
format ascii 1.0
comment Created by Blender3D 246 - www.blender.org, source file: rt3.blend
element vertex 9
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 3
property list uchar uint vertex_indices
end_header
0.216364 1.395244 0.000000 0.280241 0.910549 0.303917
0.686369 0.958168 0.876110 0.280241 0.910549 0.303917
1.275200 1.069365 0.000000 0.280241 0.910549 0.303917
0.686369 0.958168 0.876110 -0.896260 -0.288467 0.336904
0.216364 1.395244 0.000000 -0.896260 -0.288467 0.336904
0.555064 0.342909 0.000000 -0.896260 -0.288467 0.336904
0.686369 0.958168 0.876110 0.662107 -0.656347 0.361696
0.555064 0.342909 0.000000 0.662107 -0.656347 0.361696
1.275200 1.069365 0.000000 0.662107 -0.656347 0.361696
3 0 1 2
3 3 4 5
3 6 7 8
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment