From 822579383e645a8cdc1a733b21bb03b87a3f170b 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:42:27 +0200 Subject: [PATCH] Continue sorting (kinda works) --- small3dlib.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/small3dlib.h b/small3dlib.h index 7190d02..4ba85da 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -1886,7 +1886,17 @@ void S3L_drawScene(S3L_Scene scene) } #if S3L_SORT != S3L_SORT_NONE - // TODO: sort + // TODO: CHANGE BUBBLE SORT TO SOMETHING FASTER! + for (int16_t i = S3L_sortArrayLength - 1; i >= 0; --i) + for (S3L_Index j = 0; j <= i; ++j) + { + if (S3L_sortArray[j].sortValue < S3L_sortArray[j + 1].sortValue) + { + S3L_TriangleToSort tmp = S3L_sortArray[j]; + S3L_sortArray[j] = S3L_sortArray[j + 1]; + S3L_sortArray[j + 1] = tmp; + } + } for (S3L_Index i = 0; i < S3L_sortArrayLength; ++i) { @@ -1897,6 +1907,7 @@ void S3L_drawScene(S3L_Scene scene) if (modelIndex != previousModel) { + // only recompute the matrix when the model has changed S3L_makeWorldMatrix(model->transform,&matFinal); S3L_mat4Xmat4(&matFinal,&matCamera); previousModel = modelIndex;