From 44628e689575cd0009124151830dd2395de2ed91 Mon Sep 17 00:00:00 2001 From: Krow Savcik Date: Sun, 21 Jan 2024 01:33:01 +0200 Subject: feature: new option in .obj files --- README.md | 1 + draw.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c6c99f..0425b11 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Available potions are the following: 2. **v** *x* *y* *z* - add vertex. 3. **f** *v1* *v2* *v3* - add triangle face with following vertices. 4. **F** *v1* *v2* *v3* *color* - add triangle face with color and following vertices. +5. **C** *color* - triangles added afterwards will have this color. Lines that start with any other character will be ignored. diff --git a/draw.c b/draw.c index 9b703be..936ff41 100644 --- a/draw.c +++ b/draw.c @@ -41,7 +41,8 @@ add_obj(const char *path, Point off) int pc = 0; int a, b, c; float mult = 1; - unsigned int col; + unsigned int col, defcol; + defcol = 0x808080ff; if ((f = fopen(path, "r")) == NULL) { printf("%s:%d add_obj(...): Error opening file %s\n", __FILE__, __LINE__, path); @@ -62,7 +63,7 @@ add_obj(const char *path, Point off) break; case 'f': sscanf(s, "%*c %d%d%d", &a, &b, &c); - add_triangle(v[a-1], v[b-1], v[c-1], 0x808080ff); + add_triangle(v[a-1], v[b-1], v[c-1], defcol); t[0] = v[a-1]; t[0].y = 0; t[1] = v[b-1]; t[1].y = 0; t[2] = v[c-1]; t[2].y = 0; @@ -70,6 +71,9 @@ add_obj(const char *path, Point off) add_triangle(t[0], t[1], t[2], shadowcol); #endif break; + case 'C': + sscanf(s, "%*c %x", &defcol); + break; case 'F': sscanf(s, "%*c %d%d%d%x", &a, &b, &c, &col); add_triangle(v[a-1], v[b-1], v[c-1], col); -- cgit v1.2.3