shithub: 3dee

Download patch

ref: a435467f81a1d9d429109f3a34988c642bed6035
parent: 3e0fe77fe3832b4c4eb7abe9c16088d9ff08f7bc
author: rodri <rgl@antares-labs.eu>
date: Wed Mar 4 16:03:21 EST 2020

first steps towards a general rendering architecture.

--- 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;
--- a/graphics.h
+++ b/graphics.h
@@ -4,7 +4,6 @@
 } Projection;
 
 typedef struct Vertex Vertex;
-typedef struct Triangle Triangle;
 typedef struct Viewport Viewport;
 typedef struct Camera Camera;
 
@@ -14,10 +13,6 @@
 	//Image tx;	/* (?) */
 };
 
-struct Triangle {
-	Point p0, p1, p2;
-};
-
 struct Camera {
 	RFrame3;		/* VCS */
 	Image *viewport;
@@ -28,12 +23,6 @@
 	Matrix3 proj;		/* VCS to NDC xform */
 	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);
--- 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,9 +41,13 @@
 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};
 }
 
@@ -60,8 +54,13 @@
 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
--- a/libgraphics/triangle.c
+++ /dev/null
@@ -1,43 +1,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);
-}