-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.lua
242 lines (187 loc) · 7.25 KB
/
start.lua
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
------------------
-- Create Scene --
------------------
scene = Scene.new(applicationContext)
-----------------------------
-- Create and add Renderer --
-----------------------------
-- forward with skybox
--[[
SkyboxRenderer.new(5, scene)
SunRenderer.new(4, scene)
ForwardRenderer.new(3, scene)
SkeletalModelRenderer.new(2, scene)
GuiRenderer.new(1, scene)
TextRenderer.new(0, scene, "res/font/calibri.ttf")
]]
-- deferred with skybox
--[[
DeferredRenderer.new(4, scene)
SkyboxRenderer.new(3, scene)
SunRenderer.new(2, scene)
GuiRenderer.new(1, scene)
TextRenderer.new(0, scene, "res/font/calibri.ttf")
]]
-- forward with skydome
SkydomeRenderer.new(5, scene)
SunRenderer.new(4, scene)
ForwardRenderer.new(3, scene)
SkeletalModelRenderer.new(2, scene)
GuiRenderer.new(1, scene)
TextRenderer.new(0, scene, "res/font/calibri.ttf")
-- deferred with skydome
--[[
DeferredRenderer.new(4, scene)
SkydomeRenderer.new(3, scene)
SunRenderer.new(2, scene)
GuiRenderer.new(1, scene)
TextRenderer.new(0, scene, "res/font/calibri.ttf")
]]
----------------------------
-- Create and add Cameras --
----------------------------
firstPersonCamera = FirstPersonCamera.new("first_person_camera1", applicationContext, Vec3.new(883.0, 1055.0, -853.0), -205.0, -16.0, scene)
firstPersonCamera:SetCameraVelocity(128.0)
firstPersonCamera:SetMouseSensitivity(0.025)
thirdPersonCamera = ThirdPersonCamera.new("third_person_camera1", applicationContext, Vec3.new(-500.0, 200.0, -500.0), scene)
thirdPersonCamera:SetPlayerRotationY(45.0)
thirdPersonCamera:SetPitch(35.0)
------------------
-- Config Scene --
------------------
--scene:SetCurrentCamera("first_person_camera1")
scene:SetCurrentCamera("third_person_camera1")
scene:SetAmbientIntensity(Vec3.new(0.2, 0.2, 0.2))
--------------------
-- Load resources --
--------------------
plane = modelManager:GetModel("res/primitive/plane1/plane1.obj")
sphere = modelManager:GetModel("res/primitive/sphere/sphere.obj")
dome = modelManager:GetModel("res/model/Dome/dome.obj")
lamp = modelManager:GetModel("res/model/Streetlamp/streetlamp.obj")
jade = modelManager:GetMaterialByName("jade")
gold = modelManager:GetMaterialByName("gold")
sunTextureId = textureManager:LoadTexture("res/sun/sun.png")
foodGuiId = textureManager:LoadTexture("res/gui/foodIcon.png")
healthGuiId = textureManager:LoadTexture("res/gui/healthIcon.png")
hero = modelManager:GetSkeletalModel("res/model/Player/drone.X")
a = {}
a[1] = "res/skybox/sky1/sRight.png"
a[2] = "res/skybox/sky1/sLeft.png"
a[3] = "res/skybox/sky1/sUp.png"
a[4] = "res/skybox/sky1/sDown.png"
a[5] = "res/skybox/sky1/sBack.png"
a[6] = "res/skybox/sky1/sFront.png"
skyboxCubemapId = textureManager:GetCubemapId(a)
---------------------
-- Create Entities --
---------------------
-- plane
planeEntity = ecs:CreateEntity()
ecs:AddModelComponent(planeEntity, plane, false)
ecs:AddTransformComponent(planeEntity, Vec3.new(0.0, 150.0, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(5000.0, 1.0, 5000.0))
ecs:AddInputComponent(planeEntity, "MouseInput")
-- hero
heroEntity = ecs:CreateEntity()
ecs:AddSkeletalModelComponent(heroEntity, hero, false)
ecs:AddTransformComponent(heroEntity, Vec3.new(-500.0, 200.0, -500.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(64.0))
ecs:AddPlayerComponent(heroEntity, "Hero", 2, 1200.0, 200.0)
-- sphere
sphereEntity = ecs:CreateEntity()
ecs:AddModelComponent(sphereEntity, sphere, false)
ecs:AddTransformComponent(sphereEntity, Vec3.new(0.0, 240.0, 380.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(4.0, 4.0, 4.0))
ecs:AddMaterialComponent(sphereEntity, gold)
-- skydome
skydomeEntity = ecs:CreateEntity()
ecs:AddModelComponent(skydomeEntity, dome, false)
ecs:AddTransformComponent(skydomeEntity, Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(5000.0, 5000.0, 5000.0))
ecs:AddSkydomeComponent(skydomeEntity, "skydome")
-- a point light
plightEntity0 = ecs:CreateEntity()
ecs:AddPointLightComponent(plightEntity0,
Vec3.new(30.0, 240.0, 657.0), -- position
Vec3.new(0.2, 0.2, 0.2), -- ambientIntensity
Vec3.new(10.0, 1.0, 1.0), -- diffuseIntensity
Vec3.new(1.0, 1.0, 1.0), -- specularIntensity
1.0, 0.0014, 0.000007 -- constant, linear, quadratic
)
ecs:AddUpdateComponent(plightEntity0, "UpdatePointLight")
-- another point light
plightEntity1 = ecs:CreateEntity()
ecs:AddPointLightComponent(plightEntity1,
Vec3.new(204.0, 240.0, -319.0), -- position
Vec3.new(0.2, 0.2, 0.2), -- ambientIntensity
Vec3.new(1.0, 1.0, 10.0), -- diffuseIntensity
Vec3.new(1.0, 1.0, 1.0), -- specularIntensity
1.0, 0.0014, 0.000007 -- constant, linear, quadratic
)
ecs:AddUpdateComponent(plightEntity1, "UpdatePointLight")
-- the sun
--[[
dlightEntity = ecs:CreateEntity()
ecs:AddDirectionalLightComponent(dlightEntity,
Vec3.new(1.0, -0.2, -0.4), -- direction
Vec3.new(1.0, 0.8, 0.6), -- diffuseIntensity
Vec3.new(1.0, 0.8, 0.6) -- specularIntensity
)
]]
sunEntity = ecs:CreateEntity()
ecs:AddSunComponent(sunEntity,
Vec3.new(1.0, -0.2, -0.4), -- direction
Vec3.new(1.0, 0.8, 0.6), -- diffuseIntensity
Vec3.new(1.0, 0.8, 0.6), -- specularIntensity
sunTextureId,
10.0
)
-- skybox
skyboxEntity = ecs:CreateEntity()
ecs:AddCubemapComponent(skyboxEntity, skyboxCubemapId)
-- gui
foodEntity = ecs:CreateEntity()
ecs:AddGuiComponent(foodEntity, foodGuiId)
ecs:AddTransformComponent(foodEntity, Vec3.new(0.9, 0.9, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.031, 0.031, 1.0))
-- another gui
healthEntity = ecs:CreateEntity()
ecs:AddGuiComponent(healthEntity, healthGuiId)
ecs:AddTransformComponent(healthEntity, Vec3.new(0.9, 0.8, 0.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(0.031, 0.031, 1.0))
-- point light with model
plightModelEntity = ecs:CreateEntity()
ecs:AddModelComponent(plightModelEntity, lamp, false)
ecs:AddTransformComponent(plightModelEntity, Vec3.new(-1400.0, 150.0, 11.0), Vec3.new(0.0, 0.0, 0.0), Vec3.new(40.0, 40.0, 40.0))
ecs:AddPointLightComponent(plightModelEntity,
Vec3.new(-1400.0, 400.0, 11.0), -- position
Vec3.new(0.2, 0.2, 0.2), -- ambientIntensity
Vec3.new(1.0, 1.0, 10.0), -- diffuseIntensity
Vec3.new(1.0, 1.0, 1.0), -- specularIntensity
1.0, 0.0014, 0.000007 -- constant, linear, quadratic
)
-- text
textEntity0 = ecs:CreateEntity()
ecs:AddTextComponent(textEntity0, "SgOgl Test", 40.0, 750.0, 0.35, Vec3.new(0.1, 0.2, 0.2))
textEntity1 = ecs:CreateEntity()
ecs:AddTextComponent(textEntity1, "Version: dev-master", 40.0, 730.0, 0.35, Vec3.new(0.1, 0.2, 0.2))
---------------
-- Functions --
---------------
-- example update function
val = 0.0
function UpdatePointLight(entity, dt)
val = val + dt
p = ecs:GetPointLightComponent(entity)
p.position.x = p.position.x + (math.sin(val) * 4.0)
end
-- example input function
function MouseInput()
-- if left mouse button was pressed
if (mouseInput:IsLeftButtonPressed()) then
print("left mouse button pressed")
-- get current mouse position
mousePosition = mouseInput:GetCurrentPos()
print("mouse x: " .. mousePosition.x)
print("mouse y: " .. mousePosition.y)
-- get current width && height
projectionOptions = applicationContext:GetProjectionOptions()
print("screen width: " .. projectionOptions.width)
print("screen height: " .. projectionOptions.height)
end
end