summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-13 04:43:06 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-13 04:43:06 (GMT)
commitcd04bf72f39f290297305021a4788f830f897747 (patch)
treef294ff25affb79930aa0061ee011935b79e23f17 /meme/gui.c
parent3bba45ef5ecdc435b46b0ab99aeab728c36b8b9e (diff)
downloadmisc-cd04bf72f39f290297305021a4788f830f897747.zip
misc-cd04bf72f39f290297305021a4788f830f897747.tar.gz
misc-cd04bf72f39f290297305021a4788f830f897747.tar.bz2
meme/: add YZ plane cut
All this doesn't look very good. Should sort facets for drawing from differnent angles then do depth grading.
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 711e5eb..715bac9 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -114,6 +114,30 @@ static int coord_xz(int x, int y, Sint16 *res_x, Sint16 *res_y)
}
+static inline int yz_z_model2screen(int z)
+{
+ /* center at cursor in right 1/4 of screen */
+ return XRES-(XRES >> 3) - ((z-cursor->z) >> zoom);
+}
+
+
+static int coord_yz(int x, int y, Sint16 *res_x, Sint16 *res_y)
+{
+ x = yz_z_model2screen(x);
+ y = y_model2screen(y);
+
+ if (x < -32768 || x > 32767)
+ return -1;
+ if (y < -32768 || y > 32767)
+ return -1;
+
+ *res_x = x;
+ *res_y = y;
+
+ return x >= 0 && x < XRES && y >= 0 && y < YRES;
+}
+
+
/* ----- Draw the mesh ----------------------------------------------------- */
@@ -335,6 +359,36 @@ static void show_xz_profile(SDL_Surface *s)
}
+static void show_yz_profile(SDL_Surface *s)
+{
+ struct point *yz;
+ unsigned n, i;
+ Sint16 xa = 0, ya = 0, xb = 0, yb = 0;
+ /* initialize because gcc seems to "see" that they can be left
+ uninitialized by coord_xz but then fails to notice that
+ we track this via the return value. */
+ int a, b;
+
+ yz = plane_yz(cursor->x, &n);
+
+ a = coord_yz(yz[0].x, yz[0].y, &xa, &ya);
+ change(s, XRES - (XRES >> 2)-1, 0, XRES >> 2, YRES);
+ SDL_LockSurface(s);
+ for (i = 1; i < n; i++) {
+ b = coord_yz(yz[i].x, yz[i].y, &xb, &yb);
+ if (a >= 0 && b >= 0 && (a || b))
+ aalineColor(s, xa, ya, xb, yb, PROFILE_RGBA);
+ xa = xb;
+ ya = yb;
+ a = b;
+ }
+ aalineColor(s, XRES - (XRES >> 3), 0, XRES - (XRES >> 3), YRES-1, PROFILE_RGBA);
+ SDL_UnlockSurface(s);
+
+ free(yz);
+}
+
+
/* ----- Find nearest vertex ----------------------------------------------- */
@@ -411,6 +465,7 @@ static void motion_event(SDL_Surface *s, SDL_MouseMotionEvent *motion)
cursor = find_nearest(x, y);
show_cursor(s, cursor);
show_xz_profile(s);
+ show_yz_profile(s);
apply_changes(s);
}