From ca4e42c5116d6a205707e6deec26aa1eb170927e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 14 Jun 2019 04:08:44 +0200 Subject: [PATCH] Fix normals bug --- programs/hqOffline.c | 12 ++++++++---- small3dlib.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/programs/hqOffline.c b/programs/hqOffline.c index 7ada1d2..232cf0c 100644 --- a/programs/hqOffline.c +++ b/programs/hqOffline.c @@ -3,7 +3,7 @@ #define S3L_PIXEL_FUNCTION drawPixel -#define S3L_PERSPECTIVE_CORRECTION 1 +#define S3L_PERSPECTIVE_CORRECTION 0 #define S3L_SORT 0 #define S3L_Z_BUFFER 1 @@ -135,6 +135,10 @@ void drawPixel(S3L_PixelInfo *p) color[2] = light / 2 + p->modelIndex * 127; } +color[0] = S3L_clamp(127 + normal.x / 4,0,255); +color[1] = S3L_clamp(127 + normal.y / 4,0,255); +color[2] = S3L_clamp(127 + normal.z / 4,0,255); + frameBuffer[index] = color[0]; frameBuffer[index + 1] = color[1]; frameBuffer[index + 2] = color[2]; @@ -236,13 +240,13 @@ int main() GRID_TRIANGLES, &(models[MODELS - 1])); - S3L_initScene(models,MODELS,&scene); + S3L_initScene(models,/*MODELS*/1,&scene); animateWater(0); scene.camera.transform.translation.x = 4 * S3L_FRACTIONS_PER_UNIT; - scene.camera.transform.translation.y = 6 * S3L_FRACTIONS_PER_UNIT; - scene.camera.transform.translation.z = -7 * S3L_FRACTIONS_PER_UNIT; + scene.camera.transform.translation.y = 8 * S3L_FRACTIONS_PER_UNIT; + scene.camera.transform.translation.z = -10 * S3L_FRACTIONS_PER_UNIT; scene.camera.transform.rotation.x = -S3L_FRACTIONS_PER_UNIT / 8; scene.camera.transform.rotation.y = -S3L_FRACTIONS_PER_UNIT / 8; diff --git a/small3dlib.h b/small3dlib.h index 97547e9..9354f02 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -930,7 +930,7 @@ void S3L_computeModelNormals(S3L_Model3D model, S3L_Unit *dst, n.x = 0; - for (uint8_t i = 0; i < MAX_NORMALS; ++i) + for (uint8_t i = 0; i < normalCount; ++i) { n.x += ns[i].x; n.y += ns[i].y;