collision: use the complete transformation matrix

This commit is contained in:
Zack Buhman 2025-04-19 18:24:31 -05:00
parent f414171cbf
commit 5f2e7e440a

View File

@ -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;