rk_island/game/camera.py
2022-12-31 15:22:30 +01:00

43 lines
1.6 KiB
Python

# Copyright (C) 2022 RozK
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from engine import vec3_origin, mat4, mat4_projection, mat4_orbit, set_input_mat4
class Camera:
__slots__ = 'yaw', 'pitch', 'distance', 'projection', 'view'
def __init__(self):
self.yaw = 0.0
self.pitch = 0.0
self.distance = 0.0
self.projection = mat4()
self.view = mat4()
def set_projection(self, half_fov, ratio, near_z, far_z):
mat4_projection(self.projection, half_fov, ratio, near_z, far_z)
def set_view(self, yaw, pitch, distance):
self.yaw = yaw
self.pitch = pitch
self.distance = distance
mat4_orbit(self.view, vec3_origin, yaw, pitch, distance)
def to_km(self):
mat4_orbit(self.view, vec3_origin, self.yaw, self.pitch, self.distance * 0.001)
def set_inputs(self, shader):
set_input_mat4(shader.u_projection, self.projection)
set_input_mat4(shader.u_view, self.view)