aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-23 18:30:21 +0100
committerJulian T <julian@jtle.dk>2020-02-23 18:30:21 +0100
commitb0079eaa628a1f2fd99014cd12e6baac17f4d17a (patch)
tree5925033b7d27a7f0263c19b7babc97fbeb700a93 /main.c
parent9b40029e42f994aeff59ecc44a6d3b8fba93071d (diff)
Added phong light model and fixed sphere intersect
Diffstat (limited to 'main.c')
-rw-r--r--main.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/main.c b/main.c
index 0f0103a..d7232e0 100644
--- a/main.c
+++ b/main.c
@@ -11,6 +11,7 @@
#define TESTH 1000
color_t back = {0, 0, 0};
+int print = 0;
int main()
{
@@ -18,11 +19,21 @@ int main()
space_t s;
s.objects = NULL;
s.lights = NULL;
+ color_set(&s.ambient, 30, 30, 30);
material_t m;
vector_set(&m.color, 0, 1, 0);
+ m.defuse = 1;
+ m.specular = 0.7;
+ m.shine = 20;
- vector_set(&s.view.position, 0, 15, 10);
+ material_t mpl;
+ vector_set(&mpl.color, 0, 0.396, 0.7019);
+ mpl.defuse = 1;
+ mpl.specular = 0.3;
+ mpl.shine = 20;
+
+ vector_set(&s.view.position, 0, 15, 8);
vector_set(&s.view.target, 0, 0, 0);
s.view.width = TESTW;
s.view.height = TESTH;
@@ -30,14 +41,19 @@ int main()
viewpoint_init(&s.view);
// Setup plane
- add_sphere(&s, vector_set(NULL, 0, 0, 5), 5, &m);
+ add_sphere(&s, vector_set(NULL, 3, 0, 5), 5, &m);
+ add_sphere(&s, vector_set(NULL, -6, -3, 7), 3, &m);
//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));
+ add_plane(&s, vector_set(NULL, 0, 0, 2), vector_set(NULL, 0, 0, 1), &mpl);
+ add_light(&s, vector_set(NULL, 10, 0, 20), color_set(NULL, 150, 150, 150), color_set(NULL, 150, 150, 150));
pgm_write_header(stdout, TESTW, TESTH);
for (int y = TESTH; y; y--) {
for (int x = TESTW; x; x--) {
+ if (0 && y <= 500) {
+ printf("Lets go");
+ print = 1;
+ }
color_t *c = ray_trace(&s, x, y);
if (c) {
@@ -46,6 +62,7 @@ int main()
pgm_write_pixel(stdout, &back);
}
free(c);
+ print = 0;
}
}