From 3866947c8866fad5860a361185eb97d023991bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Fri, 7 Jun 2019 12:13:43 +0200 Subject: [PATCH] Add modes --- programs/modelViewer.c | 61 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/programs/modelViewer.c b/programs/modelViewer.c index 76c164f..c3ac7b6 100644 --- a/programs/modelViewer.c +++ b/programs/modelViewer.c @@ -90,7 +90,7 @@ S3L_Vec4 toLight; int8_t light = 1; int8_t fog = 0; int8_t mode = 0; -S3L_Vec4 n0, n1, n2; +S3L_Vec4 n0, n1, n2, nt; void drawPixel(S3L_PixelInfo *p) { @@ -102,6 +102,41 @@ void drawPixel(S3L_PixelInfo *p) int16_t i1 = uvIndices[index + 1]; int16_t i2 = uvIndices[index + 2]; + if (mode == 3) + { + S3L_Vec4 v0, v1, v2; + + S3L_Index v = model.triangles[index] * 3; + + v0.x = model.vertices[v]; + v++; + v0.y = model.vertices[v]; + v++; + v0.z = model.vertices[v]; + + v = model.triangles[index + 1] * 3; + + v1.x = model.vertices[v]; + v++; + v1.y = model.vertices[v]; + v++; + v1.z = model.vertices[v]; + + v = model.triangles[index + 2] * 3; + + v2.x = model.vertices[v]; + v++; + v2.y = model.vertices[v]; + v++; + v2.z = model.vertices[v]; + + S3L_triangleNormal(v0,v1,v2,&nt); + + nt.x = S3L_clamp(128 + nt.x / 4,0,255); + nt.y = S3L_clamp(128 + nt.y / 4,0,255); + nt.z = S3L_clamp(128 + nt.z / 4,0,255); + } + index = i0 * 2; uv0[0] = uvs[index]; @@ -176,7 +211,7 @@ void drawPixel(S3L_PixelInfo *p) break; } - case 2: // normal mode + case 2: // smooth normal mode { S3L_Vec4 n; @@ -194,6 +229,24 @@ void drawPixel(S3L_PixelInfo *p) r = S3L_clamp(128 + n.x / 4,0,255); g = S3L_clamp(128 + n.y / 4,0,255); b = S3L_clamp(128 + n.z / 4,0,255); + + break; + } + + case 3: // non-smooth normal mode + { + r = nt.x; + g = nt.y; + b = nt.z; + break; + } + + case 4: // barycentric mode + { + r = p->barycentric[0] >> 1; + g = p->barycentric[1] >> 1; + b = p->barycentric[2] >> 1; + break; } default: @@ -376,6 +429,10 @@ int main() mode = 1; else if (state[SDL_SCANCODE_KP_2]) mode = 2; + else if (state[SDL_SCANCODE_KP_3]) + mode = 3; + else if (state[SDL_SCANCODE_KP_4]) + mode = 4; SDL_RenderClear(renderer); SDL_RenderCopy(renderer,textureSDL,NULL,NULL);