# 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 . from engine import mat4, mat4_projection, mat4_lookat, resolve_input, set_input_mat4 class Camera: __slots__ = '_projection_input', '_projection', '_view_input', '_view' def __init__(self, projection_input = b'u_projection', view_input = b'u_view'): self._projection_input = resolve_input(projection_input) self._projection = mat4() self._view_input = resolve_input(view_input) 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) def update_inputs(self): set_input_mat4(self._projection_input, self._projection) set_input_mat4(self._view_input, self._view)