From 9fe207eebe50e120e67bbb3135f9afaa8997ed07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Tue, 28 May 2019 12:58:16 +0200 Subject: [PATCH] Add comments --- small3dlib.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/small3dlib.h b/small3dlib.h index 4d8a2bb..fb36ce1 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1878,6 +1878,11 @@ void S3L_drawScene(S3L_Scene scene) S3L_sortArray[S3L_sortArrayLength].triangleIndex = triangleIndex; S3L_sortArray[S3L_sortArrayLength].sortValue = (transformed0.z + transformed1.z + transformed2.z) >> 2; + /* ^ As a simple approximation we sort by the triangle center point, + which is a mean coordinate -- we don't actually have to divide by 3 + (or anything), that is unnecessary for sorting! We shift by 2 just + as a fast operation to prevent overflow of the sum ver uint_16t. */ + S3L_sortArrayLength++; #endif } @@ -1912,6 +1917,11 @@ void S3L_drawScene(S3L_Scene scene) S3L_mat4Xmat4(&matFinal,&matCamera); previousModel = modelIndex; } + + /* Here we project the points again, which is redundant and slow as they've + already been projected above, but saving the projected points would + require a lot of memory, which for small resolutions could be even + worse than z-bufer. So this seems to be the best way memory-wise. */ _S3L_projectVertex(model,triangleIndex,0,&matFinal, &transformed0,scene.camera.focalLength);