]> git.lizzy.rs Git - dragonblocks3d-lua.git/blob - modules/RenderEngine/src/camera.lua
Improved Yaw & Pitch
[dragonblocks3d-lua.git] / modules / RenderEngine / src / camera.lua
1 local camera = {
2         pos = glm.vec3(0, 0, 0),
3         up = glm.vec3(0, 1, 0),
4         world_up = glm.vec3(0, 1, 0),
5         front = glm.vec3(0, 0, -1),
6 }
7
8 function camera:get_view_matrix()
9         return glm.look_at(self.pos, self.pos + self.front, self.up)
10 end
11
12 function camera:update(yaw, pitch)
13         yaw, pitch = math.rad(yaw), math.rad(glm.clamp(pitch, -89.0, 89.0))
14         self.front = glm.vec3(math.cos(yaw)*math.cos(pitch), math.sin(pitch), math.sin(yaw)*math.cos(pitch)):normalize()
15         --self.front = glm.vec3(math.cos(yaw), math.sin(pitch), math.sin(yaw)):normalize()
16         self.right = (self.front % self.world_up):normalize()
17         self.up = (self.right % self.front):normalize()
18 end
19
20 return camera