-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojtest.c
103 lines (93 loc) · 2.22 KB
/
projtest.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include <memdraw.h>
#include <mouse.h>
#include <keyboard.h>
#include <geometry.h>
#include "libobj/obj.h"
#include "libgraphics/graphics.h"
#include "fns.h"
Camera *cam;
void
usage(void)
{
fprint(2, "usage: %s\n", argv0);
exits("usage");
}
void
threadmain(int argc, char *argv[])
{
Point3 np, fp;
Framebuf *fb;
GEOMfmtinstall();
ARGBEGIN{
default: usage();
}ARGEND
if(argc != 0)
usage();
if(memimageinit() != 0)
sysfatal("memimageinit: %r");
cam = Cam(Rect(0,0,640,480), nil, PERSPECTIVE, 40*DEG, 0.01, 10);
placecamera(cam, nil, Pt3(0,0,1,1), Vec3(0,0,0), Vec3(0,1,0));
fb = cam->view->getfb(cam->view);
np = Pt3(0,0,-0.01,1);
fp = Pt3(0,0,-10,1);
fprint(2, "near %V\nfar %V\n", np, fp);
np = vcs2clip(cam, np);
fp = vcs2clip(cam, fp);
fprint(2, "E → C\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = clip2ndc(np);
fp = clip2ndc(fp);
fprint(2, "C → N\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = ndc2viewport(fb, np);
fp = ndc2viewport(fb, fp);
fprint(2, "N → V\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = viewport2ndc(fb, np);
fp = viewport2ndc(fb, fp);
fprint(2, "V → N\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = ndc2vcs(cam, np);
fp = ndc2vcs(cam, fp);
fprint(2, "N → E\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
fprint(2, "\n");
np = Pt3(Dx(fb->r)/2.0,Dy(fb->r)/2.0,1,1);
fp = Pt3(Dx(fb->r)/2.0,Dy(fb->r)/2.0,0,1);
fprint(2, "near %V\nfar %V\n", np, fp);
np = viewport2ndc(fb, np);
fp = viewport2ndc(fb, fp);
fprint(2, "V → N\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = ndc2vcs(cam, np);
fp = ndc2vcs(cam, fp);
fprint(2, "N → E\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = vcs2clip(cam, np);
fp = vcs2clip(cam, fp);
fprint(2, "E → C\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = clip2ndc(np);
fp = clip2ndc(fp);
fprint(2, "C → N\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
np = ndc2viewport(fb, np);
fp = ndc2viewport(fb, fp);
fprint(2, "N → V\n");
fprint(2, "near %V\n", np);
fprint(2, "far %V\n", fp);
exits(nil);
}