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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
win = require("window")
color = require("color")
world = require("world")
sprites = require("world.sprites")
shader_shim = require("shader_shim")
hc = require("party.hardoncollider.init")
-- Process the world into buffers to send to the shader
error("Who is including world?")
print("sprites:",sprites,getmetatable(sprites))
print("sprites.floor1_diffuse",sprites["floor1_diffuse"])
view_angle = math.pi / 4
near_plane = 1
far_plane = 2
aspect = win.width / win.height
s_mv = mat4(
1, 0, 0, 0,
0, aspect, 0, 0,
0, 0, 1, 0,
-0.5, 0.5, 0, 4
)
p_mv = mat4(
1 / ((win.width / win.height) * math.tan(view_angle / 2)), 0, 0, 0,
0, 1/math.tan(view_angle/2), 0, 0,
0, 0, far_plane / (far_plane - near_plane), 1,
0, 0,(-far_plane * near_plane)/(far_plane - near_plane), 0
)
-- Each point needs:
-- vec3 position (x,y,z)
-- vec2 (u,v)
up_down_hall = (x,y) ->
r = {
--floor
vec3(x,y,0),
vec3(x+1,y,0),
vec3(x+1,y-1,0),
vec3(x+1,y-1,0),
vec3(x,y-1,0),
vec3(x,y,0),
-- Left wall
vec3(x,y,1),
vec3(x,y,0),
vec3(x,y-1,0),
vec3(x,y-1,0),
vec3(x,y-1,1),
vec3(x,y,1),
--Right wall
vec3(x+1,y,0),
vec3(x+1,y,1),
vec3(x+1,y-1,1),
vec3(x+1,y-1,1),
vec3(x+1,y-1,0),
vec3(x+1,y,0),
}
r
sd = sprites.floor1_diffuse
w1 = sprites.wall1_diffuse
-- uvs are s,t,smult, tmult
up_down_hall_uv = (x,y) ->
r = {
--floor
vec4(sd.s1,sd.t1,1,1),
vec4(sd.s2,sd.t1,1,1),
vec4(sd.s2,sd.t2,1,1),
vec4(sd.s2,sd.t2,1,1),
vec4(sd.s1,sd.t2,1,1),
vec4(sd.s1,sd.t1,1,1),
-- left wall
vec4(w1.s1,w1.t1,1,1),
vec4(w1.s1,w1.t2,1,1),
vec4(w1.s2,w1.t2,1,1),
vec4(w1.s2,w1.t2,1,1),
vec4(w1.s2,w1.t1,1,1),
vec4(w1.s1,w1.t1,1,1),
-- right wall
vec4(w1.s2,w1.t2,1,1),
vec4(w1.s2,w1.t1,1,1),
vec4(w1.s1,w1.t1,1,1),
vec4(w1.s1,w1.t1,1,1),
vec4(w1.s1,w1.t2,1,1),
vec4(w1.s2,w1.t2,1,1),
}
r
add_verts = (tbl, new) ->
for i = 1, #new
tbl[#tbl+1] = new[i]
world_geom = {}
world_uv = {}
add_verts(world_geom, up_down_hall(0,0))
add_verts(world_uv, up_down_hall_uv(0,0))
add_verts(world_geom, up_down_hall(0,1))
add_verts(world_uv, up_down_hall_uv(0,0))
add_verts(world_geom, up_down_hall(0,-1))
add_verts(world_uv, up_down_hall_uv(0,0))
--sprites["diffuse"].texture.wrap = "repeat"
--sprites["normals"].texture.wrap = "repeat"
node = shader_shim.world\append(am.cull_face("front")\append(am.bind({
MV: s_mv
P: mat4(1)
color: color.am_color.highlight,
world_x: 0,
world_y: 0,
world: am.vec3_array(world_geom)
time: am.current_time(),
textures: sprites.floor1_diffuse.texture
texuv: am.vec4_array(world_uv)
})\append(am.draw("triangles"))))
node\action(() =>
bind = self("bind")
bind.time = am.current_time!
bind.world_x = math.sin(am.current_time!) * 2
bind.world_y = math.cos(am.current_time!) * 2
)
{
node: node
bind: node("bind")
}
|