/
main.awk
executable file
·105 lines (88 loc) · 3.16 KB
/
main.awk
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
104
105
#!/usr/bin/gawk -f
@include "lib/3d.gawk"
@include "lib/colors.gawk"
BEGIN {
if ("COLUMNS" in ENVIRON) {
width = ENVIRON["COLUMNS"]
height = ENVIRON["LINES"]
} else {
"tput cols" | getline width
"tput lines" | getline height
close("tput cols")
close("tput lines")
if (!width || !height) {
width = 80
height = 24
}
}
## two pixels per lines
height = (height-1) * 2
## initialize screen buffer
#width = 120
#height = 70
init(scr, width,height)
f["interval"] = 0.5
## set up viewmode variables
cam["viewmode"] = 1; # 0 == isometric, 1 == 3d
cam["drawmode"] = 3; # 0 == vertices; 1 == edges; 2 == triangles; 3 == filled triangles
cam["wireframe"] = 0; # 0 == solid; 1 == wireframe
cam["shading"] = 1; # 0 == no shading; 1 == shading
cam["color"] = 1; # 0 == greyscale; 1 == color
## create 'camera' array
array(cam, "loc")
array(cam, "move")
array(cam, "angle")
array(cam, "piv")
## set camera values
vector(cam["loc"], 0, 0, 200)
vector(cam["move"], width/2, height/2, 1)
vector(cam["angle"], 0, 0, 0)
vector(cam["piv"], 0, 0, 0)
## load 3D object
#loadmesh(mesh, "models/pyramid.mesh")
#loadmesh(mesh, "models/cube.mesh")
#loadmesh(mesh, "models/octohedron.mesh")
#loadmesh(mesh, "models/dodecahedron.mesh")
#loadmesh(mesh, "models/icosahedron.mesh")
#loadmesh(mesh, "models/true/true.mesh")
#loadmesh(mesh, "models/plane/plane.mesh")
#loadmesh(mesh, "models/hypercube/hypercube.mesh")
loadmesh(mesh, "models/obj/starwest.mesh")
##
## main loop
##
cursor("off")
start = myTime()
cam["angle"]["x"] = 1.7;
# cam["angle"]["y"] += 0.1;
while ("awk" != "difficult") {
# while (framenr++ < 500) {
#cam["angle"]["x"] += 0.02; # spin on x-axis
#cam["angle"]["y"] += 0.02; # spin on y-axis
cam["angle"]["z"] += 0.02; # spin on z-axis
cam["angle"]["x"] = cos(cam["angle"]["z"])/2 + 1.7
#cam["loc"]["y"] = sin(cam["angle"]["x"]) * height / 8
#cam["angle"]["y"] = sin(cam["angle"]["x"])
clear(scr)
# animate(start)
drawmesh(scr, mesh, cam)
draw(scr)
printf("\033[H%.2fFPS", fps(f))
system("sleep 0.01")
}
cursor("on")
}
function between(value, min, max) {
if ((value >= min) && (value < max)) return(1)
else return(0)
}
function animate(starttime) {
elapsed = myTime() - starttime
if (between(elapsed, 0, 5)) { cam["viewmode"] = 0; cam["drawmode"] = 0; cam["wireframe"] = 1; cam["shading"] = 0; cam["color"] = 0 }
if (between(elapsed, 5, 10)) { cam["viewmode"] = 0; cam["drawmode"] = 2; cam["wireframe"] = 1; cam["shading"] = 0; cam["color"] = 0 }
if (between(elapsed, 10, 15)) { cam["viewmode"] = 0; cam["drawmode"] = 3; cam["wireframe"] = 0; cam["shading"] = 0; cam["color"] = 0 }
if (between(elapsed, 15, 20)) { cam["viewmode"] = 0; cam["drawmode"] = 3; cam["wireframe"] = 0; cam["shading"] = 1; cam["color"] = 0 }
if (between(elapsed, 20, 25)) { cam["viewmode"] = 1; cam["drawmode"] = 3; cam["wireframe"] = 0; cam["shading"] = 1; cam["color"] = 0 }
if (between(elapsed, 25, 30)) { cam["viewmode"] = 1; cam["drawmode"] = 3; cam["wireframe"] = 0; cam["shading"] = 1; cam["color"] = 1 }
if (elapsed > 35) exit 0
}