diff --git a/res/graphics/tim.ase b/res/graphics/tim.ase index d28b0a57..983f9a13 100644 --- a/res/graphics/tim.ase +++ b/res/graphics/tim.ase @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:70f7f9f3cd307b97da03c233bb38f30c71d5766cee011e95049f3493cb3f9bd6 -size 1453 +oid sha256:32478c7862c244341a3311a16b862da428e750260af2510f08251779d743b023 +size 4451 diff --git a/src/game.c b/src/game.c index 50e5e771..f4073ef1 100644 --- a/src/game.c +++ b/src/game.c @@ -350,64 +350,42 @@ INTERNAL void game_update(void) /* Update focus */ ent->focus = G.world.player_aim; -#if 0 - struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite); - struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("hold"), ent->animation_frame); - - struct v2 hold_pos = xform_mul_v2(ent->xform_world, xform_mul_v2(ent->sprite_xform, slice.center)); - struct v2 hold_dir = xform_basis_mul_v2(ent->xform_world, xform_basis_mul_v2(ent->sprite_xform, slice.dir)); - - struct v2 focus_pos = v2_add(ent->xform_world.og, ent->focus); - struct v2 hold_focus_dir = v2_sub(focus_pos, hold_pos); - - /* Only rotate if rotation to focus around origin is possible */ - f32 min_hold_radius = 0; + /* Solve for missing angle using law of sines */ + f32 final_xf_angle; { - struct v2 center = xform_mul_v2(ent->sprite_xform_world, slice.center); - struct v2 center_dir = v2_norm(xform_basis_mul_v2(ent->sprite_xform_world, slice.dir)); - struct v2 minpoint = v2_closest_point_ray(center, center_dir, ent->xform_world.og); - min_hold_radius = v2_len(v2_sub(minpoint, ent->xform_world.og)); - } - f32 ent_focus_len = v2_len(v2_sub(focus_pos, ent->xform_world.og)); - if (ent_focus_len > min_hold_radius) { - ent->xform = xform_rotate(ent->xform, v2_angle_from_dirs(hold_dir, hold_focus_dir)); - } -#else - struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite); - struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("hold"), ent->animation_frame); + struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite); + struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("hold"), ent->animation_frame); - struct xform xf = ent->xform; + struct xform xf = ent->xform_world; - struct v2 ent_pos = ent->xform_world.og; - struct v2 focus_pos = v2_add(ent_pos, ent->focus); - struct v2 hold_pos = xform_mul_v2(ent->xform_world, xform_mul_v2(ent->sprite_xform, slice.center)); + f32 forward_hold_angle_offset; + { + struct xform xf_unrotated = xform_with_rotation(xf, 0); + struct v2 hold_pos_unrotated = xform_mul_v2(xf_unrotated, xform_mul_v2(ent->sprite_xform, slice.center)); + forward_hold_angle_offset = v2_angle_from_dirs(V2(0, -1), v2_sub(hold_pos_unrotated, xf_unrotated.og)); + } - struct v2 hold_dir = xform_basis_mul_v2(ent->xform_world, xform_basis_mul_v2(ent->sprite_xform, slice.dir)); - struct v2 hold_ent_dir = v2_sub(ent_pos, hold_pos); - struct v2 focus_ent_dir = v2_sub(ent_pos, focus_pos); + struct v2 ent_pos = xf.og; + struct v2 focus_pos = v2_add(ent_pos, ent->focus); + struct v2 hold_pos = xform_mul_v2(xf, xform_mul_v2(ent->sprite_xform, slice.center)); - f32 hold_ent_len = v2_len(hold_ent_dir); - f32 focus_ent_len = v2_len(focus_ent_dir); + struct v2 hold_dir = xform_basis_mul_v2(xf, xform_basis_mul_v2(ent->sprite_xform, slice.dir)); + struct v2 hold_ent_dir = v2_sub(ent_pos, hold_pos); + struct v2 focus_ent_dir = v2_sub(ent_pos, focus_pos); - f32 final_hold_angle_btw_ent_and_focus = v2_angle_from_dirs(v2_norm(hold_ent_dir), v2_norm(hold_dir)); - f32 final_focus_angle_btw_ent_and_hold = math_asin((math_sin(final_hold_angle_btw_ent_and_focus) * hold_ent_len) / focus_ent_len); - f32 final_ent_angle_btw_focus_and_hold = PI - (final_focus_angle_btw_ent_and_hold + final_hold_angle_btw_ent_and_focus); + f32 hold_ent_len = v2_len(hold_ent_dir); + f32 focus_ent_len = v2_len(focus_ent_dir); - f32 final_hold_ent_angle_offset; - { - struct xform ent_world_xform_unrotated = xform_with_rotation(ent->xform_world, 0); - struct v2 hold_pos_unrotated = xform_mul_v2(ent_world_xform_unrotated, xform_mul_v2(ent->sprite_xform, slice.center)); - final_hold_ent_angle_offset = v2_angle_from_dirs(V2(0, -1), v2_norm(v2_sub(hold_pos_unrotated, ent_world_xform_unrotated.og))); + f32 final_hold_angle_btw_ent_and_focus = v2_angle_from_dirs(hold_ent_dir, hold_dir); + f32 final_focus_angle_btw_ent_and_hold = math_asin((math_sin(final_hold_angle_btw_ent_and_focus) * hold_ent_len) / focus_ent_len); + f32 final_ent_angle_btw_focus_and_hold = PI - (final_focus_angle_btw_ent_and_hold + final_hold_angle_btw_ent_and_focus); + + final_xf_angle = v2_angle_from_dirs(V2(0, -1), v2_sub(focus_pos, ent_pos)) + final_ent_angle_btw_focus_and_hold - forward_hold_angle_offset; } - f32 final_ent_angle = v2_angle_from_dirs(V2(0, -1), v2_sub(focus_pos, ent_pos)) + final_ent_angle_btw_focus_and_hold - final_hold_ent_angle_offset; - - if (!F32_IS_NAN(final_ent_angle)) { - xf = xform_with_rotation(xf, final_ent_angle); + if (!F32_IS_NAN(final_xf_angle)) { + ent->xform = xform_with_rotation(ent->xform_world, final_xf_angle); } - - ent->xform = xf; -#endif } /* ========================== * diff --git a/src/user.c b/src/user.c index 63a2005f..6acbabab 100644 --- a/src/user.c +++ b/src/user.c @@ -862,7 +862,7 @@ INTERNAL void user_update(void) if (slice.has_ray) { struct v2 ray = xform_basis_mul_v2(ent->sprite_xform_world, slice.dir); ray = xform_basis_mul_v2(G.world_view, ray); - ray = v2_mul(v2_norm(ray), 50); + ray = v2_mul(v2_norm(ray), 25); draw_solid_arrow_ray(G.viewport_canvas, center, ray, 2, 10, RGBA_32_F(1, 0, 0.5, 1)); } }