-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.lc
More file actions
113 lines (107 loc) · 5.39 KB
/
Copy pathviewer.lc
File metadata and controls
113 lines (107 loc) · 5.39 KB
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
filterFace True 0 p = p%y >= 0.1 -- up in
filterFace False 0 p = p%y <= 0.1 -- up out
filterFace True 1 p = p%x >= 0.1 -- left in
filterFace False 1 p = p%x <= 0.1 -- left ou
eq :: Float -> Float -> Bool
eq a b = a <= b && a >= b
makeFrame (time :: Float)
(color :: Vec 4 Float)
(angleX :: Float)
(angleY :: Float)
(rotatingFace :: Float)
(faceAngle :: Float)
(prims :: PrimitiveStream Triangle ((Vec 4 Float)))
= imageFrame (emptyDepthImage 1, emptyColorImage (V4 0.2 0 0.5 1))
`overlay`
prims
& mapPrimitives (\((p)) -> (projmat *. p, p, color))
& rasterizePrimitives (TriangleCtx CullFront PolygonFill NoOffset LastVertex) (Smooth, Smooth)
& filterFragments(\(p, c) -> filterFace True (p,c))
& mapFragments(\(p, c) -> ((addShadow (projmat *. p) . addBorders p $ c)) )
& accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
`overlay`
prims
& mapPrimitives (\((p)) -> (projmat *. p, p, color))
& rasterizePrimitives (TriangleCtx CullBack PolygonFill NoOffset LastVertex) (Smooth, Smooth)
& filterFragments(\(p, c) -> filterFace True (p,c))
& mapFragments(\(p, c) -> ((black)))
& accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
`overlay`
prims
& mapPrimitives (\((p)) -> (projmat' *. p, p, color))
& rasterizePrimitives (TriangleCtx CullFront PolygonFill NoOffset LastVertex) (Smooth, Smooth)
& filterFragments(\(p, c) -> filterFace False (p,c))
& mapFragments(\(p, c) -> ((addShadow (projmat' *. p) . addBorders p $ c)) )
& accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
`overlay`
prims
& mapPrimitives (\((p)) -> (projmat' *. p, p, color))
& rasterizePrimitives (TriangleCtx CullBack PolygonFill NoOffset LastVertex) (Smooth, Smooth)
& filterFragments(\(p, c) -> filterFace False (p,c))
& mapFragments(\(p, c) -> ((black)))
& accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))
where
filterFace t (p, c) = if rotatingFace `eq` 0 -- UP
then
if t then p%y >= 0.1
else p%y <= 0.1
else if rotatingFace `eq` 1 then -- LEFT
if t then p%x >= 0.1
else p%x <= 0.1
else if rotatingFace `eq` 2 then -- FRONT
if t then p%z <= -0.1
else p%z >= -0.1
else if rotatingFace `eq` 3 then -- RIGHT
if t then p%x <= -0.1
else p%x >= -0.1
else if rotatingFace `eq` 4 then -- DOWN
if t then p%y <= -0.1
else p%y >= -0.1
else -- BACK
if t then p%z >= 0.1
else p%z <= 0.1
-- translateBefore4 does NOT work, so we are limited to just one axis
-- of interactive rotation (i.e. the Y axis)
projmat = perspective 0.1 100.0 (40 * pi / 180) 1.0
.*. lookat (rotMatrixX angleX *. V4 0.0 1 (-2.0) 0.0)%xyz
(V3 0.0 0.0 0.0)
(rotMatrixX angleX *. V4 0.0 1.0 0.0 0.0)%xyz
.*. rotMatrixY (if not (rotatingFace `eq` 0 || rotatingFace `eq` 4) then angleY else 0.0) -- NOT (UP OR DOWN)
.*. rotMatrixY (if rotatingFace `eq` 0 then faceAngle + angleY else 0.0) -- UP
.*. rotMatrixY (if rotatingFace `eq` 4 then -faceAngle + angleY else 0.0) -- DOWN
.*. rotMatrixX (if rotatingFace `eq` 1 then faceAngle else 0.0) -- LEFT
.*. rotMatrixX (if rotatingFace `eq` 3 then -faceAngle else 0.0) -- RIGHT
.*. rotMatrixZ (if rotatingFace `eq` 2 then -faceAngle else 0.0) -- FRONT
.*. rotMatrixZ (if rotatingFace `eq` 5 then faceAngle else 0.0) -- BACK
projmat' = perspective 0.1 100.0 (40 * pi / 180) 1.0
.*. lookat (rotMatrixX angleX *. V4 0.0 1 (-2.0) 0.0)%xyz
(V3 0.0 0.0 0.0)
(rotMatrixX angleX *. V4 0.0 1.0 0.0 0.0)%xyz
-- .*. lookat (V3 0.0 1 (-2.0)) (V3 0.0 0.0 0.0) (V3 0.0 1.0 0.0)
.*. rotMatrixY angleY
-- .*. rotMatrixX angleX
addShadow p c = c *! (p%y/1.5 + 0.9)
addBorders p c = c * white *! k
where width = 0.005
k = if
abs(p%x - 0.295) <= width
|| abs(p%x - 0.1) <= width
|| abs(p%x + 0.1) <= width
|| abs(p%x + 0.295) <= width
|| abs(p%y - 0.295) <= width
|| abs(p%y - 0.1) <= width
|| abs(p%y + 0.1) <= width
|| abs(p%y + 0.295) <= width
|| abs(p%z - 0.295) <= width
|| abs(p%z - 0.1) <= width
|| abs(p%z + 0.1) <= width
|| abs(p%z + 0.295) <= width
then 0.0 else 1.0
main = renderFrame $
makeFrame (Uniform "time")
(Uniform "color")
(Uniform "angleX")
(Uniform "angleY")
(Uniform "rotatingFace")
(Uniform "faceAngle")
(fetch "objects" ((Attribute "position")))