summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geometry.h2
-rw-r--r--graphics.h11
-rw-r--r--libgraphics/render.c27
-rw-r--r--libgraphics/triangle.c43
4 files changed, 14 insertions, 69 deletions
diff --git a/geometry.h b/geometry.h
index a62d667..0e4f748 100644
--- a/geometry.h
+++ b/geometry.h
@@ -1,4 +1,4 @@
-#define DEG 0.01745329251994330
+#define DEG 0.01745329251994330 /* π/180 */
typedef struct Point2 Point2;
typedef struct Point3 Point3;
diff --git a/graphics.h b/graphics.h
index be3105d..57aa56e 100644
--- a/graphics.h
+++ b/graphics.h
@@ -4,7 +4,6 @@ typedef enum {
} Projection;
typedef struct Vertex Vertex;
-typedef struct Triangle Triangle;
typedef struct Viewport Viewport;
typedef struct Camera Camera;
@@ -14,10 +13,6 @@ struct Vertex {
//Image tx; /* (?) */
};
-struct Triangle {
- Point p0, p1, p2;
-};
-
struct Camera {
RFrame3; /* VCS */
Image *viewport;
@@ -29,12 +24,6 @@ struct Camera {
Projection ptype;
};
-/* Triangle */
-Triangle Trian(int, int, int, int, int, int);
-Triangle Trianpt(Point, Point, Point);
-void triangle(Image *, Triangle, int, Image *, Point);
-void filltriangle(Image *, Triangle, Image *, Point);
-
/* Camera */
void perspective(Matrix3, double, double, double, double);
void orthographic(Matrix3, double, double, double, double, double, double);
diff --git a/libgraphics/render.c b/libgraphics/render.c
index f4e4c0f..ddc0663 100644
--- a/libgraphics/render.c
+++ b/libgraphics/render.c
@@ -4,16 +4,6 @@
#include "../geometry.h"
#include "../graphics.h"
-/*
- * careful with concurrent rendering.
- * use a lock or embed on each routine.
- */
-static RFrame imgrframe = {
- 0, 0, 1, /* p */
- 1, 0, 0, /* bx */
- 0, -1, 0 /* by */
-};
-
/* requires p to be in NDC */
int
isclipping(Point3 p)
@@ -51,17 +41,26 @@ Point
toviewport(Camera *c, Point3 p)
{
Point2 p2;
+ RFrame rf = {
+ c->viewport->r.min.x, c->viewport->r.max.y, 1,
+ 1, 0, 0,
+ 0, -1, 0
+ };
- imgrframe.p = Pt2(c->viewport->r.min.x, c->viewport->r.max.y, 1);
- p2 = invrframexform(flatten(c, p), imgrframe);
+ p2 = invrframexform(flatten(c, p), rf);
return (Point){p2.x, p2.y};
}
Point2
fromviewport(Camera *c, Point p)
{
- imgrframe.p = Pt2(c->viewport->r.min.x, c->viewport->r.max.y, 1);
- return rframexform(Pt2(p.x, p.y, 1), imgrframe);
+ RFrame rf = {
+ c->viewport->r.min.x, c->viewport->r.max.y, 1,
+ 1, 0, 0,
+ 0, -1, 0
+ };
+
+ return rframexform(Pt2(p.x, p.y, 1), rf);
}
void
diff --git a/libgraphics/triangle.c b/libgraphics/triangle.c
deleted file mode 100644
index b598855..0000000
--- a/libgraphics/triangle.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <u.h>
-#include <libc.h>
-#include <draw.h>
-#include "../geometry.h"
-#include "../graphics.h"
-
-Triangle
-Trian(int x0, int y0, int x1, int y1, int x2, int y2)
-{
- return (Triangle){Pt(x0, y0), Pt(x1, y1), Pt(x2, y2)};
-}
-
-Triangle
-Trianpt(Point p0, Point p1, Point p2)
-{
- return (Triangle){p0, p1, p2};
-}
-
-void
-triangle(Image *dst, Triangle t, int thick, Image *src, Point sp)
-{
- Point pl[4];
-
- pl[0] = t.p0;
- pl[1] = t.p1;
- pl[2] = t.p2;
- pl[3] = pl[0];
-
- poly(dst, pl, nelem(pl), 0, 0, thick, src, sp);
-}
-
-void
-filltriangle(Image *dst, Triangle t, Image *src, Point sp)
-{
- Point pl[4];
-
- pl[0] = t.p0;
- pl[1] = t.p1;
- pl[2] = t.p2;
- pl[3] = pl[0];
-
- fillpoly(dst, pl, nelem(pl), 0, src, sp);
-}