forked from JaviCervera/vortex-cx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeshtool.cxs
159 lines (132 loc) · 3.66 KB
/
meshtool.cxs
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'NOTE: To build on Win32 GCC, you need to go to the Makefile (i.e. glfw3/gcc_winnt/Makefile)
'and add -lole32 to the LDLIBS property
Strict
'Config settings
#GLFW_WINDOW_TITLE="Vortex2 Mesh Tool"
#GLFW_WINDOW_WIDTH=800
#GLFW_WINDOW_HEIGHT=600
#GLFW_WINDOW_RESIZABLE=True
#GLFW_WINDOW_SAMPLES=2
#GLFW_GCC_MSIZE_WINNT="32"
#If HOST = "winnt"
#BINARY_FILES += "*.exe"
#End
'Ensure 32 bit Windows builds
#If HOST = "winnt"
#CC_OPTS="-m32"
#End
'Imports
Import mojo.app
Import mojo.input
Import src_tools.dialog
Import src_tools.meshtool_gui
Import vortex
Import src.math3d
'Constants
Const CAM_DEFX : Float = 2
Const CAM_DEFY : Float = 2
Const CAM_DEFZ : Float = -2
Const CAM_DEFPITCH : Float = 37
Const CAM_DEFYAW : Float = -45
Class MeshToolApp Extends App Final
Public
Method OnCreate:Int()
'Setup
SetUpdateRate(30)
SetSwapInterval(1)
Seed = Millisecs()
'Init vortex
If Not World.Init() Then Notify("Error", "Could not initialize World", True); EndApp()
Print "Vendor name: " + Graphics.VendorName()
Print "Renderer name: " + Graphics.RendererName()
Print "API version name: " + Graphics.APIVersionName()
Print "Shading version name: " + Graphics.ShadingVersionName()
'Create gui
mGui = New Gui
'Create camera
mCam = New Camera()
mCam.Position(CAM_DEFX, CAM_DEFY, CAM_DEFZ)
mCam.Rotate(CAM_DEFPITCH, CAM_DEFYAW, 0)
mCam.BackgroundColor = Color.RGB(15, 15, 15)
mCam.Far = 5000
'Create look point
mLookPoint = New Entity(mCam)
mLookPoint.Position(0, 0, 1)
mLastMouseX = MouseX()
mLastMouseY = MouseY()
mFreeLook = False
Return False
End
Method OnUpdate:Int()
'Update world
World.Update()
'Update GUI
Local newModel:Model = mGui.Update(mModel)
If newModel <> Null
If mModel
mModel.Mesh.Discard()
mModel.Discard()
End
mModel = newModel
End
'Update camera view
mCam.Viewport(0, 24, DeviceWidth(), DeviceHeight() - 24)
'Update camera controls
If MouseHit(MOUSE_RIGHT)
mFreeLook = Not mFreeLook
'If mFreeLook Then HideMouse() Else ShowMouse()
End
If mFreeLook
mCam.Pitch += (MouseY() - mLastMouseY) * 90 * World.DeltaTime()
mCam.Yaw += (MouseX() - mLastMouseX) * 90 * World.DeltaTime()
If mCam.Pitch > 89 Then mCam.Pitch = 89
If mCam.Pitch < -89 Then mCam.Pitch = -89
If KeyDown(KEY_W) Then mCam.Move(0, 0, 32 * World.DeltaTime())
If KeyDown(KEY_S) Then mCam.Move(0, 0, -32 * World.DeltaTime())
If KeyDown(KEY_A) Then mCam.Move(-32 * World.DeltaTime(), 0, 0)
If KeyDown(KEY_D) Then mCam.Move(32 * World.DeltaTime(), 0, 0)
End
'Reset camera with R
If KeyHit(KEY_R)
mCam.Position(CAM_DEFX, CAM_DEFY, CAM_DEFZ)
mCam.Rotate(CAM_DEFPITCH, CAM_DEFYAW, 0)
End
'Update light rotation
Vec3Sub(mLookPoint.WorldX, mLookPoint.WorldY, mLookPoint.WorldZ, mCam.WorldX, mCam.WorldY, mCam.WorldZ, mTempVec)
Vec3Norm(mTempVec[0], mTempVec[1], mTempVec[2], mTempVec)
World.SunRotation(Vec3Pitch(mTempVec[0], mTempVec[1], mTempVec[2]), Vec3Yaw(mTempVec[0], mTempVec[1], mTempVec[2]))
'Update mouse
mLastMouseX = MouseX()
mLastMouseY = MouseY()
Return False
End
Method OnRender:Int()
'Clear background
Graphics.Setup2D(0, 0, DeviceWidth(), DeviceHeight())
Graphics.Clear(Color.White)
'Render world
World.Render()
'Render GUI
mGui.Render(mModel)
Return False
End
Private
Field mCam : Camera
Field mLookPoint : Entity
Field mModel : Model
Field mGui : Gui
Field mLastMouseX : Float
Field mLastMouseY : Float
Field mFreeLook : Bool
Field mTempVec : Float[3]
End
Function Main:Int()
New MeshToolApp()
Return False
End
Function Vec3Pitch#(x#, y#, z#)
Return ASin(-y)
End
Function Vec3Yaw#(x#, y#, z#)
Return ATan2(x, z)
End