diff options
Diffstat (limited to 'libgraphics')
-rw-r--r-- | libgraphics/render.c | 27 | ||||
-rw-r--r-- | libgraphics/triangle.c | 43 |
2 files changed, 13 insertions, 57 deletions
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); -} |