From b0079eaa628a1f2fd99014cd12e6baac17f4d17a Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 23 Feb 2020 18:30:21 +0100 Subject: Added phong light model and fixed sphere intersect --- pgm.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'pgm.c') diff --git a/pgm.c b/pgm.c index 90791de..efc50f7 100644 --- a/pgm.c +++ b/pgm.c @@ -32,9 +32,14 @@ color_t *color_add(color_t *dest, color_t *a, color_t *b) dest = (color_t *) malloc(sizeof(dest)); } - dest->r = a->r + b->r; - dest->g = a->g + b->g; - dest->b = a->b + b->b; + unsigned int tmp = a->r + b->r; + dest->r = tmp > 255 ? 255 : tmp; + + tmp = a->g + b->g; + dest->g = tmp > 255 ? 255 : tmp; + + tmp = a->b + b->b; + dest->b = tmp > 255 ? 255 : tmp; return dest; } @@ -45,9 +50,14 @@ color_t *color_scale(color_t *dest, color_t *a, float b) dest = (color_t *) malloc(sizeof(dest)); } - dest->r = a->r * b; - dest->g = a->g * b; - dest->b = a->b * b; + unsigned int tmp = a->r * b; + dest->r = tmp > 255 ? 255 : tmp; + + tmp = a->g * b; + dest->g = tmp > 255 ? 255 : tmp; + + tmp = a->b * b; + dest->b = tmp > 255 ? 255 : tmp; return dest; } -- cgit v1.2.3