aboutsummaryrefslogtreecommitdiff
path: root/graphics.h
blob: b9582f3ab59c7d6ee1fd5250ae3147478a88b75e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
typedef enum {
	Portho,		/* orthographic */
	Ppersp		/* perspective */
} Projection;

typedef struct Vertex Vertex;
typedef struct Camera Camera;

struct Vertex {
	Point3 p;	/* position */
	Point3 n;	/* surface normal */
};

struct Camera {
	RFrame3;		/* VCS */
	Image *viewport;
	double fov;		/* vertical FOV */
	struct {
		double n, f;
	} clip;
	Matrix3 proj;		/* VCS to NDC xform */
	Projection ptype;
};

/* Camera */
void configcamera(Camera*, Image*, double, double, double, Projection);
void placecamera(Camera*, Point3, Point3, Point3);
void aimcamera(Camera*, Point3);
void reloadcamera(Camera*);

/* rendering */
#define FPS2MS(n)		(1000/(n))
#define WORLD2VCS(cp, p)	(rframexform3((p), *(cp)))
#define VCS2NDC(cp, p)		(xform3((p), (cp)->proj))
#define WORLD2NDC(cp, p)	(VCS2NDC((cp), WORLD2VCS((cp), (p))))
int isclipping(Point3);
Point toviewport(Camera*, Point3);
Point2 fromviewport(Camera*, Point);
void perspective(Matrix3, double, double, double, double);
void orthographic(Matrix3, double, double, double, double, double, double);
void line3(Camera*, Point3, Point3, int, int, Image*);
Point string3(Camera*, Point3, Image*, Font*, char*);