-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcube.erl
106 lines (83 loc) · 2.42 KB
/
cube.erl
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
-module(cube).
-author('[email protected]').
-include_lib("wx/include/gl.hrl").
-export([start/0, loop0/2]).
-export([on/0, off/0]).
-record(state, {enabled=true, gl}).
start() ->
{Env, GL} = gui:env(),
Pid = spawn(?MODULE, loop0, [Env, GL]),
register(?MODULE, Pid),
gui:connect(Pid).
on() ->
?MODULE ! enabled.
off() ->
?MODULE ! disabled.
loop0(Env, GL) ->
wx:set_env(Env),
State = #state{gl=GL},
loop(State).
loop(State) ->
receive
enabled ->
loop(State#state{enabled=true});
disabled ->
loop(State#state{enabled=false});
{Pid, {Ref, draw}} ->
draw(State),
Pid ! {ok, Ref},
loop(State)
end.
-define(MAXC, 1.0).
-define(CUBE, {
{ ?MAXC, ?MAXC, -?MAXC}, %1
{ ?MAXC, -?MAXC, -?MAXC}, %2
{-?MAXC, -?MAXC, -?MAXC},
{-?MAXC, ?MAXC, -?MAXC}, %4
{-?MAXC, ?MAXC, ?MAXC},
{ ?MAXC, ?MAXC, ?MAXC}, %6
{ ?MAXC, -?MAXC, ?MAXC},
{-?MAXC, -?MAXC, ?MAXC}}). %8
draw(#state{enabled=false}) ->
ok;
draw(State) ->
wxGLCanvas:setCurrent(State#state.gl),
u:set_model_view(),
gl:lineWidth(2),
gl:'begin'(?GL_LINES),
gl:color3ub(255, 255, 255),
gl:vertex3fv(element(1, ?CUBE)),
gl:vertex3fv(element(2, ?CUBE)),
gl:vertex3fv(element(2, ?CUBE)),
gl:vertex3fv(element(3, ?CUBE)),
gl:vertex3fv(element(3, ?CUBE)),
gl:vertex3fv(element(4, ?CUBE)),
gl:vertex3fv(element(4, ?CUBE)),
gl:vertex3fv(element(5, ?CUBE)),
gl:vertex3fv(element(5, ?CUBE)),
gl:vertex3fv(element(8, ?CUBE)),
gl:vertex3fv(element(8, ?CUBE)),
gl:vertex3fv(element(3, ?CUBE)),
gl:vertex3fv(element(1, ?CUBE)),
gl:vertex3fv(element(6, ?CUBE)),
gl:vertex3fv(element(6, ?CUBE)),
gl:vertex3fv(element(7, ?CUBE)),
gl:vertex3fv(element(7, ?CUBE)),
gl:vertex3fv(element(2, ?CUBE)),
gl:vertex3fv(element(6, ?CUBE)),
gl:vertex3fv(element(5, ?CUBE)),
gl:vertex3fv(element(5, ?CUBE)),
gl:vertex3fv(element(8, ?CUBE)),
gl:vertex3fv(element(8, ?CUBE)),
gl:vertex3fv(element(7, ?CUBE)),
gl:vertex3fv(element(6, ?CUBE)),
gl:vertex3fv(element(1, ?CUBE)),
gl:vertex3fv(element(1, ?CUBE)),
gl:vertex3fv(element(4, ?CUBE)),
gl:vertex3fv(element(4, ?CUBE)),
gl:vertex3fv(element(5, ?CUBE)),
gl:vertex3fv(element(7, ?CUBE)),
gl:vertex3fv(element(2, ?CUBE)),
gl:vertex3fv(element(3, ?CUBE)),
gl:vertex3fv(element(8, ?CUBE)),
gl:'end'().