From 5f2e7e440a4fb6aab04a4970720efe7d8246911c Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sat, 19 Apr 2025 18:24:31 -0500 Subject: [PATCH] collision: use the complete transformation matrix --- src/haunted_mansion.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/haunted_mansion.cpp b/src/haunted_mansion.cpp index 1e21cc8..bc738f5 100644 --- a/src/haunted_mansion.cpp +++ b/src/haunted_mansion.cpp @@ -777,26 +777,22 @@ bool collided[256] = {}; bool line_has_collision(vec3 a1, vec3 a2, const mat4x4& model_trans, const mat4x4& screen) { + mat4x4 trans = screen * model_trans; + const struct model * model = &haunted_mansion_collision_model; const struct object * object = &haunted_mansion_collision_house_coll_display; - float tx = screen[0][3]; - float ty = screen[2][3]; - for (int i = 0; i < object->line_count; i++) { const union line * line = &object->line[i]; - vec3 la = model->position[line->a]; - vec3 lb = model->position[line->b]; + vec3 b1 = trans * model->position[line->a]; + vec3 b2 = trans * model->position[line->b]; - vec2 b1 = {la.x + tx, la.z + ty}; - vec2 b2 = {lb.x + tx, lb.z + ty}; - - vec2 tu = line_intersection({a1.x, a1.y}, - {a2.x, a2.y}, - {b1.x, b1.y}, - {b2.x, b2.y}); + vec2 tu = line_intersection({a1.x, a1.z}, + {a2.x, a2.z}, + {b1.x, b1.z}, + {b2.x, b2.z}); if (tu.x >= 0.0f && tu.x <= 1.0f && tu.y >= 0.0f && tu.y <= 1.0f) { collided[i] = true; @@ -835,7 +831,7 @@ void render_collision(ta_parameter_writer& writer, const mat4x4& model_trans, co collided[i] ? 0xffff0000 : base_color); } - vec3 a = {last_dx * -2, last_dy * -2, 1}; + vec3 a = {last_dx * -2, last_dy * 2, 1}; vec3 b = {0, 0, 1}; if (a.z > 0) { render_line(writer, @@ -999,8 +995,8 @@ constexpr inline mat4x4 update_analog(const mat4x4& model_trans, const mat4x4& s last_dx = x; last_dy = y; - vec3 a = {last_dx * -2, last_dy * -2, 1.f}; - vec3 b = {0, 0, 1.f}; + vec3 a = {last_dx * -2, 0.f, last_dy * 2}; + vec3 b = {0, 0.f, 1.f}; if (line_has_collision(a, b, model_trans, screen)) { x = 0;