summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo <leo@azuminha.com>2024-02-15 02:22:09 -0300
committerleo <leo@azuminha.com>2024-02-15 02:22:09 -0300
commitb96e1de0bd5e00d7bd3c74cf5319a6fb76439c24 (patch)
tree255455571ed26aa825c336d1ab27b5119c933ba3
parent282c24f7f940b3b7e0caf76bd6e20d2993bf42b6 (diff)
acho que tem sombras, porem tem que arrumar a ordem de renderizacao
-rw-r--r--donut.c38
-rw-r--r--donut.h4
2 files changed, 29 insertions, 13 deletions
diff --git a/donut.c b/donut.c
index 3862056..9355ed4 100644
--- a/donut.c
+++ b/donut.c
@@ -1,6 +1,9 @@
#include "donut.h"
#include <raylib.h>
+point3d light1 = {10, 10, 10};
+point3d light2 = {-10, -10, -10};
+point3d light3 = {-5, 0, -5};
//center nao deve ter passado pela funcao map antes
void draw_circle(point2d center, double radius){
double angle = 0;
@@ -10,10 +13,6 @@ void draw_circle(point2d center, double radius){
for(double i=0; i<2*PI; i+=0.01){
double r = radius;
- //point3d tmpc = {center.x, center.y, 0};
- //tmpc = rotate_x(tmpc, angle);
- //center.x = tmpc.x; center.y = tmpc.y;
-
point2d aux = {r*cos(i), r*sin(i)};
aux.x += center.x; aux.y += center.y;
@@ -23,18 +22,33 @@ void draw_circle(point2d center, double radius){
tmp3 = rotate_x(tmp3, static_angle);
aux.x = tmp3.x; aux.y = tmp3.y;
- //point3d tmp = {aux.x, aux.y, 0};
- //tmp = rotate_y(tmp, angle);
- //aux.x = tmp.x; aux.y = tmp.y;
+ // normal N = tmp3 - center
+ point3d cen = {center.x, center.y, 0};
+ cen = rotate_y(cen, angle);
+ cen = rotate_z(cen, static_angle);
+ cen = rotate_x(cen, static_angle);
-// point3d tmp2 = {aux.x, aux.y, 0};
-// tmp2 = rotate_x(tmp2, static_angle);
-// aux.x = tmp2.x; aux.y = tmp2.y;
+ point3d N;
+ N.x = tmp3.x - cen.x;
+ N.y = tmp3.y - cen.y;
+ N.z = tmp3.z - cen.z;
+
+ //(N ^ light)
+ double lv1 = N.x * light1.x + N.y * light1.y + N.z * light1.z;
+ double lv2 = N.x * light2.x + N.y * light2.y + N.z * light2.z;
+ double lv3 = N.x * light3.x + N.y * light3.y + N.z * light3.z;
+ lv2 = 0;
+ lv3 = 0;
+ double lv = MAX(MAX(lv1, lv2), lv3);
aux = map(aux);
- DrawPixel(aux.x, aux.y, GREEN);
+ if(lv > 0){
+ int alp = 255 * lv / 5;
+ alp = (alp > 255 ? 255 : alp);
+ DrawPixel(aux.x, aux.y, (Color){0, 255, 0, alp});
+ }
}
- angle += 0.005;
+ angle += 0.01;
}
static_angle += 0.05;
}
diff --git a/donut.h b/donut.h
index 568ae80..e4e0519 100644
--- a/donut.h
+++ b/donut.h
@@ -5,6 +5,8 @@
#include <stdio.h>
#include <math.h>
+#define MAX(a,b) ((a)>(b)?(a):(b))
+
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 640
@@ -26,4 +28,4 @@ point3d rotate_x(point3d p, double a);
point3d rotate_y(point3d p, double a);
point3d rotate_z(point3d p, double a);
-#endif \ No newline at end of file
+#endif