/
maxgui.bmx
executable file
·142 lines (97 loc) · 2.55 KB
/
maxgui.bmx
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
' Based on code by Birdie and Peter Scheutz
Import "../minib3d.bmx"
Strict
SetGraphicsDriver GLGraphicsDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER
Local win:TGadget=CreateWindow("MiniB3D in a GUI window", 10, 10, 512, 512 )
Local can:TGadget=CreateCanvas(0,0,ClientWidth(win),ClientHeight(win),win,0)
SetGadgetLayout can,1,1,1,1
TGlobal.width=ClientWidth(win)
TGlobal.height=ClientHeight(win)
TGlobal.depth=16
TGlobal.mode=0
TGlobal.rate=60
SetGraphics CanvasGraphics(can)
TGlobal.GraphicsInit()
Local cam:TCamera=CreateCamera()
PositionEntity cam,0,0,-10
Local light:TLight=CreateLight(1)
Local tex:TTexture=LoadTexture("media/test.png")
Local cube:TMesh=CreateCube()
Local sphere:TMesh=CreateSphere()
Local cylinder:TMesh=CreateCylinder()
Local cone:TMesh=CreateCone()
PositionEntity cube,-6,0,0
PositionEntity sphere,-2,0,0
PositionEntity cylinder,2,0,0
PositionEntity cone,6,0,0
EntityTexture cube,tex
EntityTexture sphere,tex
EntityTexture cylinder,tex
EntityTexture cone,tex
Local cx#=0
Local cy#=0
Local cz#=0
Local pitch#=0
Local yaw#=0
Local roll#=0
' used by fps code
Local old_ms:Int=MilliSecs()
Local renders:Int
Local fps:Int
Local up_key:Int
Local down_key:Int
Local left_key:Int
Local right_key:Int
CreateTimer( 60 )
While True
WaitEvent()
Select EventID()
Case EVENT_KEYDOWN
Select EventData()
Case KEY_ESCAPE
End
Case KEY_UP
up_key=True
Case KEY_DOWN
down_key=True
Case KEY_LEFT
left_key=True
Case KEY_RIGHT
right_key=True
EndSelect
Case EVENT_KEYUP
Select EventData()
Case KEY_UP
up_key=False
Case KEY_DOWN
down_key=False
Case KEY_LEFT
left_key=False
Case KEY_RIGHT
right_key=False
EndSelect
Case EVENT_WINDOWCLOSE
End
Case EVENT_WINDOWSIZE
TGlobal.width=ClientWidth(win)
TGlobal.height=ClientHeight(win)
cam.CameraViewport(0,0,ClientWidth(win),ClientHeight(win))
DebugLog "EVENT_WINDOWSIZE"
Case EVENT_TIMERTICK
If up_key Then cz#=cz#+1.0
If left_key Then cx#=cx#-1.0
If right_key Then cx#=cx#+1.0
If down_key Then cz#=cz#-1.0
MoveEntity cam,cx#*0.5,cy#*0.5,cz#*0.5
RotateEntity cam,pitch#,yaw#,roll#
cx#=0
cy#=0
cz#=0
RedrawGadget can
Case EVENT_GADGETPAINT
SetGraphics CanvasGraphics(can)
TurnEntity cube,0,1,0
RenderWorld
Flip
EndSelect
Wend