aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-21 06:55:27 +0100
committerJulian T <julian@jtle.dk>2020-02-21 06:55:27 +0100
commit623fee395425ab33f14fb9cd8ffa790e362f59d7 (patch)
treec70b64e13fd5e00c2317fa40ee4b8cd786e635d5 /main.c
parent63a84080f9f0e3d719d5470e370584a5eff18a47 (diff)
Added pgm drawing and got light ray tracing working
Still needs correct light simulation and reflections
Diffstat (limited to 'main.c')
-rw-r--r--main.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/main.c b/main.c
index 0f64c57..011f2c1 100644
--- a/main.c
+++ b/main.c
@@ -3,39 +3,47 @@
#include <stdlib.h>
#include "vector.h"
-#include "viewpoint.h"
#include "ray.h"
+#include "scene.h"
+#include "pgm.h"
-typedef struct {
- viewpoint_t view;
-} space_t;
+#define TESTW 1000
+#define TESTH 1000
+
+color_t back = {0, 0, 0};
int main()
{
- printf("Starting\n");
-
+ //printf("Starting\n");
space_t s;
+ s.objects = NULL;
+ s.lights = NULL;
- vector_set(&s.view.position, 10, 20, 10);
+ vector_set(&s.view.position, 0, 15, 10);
vector_set(&s.view.target, 0, 0, 0);
- s.view.width = 100;
- s.view.height = 100;
+ s.view.width = TESTW;
+ s.view.height = TESTH;
viewpoint_init(&s.view);
-
- ray_t r;
- r.start = &s.view.position;
- viewpoint_ray(&s.view, &r.direction, 66, 33);
-
- vector_print(&r.direction);
-
- plane_t pl;
- pl.start = vector_set(NULL, 0, 0, 12);
- vector_set(&pl.norm, 6, 2, 0);
- vector_scale_inv(&pl.norm, &pl.norm, vector_len(&pl.norm));
- vector_print(&pl.norm);
-
- printf("Intersect distance %f\n", ray_intersect_plane(&pl, &r));
-
+
+ // Setup plane
+ add_sphere(&s, vector_set(NULL, 0, 0, 5), 5);
+ add_sphere(&s, vector_set(NULL, 10, 0, 5), 5);
+ add_plane(&s, vector_set(NULL, 0, 0, 2), vector_set(NULL, 0, 0, 1));
+ add_light(&s, vector_set(NULL, 10, 0, 20), color_set(NULL, 255, 255, 255));
+
+ pgm_write_header(stdout, TESTW, TESTH);
+ for (int y = TESTH; y; y--) {
+ for (int x = TESTW; x; x--) {
+ color_t *c = ray_trace(&s, x, y);
+
+ if (c) {
+ pgm_write_pixel(stdout, c);
+ } else {
+ pgm_write_pixel(stdout, &back);
+ }
+ free(c);
+ }
+ }
}