summaryrefslogtreecommitdiff
path: root/meme/plane.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/plane.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/plane.c')
-rw-r--r--meme/plane.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/meme/plane.c b/meme/plane.c
index a2a392c..4fdcaf3 100644
--- a/meme/plane.c
+++ b/meme/plane.c
@@ -45,6 +45,9 @@ static void add_point(struct cut *cut, int x, int y)
}
+/* ----- XZ plane ---------------------------------------------------------- */
+
+
static bool cut_xz(const struct vertex *a, const struct vertex *b, void *user)
{
struct cut *cut = user;
@@ -96,3 +99,59 @@ struct point *plane_xz(int y, unsigned *n)
*n = cut.n-1;
return cut.res;
}
+
+
+/* ----- YZ plane ---------------------------------------------------------- */
+
+
+static bool cut_yz(const struct vertex *a, const struct vertex *b, void *user)
+{
+ struct cut *cut = user;
+ int x = cut->coord;
+ int dx, dy, dz;
+ float f;;
+
+ if ((a->x > x || b->x < x) && (a->x < x || b->x > x))
+ return 0;
+
+ if (a->x == b->x) {
+ add_point(cut, (a->z + b->z) / 2, (a->y + b->y) / 2);
+ return 0;
+ }
+
+ dx = a->x - b->x;
+ dy = a->y - b->y;
+ dz = a->z - b->z;
+ f = (x - b->x)/(float) dx;
+ add_point(cut, b->z + f * dz, b->y + f * dy);
+
+ return 0;
+}
+
+
+static int comp_y(const void *a, const void *b)
+{
+ const struct point *pa = a;
+ const struct point *pb = b;
+
+ if (pa->y < pb->y)
+ return -1;
+ if (pa->y > pb->y)
+ return 1;
+ return 0;
+}
+
+
+struct point *plane_yz(int x, unsigned *n)
+{
+ struct cut cut = {
+ .coord = x,
+ .res = NULL,
+ .n = 0,
+ };
+
+ edge_foreach(cut_yz, &cut);
+ qsort(cut.res, cut.n, sizeof(struct point), comp_y);
+ *n = cut.n-1;
+ return cut.res;
+}