Compare commits
No commits in common. "d0f739c6032bcb58e81ebe61c3fb69fb7a8bc441" and "cdf13f50a7b1fed5dd264ef8d1494055283fdef6" have entirely different histories.
d0f739c603
...
cdf13f50a7
2
engine
2
engine
@ -1 +1 @@
|
||||
Subproject commit ccce6c5d83deb260d06bc525721e31c7c4edcabe
|
||||
Subproject commit abf1e87a3677cc01543f295df588cfa5c54db4e4
|
@ -13,13 +13,7 @@
|
||||
# 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, vec3_mul_vec3,
|
||||
mat3, mat3_rotation, mat3_mul_vec3,
|
||||
mat4, mat4_projection, mat4_lookat,
|
||||
resolve_input, set_input_mat4)
|
||||
|
||||
_m2km = vec3(0.001, 0.001, 0.001)
|
||||
from engine import mat4, mat4_projection, mat4_lookat, resolve_input, set_input_mat4
|
||||
|
||||
class _Inputs:
|
||||
__slots__ = 'projection', 'view'
|
||||
@ -29,30 +23,17 @@ class _Inputs:
|
||||
self.view = resolve_input(shader, view)
|
||||
|
||||
class Camera:
|
||||
__slots__ = 'origin', 'lookat', 'rotation', 'projection', 'view'
|
||||
__slots__ = 'projection', 'view'
|
||||
|
||||
def __init__(self):
|
||||
self.origin = vec3()
|
||||
self.lookat = vec3()
|
||||
self.rotation = mat3()
|
||||
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, origin, lookat, axis, angle):
|
||||
self.origin.set(*origin)
|
||||
self.lookat.set(*lookat)
|
||||
mat3_rotation(self.rotation, axis, angle)
|
||||
mat3_mul_vec3(self.origin, self.rotation, self.origin)
|
||||
mat3_mul_vec3(self.lookat, self.rotation, self.lookat)
|
||||
mat4_lookat(self.view, self.origin, self.lookat)
|
||||
|
||||
def to_km(self):
|
||||
vec3_mul_vec3(self.origin, _m2km, self.origin)
|
||||
vec3_mul_vec3(self.lookat, _m2km, self.lookat)
|
||||
mat4_lookat(self.view, self.origin, self.lookat)
|
||||
def set_view(self, origin, lookat):
|
||||
mat4_lookat(self.view, origin, lookat)
|
||||
|
||||
def resolve_inputs(self, shader, projection = b'u_projection', view = b'u_view'):
|
||||
return _Inputs(shader, projection, view)
|
||||
|
41
game/game.py
41
game/game.py
@ -148,10 +148,9 @@ def main():
|
||||
tests_environment_inputs = environment.resolve_inputs(tests_shader)
|
||||
sky_environment_inputs = environment.resolve_inputs(sky_shader)
|
||||
|
||||
blob_translation = tests_batch.params[blob_id].translation
|
||||
cube_translation = tests_batch.params[cube_id].translation
|
||||
cube_orientation = tests_batch.params[cube_id].orientation
|
||||
clouds_orientation = tests_batch.params[clouds_id].orientation
|
||||
_rotation = mat3()
|
||||
_origin = vec3()
|
||||
_lookat = vec3()
|
||||
|
||||
print("Running...")
|
||||
start_time = time.monotonic()
|
||||
@ -170,14 +169,18 @@ def main():
|
||||
begin_frame()
|
||||
frame_begin = time.thread_time()
|
||||
|
||||
rotation = mat3()
|
||||
mat3_rotation(rotation, vec3_up, (current_time * 0.21) % tau)
|
||||
mat3_mul_vec3(blob_translation, rotation, blob_spawn_translation)
|
||||
mat3_mul_vec3(cube_translation, rotation, cube_spawn_translation)
|
||||
vec3_rotate(cube_orientation, vec3_forward, vec3_up, (current_time * 0.43) % tau)
|
||||
vec3_rotate(clouds_orientation, vec3_forward, vec3_up, (current_time * -0.037) % tau)
|
||||
mat3_rotation(_rotation, vec3_up, (current_time * 0.21) % tau)
|
||||
mat3_mul_vec3(tests_batch.params[blob_id].translation, _rotation, blob_spawn_translation)
|
||||
mat3_mul_vec3(tests_batch.params[cube_id].translation, _rotation, cube_spawn_translation)
|
||||
mat3_rotation(_rotation, vec3_up, (current_time * 0.43) % tau)
|
||||
mat3_mul_vec3(tests_batch.params[cube_id].orientation, _rotation, vec3_forward)
|
||||
mat3_rotation(_rotation, vec3_up, (current_time * -0.037) % tau)
|
||||
mat3_mul_vec3(tests_batch.params[clouds_id].orientation, _rotation, vec3_forward)
|
||||
|
||||
camera.set_view(camera_origin, camera_lookat, vec3_up, (current_time * 0.05) % tau)
|
||||
mat3_rotation(_rotation, vec3_up, (current_time * 0.05) % tau)
|
||||
mat3_mul_vec3(_origin, _rotation, vec3(*camera_origin))
|
||||
mat3_mul_vec3(_lookat, _rotation, vec3(*camera_lookat))
|
||||
camera.set_view(_origin, _lookat)
|
||||
environment.from_sun(camera.view, sun_direction, sun_power)
|
||||
|
||||
select_shader(terrain_shader)
|
||||
@ -210,7 +213,9 @@ def main():
|
||||
unselect_texture(2, normalmap)
|
||||
unselect_shader(tests_shader)
|
||||
|
||||
camera.to_km()
|
||||
camera.set_view(
|
||||
vec3(_origin.x * 0.001, _origin.y * 0.001, _origin.z * 0.001),
|
||||
vec3(_lookat.x * 0.001, _lookat.y * 0.001, _lookat.z * 0.001))
|
||||
|
||||
select_shader(sky_shader)
|
||||
camera.update_inputs(sky_camera_inputs)
|
||||
@ -255,13 +260,13 @@ def main():
|
||||
# for x in range(10000)
|
||||
# current_time = 0
|
||||
|
||||
# Draw * 9999 : min = 0.2 , max = 2.31 , avg = 0.27 ms
|
||||
# Draw * 9999 : min = 0.2 , max = 2.41 , avg = 0.27 ms
|
||||
# Draw * 9999 : min = 0.2 , max = 2.73 , avg = 0.27 ms
|
||||
# Draw * 9999 : min = 0.21 , max = 2.16 , avg = 0.27 ms
|
||||
# Draw * 9999 : min = 0.20 , max = 1.96 , avg = 0.27 ms
|
||||
# Draw * 9999 : min = 0.20 , max = 2.43 , avg = 0.27 ms
|
||||
|
||||
# Frame * 9999 : min = 0.26 , max = 2.44 , avg = 0.38 ms
|
||||
# Frame * 9999 : min = 0.26 , max = 2.54 , avg = 0.37 ms
|
||||
# Frame * 9999 : min = 0.26 , max = 2.90 , avg = 0.38 ms
|
||||
# Frame * 9999 : min = 0.27 , max = 2.29 , avg = 0.38 ms
|
||||
# Frame * 9999 : min = 0.26 , max = 2.08 , avg = 0.37 ms
|
||||
# Frame * 9999 : min = 0.26 , max = 2.59 , avg = 0.38 ms
|
||||
|
||||
print("Quitting...")
|
||||
del tests_batch
|
||||
|
Loading…
Reference in New Issue
Block a user