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