scene: init returns the initial view transformation

This commit is contained in:
Zack Buhman 2025-07-19 01:28:42 -05:00
parent 7455eb7b30
commit f7f109df28
5 changed files with 15 additions and 17 deletions

View File

@ -16,13 +16,21 @@ namespace demo {
draw_cube(writer, trans * translate(particle.position) * scale(1.f), color); draw_cube(writer, trans * translate(particle.position) * scale(1.f), color);
} }
void ballistics::init() mat4x4 ballistics::init()
{ {
current_projectile_type = projectile_type::ARTILLERY; current_projectile_type = projectile_type::ARTILLERY;
for (int i = 0; i < max_projectiles; i++) { for (int i = 0; i < max_projectiles; i++) {
projectiles[i].type = projectile_type::NONE; 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() void ballistics::a()

View File

@ -29,7 +29,7 @@ namespace demo {
projectile_type current_projectile_type; projectile_type current_projectile_type;
int32_t tick; int32_t tick;
void init() override; mat4x4 init() override;
void a() override; void a() override;
void x() override; void x() override;
void update() override; void update() override;

View File

@ -6,7 +6,7 @@
namespace demo { namespace demo {
struct scene { struct scene {
virtual void init() = 0; virtual mat4x4 init() = 0;
virtual void a() {} virtual void a() {}
virtual void b() {} virtual void b() {}
virtual void x() {} virtual void x() {}

View File

@ -104,7 +104,7 @@ namespace graphics {
core_init(); core_init();
framebuffer::scaler_init(); framebuffer::scaler_init();
current_scene->init(); view_trans = current_scene->init();
// read // read
while (spg_status::vsync(holly.SPG_STATUS)); while (spg_status::vsync(holly.SPG_STATUS));
@ -144,17 +144,6 @@ namespace graphics {
1, 1,
texture_memory_alloc.region_array.start, texture_memory_alloc.region_array.start,
texture_memory_alloc.object_list.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() void input_events()

View File

@ -33,10 +33,11 @@ static inline vec3 screen_transform(const vec3& v)
{ {
float tx = framebuffer::framebuffer.px_width / 2.f; float tx = framebuffer::framebuffer.px_width / 2.f;
float ty = framebuffer::framebuffer.px_height / 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; 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, static inline void draw_grid(ta_parameter_writer& writer,