From f7f109df28768d158eb789935667c418deb92cd1 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sat, 19 Jul 2025 01:28:42 -0500 Subject: [PATCH] scene: init returns the initial view transformation --- src/demo/ballistics.cpp | 10 +++++++++- src/demo/ballistics.hpp | 2 +- src/demo/scene.hpp | 2 +- src/platform/graphics.cpp | 13 +------------ src/platform/graphics_primitive.hpp | 5 +++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/demo/ballistics.cpp b/src/demo/ballistics.cpp index e452339..bb5df2f 100644 --- a/src/demo/ballistics.cpp +++ b/src/demo/ballistics.cpp @@ -16,13 +16,21 @@ namespace demo { draw_cube(writer, trans * translate(particle.position) * scale(1.f), color); } - void ballistics::init() + mat4x4 ballistics::init() { current_projectile_type = projectile_type::ARTILLERY; for (int i = 0; i < max_projectiles; i++) { projectiles[i].type = projectile_type::NONE; } + + mat4x4 view_trans + = translate(vec3(-0.5, 0.5, 0.75)) + * rotate_x(pi / 4) + * rotate_y(pi / 4) + * scale(vec3(-1, -1, 1)); + + return view_trans; } void ballistics::a() diff --git a/src/demo/ballistics.hpp b/src/demo/ballistics.hpp index b10d2f5..714f004 100644 --- a/src/demo/ballistics.hpp +++ b/src/demo/ballistics.hpp @@ -29,7 +29,7 @@ namespace demo { projectile_type current_projectile_type; int32_t tick; - void init() override; + mat4x4 init() override; void a() override; void x() override; void update() override; diff --git a/src/demo/scene.hpp b/src/demo/scene.hpp index 48ec1c9..7df02b5 100644 --- a/src/demo/scene.hpp +++ b/src/demo/scene.hpp @@ -6,7 +6,7 @@ namespace demo { struct scene { - virtual void init() = 0; + virtual mat4x4 init() = 0; virtual void a() {} virtual void b() {} virtual void x() {} diff --git a/src/platform/graphics.cpp b/src/platform/graphics.cpp index 5763bf0..9906f86 100644 --- a/src/platform/graphics.cpp +++ b/src/platform/graphics.cpp @@ -104,7 +104,7 @@ namespace graphics { core_init(); framebuffer::scaler_init(); - current_scene->init(); + view_trans = current_scene->init(); // read while (spg_status::vsync(holly.SPG_STATUS)); @@ -144,17 +144,6 @@ namespace graphics { 1, texture_memory_alloc.region_array.start, texture_memory_alloc.object_list.start); - - //vec3 t = {framebuffer::framebuffer.px_width / 2.f, framebuffer::framebuffer.px_height / 2.f, 0}; - float s = framebuffer::framebuffer.px_height / 3.f; - - view_trans - = scale(vec3(s, s, 1)) - * translate(vec3(0, 0, 10)) - * rotate_x(pi / 4) - * rotate_y(pi / 4) - * scale(vec3(-1, -1, 1)); - view_trans = view_trans * translate(vec3(0, 0, -0.9)); } void input_events() diff --git a/src/platform/graphics_primitive.hpp b/src/platform/graphics_primitive.hpp index cefa7d9..d5a8551 100644 --- a/src/platform/graphics_primitive.hpp +++ b/src/platform/graphics_primitive.hpp @@ -33,10 +33,11 @@ static inline vec3 screen_transform(const vec3& v) { float tx = framebuffer::framebuffer.px_width / 2.f; float ty = framebuffer::framebuffer.px_height / 2.f; + float s = framebuffer::framebuffer.px_height / 2.f; - float z = _fsrra(v.z - 9); + float z = _fsrra(v.z); float z2 = z * z; - return {v.x * z2 + tx , v.y * z2 + ty, z2}; + return {(v.x) * s * z2 + tx , (v.y) * s * z2 + ty , z2}; } static inline void draw_grid(ta_parameter_writer& writer,