@@ -5,44 +5,80 @@ import Http (..)
5import MJS (..)
5import MJS (..)
6import Graphics.WebGL (..)
6import Graphics.WebGL (..)
8−pul = v3 -1 1 0
8+pul = {pos=v3 -1 1 0, coord=v3 0 1 0}
9−pur = v3 1 1 0
9+pur = {pos=v3 1 1 0, coord=v3 1 1 0}
10−pbl = v3 -1 -1 0
10+pbl = {pos=v3 -1 -1 0, coord=v3 0 0 0}
11−pbr = v3 1 -1 0
11+pbr = {pos=v3 1 -1 0, coord=v3 1 0 0}
13−mesh : [Triangle { pos : V3 }]
13+face : [Triangle { pos : V3, coord : V3 }]
14−mesh = map (mapTriangle (\pos -> {pos=pos})) <|
15− [(pul,pur,pbl),(pbl,pur,pbr)]
14+face = [(pul,pur,pbl),(pbl,pur,pbr)]
16+rotFace : Float -> Float -> [Triangle { pos : V3, coord : V3 }]
18+ let x = makeRotate (turnV * pi / 2) (v3 1 0 0)
19+ y = makeRotate (turnH * pi / 2) (v3 0 1 0)
20+ s = makeTranslate (v3 0 0 1)
22+ in map (mapTriangle (\x -> {x | pos <- mul4x4 t x.pos })) face
24+mesh : [Triangle { pos : V3, coord : V3 }]
25+mesh = concat . map (uncurry rotFace) <|
17−vert : Shader { pos : V3 } u { coord : V2 }
34+vert : Shader { pos : V3, coord : V3 } { u | view : M4x4 } { vcoord : V2 }
18vert = [glShader|
35vert = [glShader|
19attribute vec3 pos;
36attribute vec3 pos;
20−varying vec2 coord;
39+varying vec2 vcoord;
21void main () {
40void main () {
22− gl_Position = vec4(pos, 1.0);
41+ gl_Position = view * vec4(pos, 1.0);
23− coord = pos.xy;
42+ vcoord = coord.xy;
27−frag : Shader {} { u | crate : Texture } { coord : V2 }
46+frag : Shader {} { u | crate : Texture } { vcoord : V2 }
28frag = [glShader|
47frag = [glShader|
29precision mediump float;
48precision mediump float;
30uniform sampler2D crate;
49uniform sampler2D crate;
31−varying vec2 coord;
50+varying vec2 vcoord;
32void main () {
51void main () {
33− gl_FragColor = texture2D(crate, coord);
52+ gl_FragColor = texture2D(crate, vcoord);
37crateTex : Signal (Response Texture)
56crateTex : Signal (Response Texture)
38crateTex = loadTex "woodCrate.JPG"
57crateTex = loadTex "woodCrate.JPG"
60+per = makePerspective 45 1 0.01 100
63+cam = makeLookAt (v3 0 0 5) (v3 0 0 0) (v3 0 1 0)
66+angle = foldp (\_ n -> n + 0.02) 0 (fps 25)
70+ let x = makeRotate (2*t) (v3 1 0 0)
71+ y = makeRotate (3*t) (v3 0 1 0)
72+ in foldr mul identity [per,cam,y,x]
40−content : Response Texture -> [Model]
74+content : Response Texture -> M4x4 -> [Model]
41−content response = case response of
75+content response view = case response of
42 Waiting -> []
76 Waiting -> []
43 Failure i s -> []
77 Failure i s -> []
44− Success tex -> [model vert frag mesh { crate = tex }]
78+ Success tex -> [model vert frag mesh { crate = tex, view = view }]
80+main = webgl (400,400) <~ (content <~ crateTex ~ (view <~ angle))
46−main = webgl (400,400) <~ (content <~ crateTex)
82+--main = asText (List.length mesh)