2022-11-29 03:19:57 +01:00
|
|
|
# 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 mat4, mat4_projection, mat4_lookat, resolve_input, set_input_mat4
|
|
|
|
|
|
|
|
class Camera:
|
|
|
|
__slots__ = '_projection_input', '_projection', '_view_input', '_view'
|
|
|
|
|
2022-12-18 03:44:31 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._projection_input = None
|
2022-11-29 03:19:57 +01:00
|
|
|
self._projection = mat4()
|
2022-12-18 03:44:31 +01:00
|
|
|
self._view_input = None
|
2022-11-29 03:19:57 +01:00
|
|
|
self._view = mat4()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def projection(self):
|
|
|
|
return self._projection
|
|
|
|
|
|
|
|
@property
|
|
|
|
def view(self):
|
|
|
|
return self._view
|
|
|
|
|
|
|
|
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, origin, lookat):
|
|
|
|
mat4_lookat(self._view, origin, lookat)
|
|
|
|
|
2022-12-18 03:44:31 +01:00
|
|
|
def resolve_inputs(self, shader, projection_input = b'u_projection', view_input = b'u_view'):
|
|
|
|
self._projection_input = resolve_input(shader, projection_input)
|
|
|
|
self._view_input = resolve_input(shader, view_input)
|
|
|
|
|
2022-11-29 03:19:57 +01:00
|
|
|
def update_inputs(self):
|
|
|
|
set_input_mat4(self._projection_input, self._projection)
|
|
|
|
set_input_mat4(self._view_input, self._view)
|