summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-17 14:22:55 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-17 14:22:55 (GMT)
commitcfa2659a9ac9318be959d1fd0713f3bd0b31a54b (patch)
treedfef5d9e86ecb589715b447e645b0b56a69d7178 /meme/gui.c
parente5bcb21451fe8db2ba699a9d7cd7ce16be3b1490 (diff)
downloadmisc-cfa2659a9ac9318be959d1fd0713f3bd0b31a54b.zip
misc-cfa2659a9ac9318be959d1fd0713f3bd0b31a54b.tar.gz
misc-cfa2659a9ac9318be959d1fd0713f3bd0b31a54b.tar.bz2
meme/gui.c (surface_draw): draw contour for equality (more precise), change color to purple
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c118
1 files changed, 106 insertions, 12 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 6d52c29..09b7331 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -42,7 +42,7 @@
#define MARK_A_RGBA 0x00ff00ff
#define MARK_B_RGBA 0x3030ffff
#define CONTRAST_RGBA 0xffe080ff
-#define EQUAL_RGBA 0xffd0a0ff
+#define EQUAL_RGBA 0xf080ffff
#define DEPTH_RANGE 0xc0
#define DEPTH_OFFSET 0x30
@@ -261,6 +261,107 @@ static void end_equal(void)
}
+#include <assert.h>
+
+
+/*
+ * Draw line between sides AC and BC
+ */
+
+static void equal_line(SDL_Surface *s,
+ const struct vertex *a, const struct vertex *b, const struct vertex *c,
+ Sint16 xa, Sint16 ya, Sint16 xb, Sint16 yb, Sint16 xc, Sint16 yc)
+{
+ float fa, fb;
+
+assert(a->z != c->z);
+assert(b->z != c->z);
+ fa = (float) (equal - c->z) / (a->z - c->z);
+ fb = (float) (equal - c->z) / (b->z - c->z);
+
+ aalineColor(s, xc+(xa-xc)*fa, yc+(ya-yc)*fa,
+ xc+(xb-xc)*fb, yc+(yb-yc)*fb, EQUAL_RGBA);
+}
+
+
+static inline bool between(int v, int a, int b)
+{
+ return (a <= v && b >= v) || (b <= v && a >= v);
+}
+
+
+/*
+ * This duplicates a lot of things from surface_draw, but there doesn't seem
+ * to be an easy way around that problem.
+ */
+
+static void equal_draw(SDL_Surface *s)
+{
+ const struct facet *f;
+ Sint16 xa, ya, xb, yb, xc, yc;
+ int a, b, c;
+ bool ab, ac, bc;
+
+ for (f = facets; f; f = f->next) {
+ a = coord(f->v[0]->x, f->v[0]->y, &xa, &ya);
+ if (a < 0)
+ continue;
+ b = coord(f->v[1]->x, f->v[1]->y, &xb, &yb);
+ if (b < 0)
+ continue;
+ c = coord(f->v[2]->x, f->v[2]->y, &xc, &yc);
+ if (c < 0)
+ continue;
+ if (!(a || b || c))
+ continue;
+
+ ab = f->v[0]->z == equal && f->v[1]->z == equal;
+ ac = f->v[0]->z == equal && f->v[2]->z == equal;
+ bc = f->v[1]->z == equal && f->v[2]->z == equal;
+
+ if (ab && ac) {
+ filledTrigonColor(s, xa, ya, xb, yb, xc, yc,
+ EQUAL_RGBA);
+ continue;
+ }
+ if (ab) {
+ aalineColor(s, xa, ya, xb, yb, EQUAL_RGBA);
+ continue;
+ }
+ if (ac) {
+ aalineColor(s, xa, ya, xc, yc, EQUAL_RGBA);
+ continue;
+ }
+ if (bc) {
+ aalineColor(s, xb, yb, xc, yc, EQUAL_RGBA);
+ continue;
+ }
+
+ ab = between(equal, f->v[0]->z, f->v[1]->z);
+ ac = between(equal, f->v[0]->z, f->v[2]->z);
+ bc = between(equal, f->v[1]->z, f->v[2]->z);
+ if (!(ab || ac || bc))
+ continue;
+ if (ac && bc) {
+ equal_line(s, f->v[0], f->v[1], f->v[2],
+ xa, ya, xb, yb, xc, yc);
+ continue;
+ }
+ if (ab && ac) {
+ equal_line(s, f->v[1], f->v[2], f->v[0],
+ xb, yb, xc, yc, xa, ya);
+ continue;
+ }
+ if (ab && bc) {
+ equal_line(s, f->v[0], f->v[2], f->v[1],
+ xa, ya, xc, yc, xb, yb);
+ continue;
+ }
+abort();
+ }
+}
+
+
/* ----- Draw the mesh ----------------------------------------------------- */
@@ -270,7 +371,6 @@ static void surface_draw(SDL_Surface *s)
Sint16 xa, ya, xb, yb, xc, yc;
int a, b, c;
int z_off = z_min*3;
- Uint32 col;
for (f = facets; f; f = f->next) {
a = coord(f->v[0]->x, f->v[0]->y, &xa, &ya);
@@ -284,16 +384,8 @@ static void surface_draw(SDL_Surface *s)
continue;
if (!(a || b || c))
continue;
-
- if ((f->v[0]->z < equal && f->v[1]->z < equal &&
- f->v[2]->z < equal) ||
- (f->v[0]->z > equal && f->v[1]->z > equal &&
- f->v[2]->z > equal))
- col = z_grad[f->v[0]->z + f->v[1]->z + f->v[2]->z -
- z_off];
- else
- col = EQUAL_RGBA;
- filledTrigonColor(s, xa, ya, xb, yb, xc, yc, col);
+ filledTrigonColor(s, xa, ya, xb, yb, xc, yc,
+ z_grad[f->v[0]->z + f->v[1]->z + f->v[2]->z - z_off]);
}
}
@@ -330,6 +422,8 @@ static void draw(SDL_Surface *s)
surface_draw(s);
if (show_grid)
edges_draw(s);
+ if (equal != INT_MAX)
+ equal_draw(s);
}