update tim test image
This commit is contained in:
parent
3049e02b57
commit
bda472d15e
BIN
res/graphics/tim.ase
(Stored with Git LFS)
BIN
res/graphics/tim.ase
(Stored with Git LFS)
Binary file not shown.
74
src/game.c
74
src/game.c
@ -350,64 +350,42 @@ INTERNAL void game_update(void)
|
|||||||
/* Update focus */
|
/* Update focus */
|
||||||
ent->focus = G.world.player_aim;
|
ent->focus = G.world.player_aim;
|
||||||
|
|
||||||
#if 0
|
/* Solve for missing angle using law of sines */
|
||||||
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite);
|
f32 final_xf_angle;
|
||||||
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;
|
|
||||||
{
|
{
|
||||||
struct v2 center = xform_mul_v2(ent->sprite_xform_world, slice.center);
|
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite);
|
||||||
struct v2 center_dir = v2_norm(xform_basis_mul_v2(ent->sprite_xform_world, slice.dir));
|
struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, STR("hold"), ent->animation_frame);
|
||||||
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 xform xf = ent->xform;
|
struct xform xf = ent->xform_world;
|
||||||
|
|
||||||
struct v2 ent_pos = ent->xform_world.og;
|
f32 forward_hold_angle_offset;
|
||||||
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));
|
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 ent_pos = xf.og;
|
||||||
struct v2 hold_ent_dir = v2_sub(ent_pos, hold_pos);
|
struct v2 focus_pos = v2_add(ent_pos, ent->focus);
|
||||||
struct v2 focus_ent_dir = v2_sub(ent_pos, focus_pos);
|
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);
|
struct v2 hold_dir = xform_basis_mul_v2(xf, xform_basis_mul_v2(ent->sprite_xform, slice.dir));
|
||||||
f32 focus_ent_len = v2_len(focus_ent_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 hold_ent_len = v2_len(hold_ent_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 focus_ent_len = v2_len(focus_ent_dir);
|
||||||
f32 final_ent_angle_btw_focus_and_hold = PI - (final_focus_angle_btw_ent_and_hold + final_hold_angle_btw_ent_and_focus);
|
|
||||||
|
|
||||||
f32 final_hold_ent_angle_offset;
|
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);
|
||||||
struct xform ent_world_xform_unrotated = xform_with_rotation(ent->xform_world, 0);
|
f32 final_ent_angle_btw_focus_and_hold = PI - (final_focus_angle_btw_ent_and_hold + final_hold_angle_btw_ent_and_focus);
|
||||||
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)));
|
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_xf_angle)) {
|
||||||
|
ent->xform = xform_with_rotation(ent->xform_world, final_xf_angle);
|
||||||
if (!F32_IS_NAN(final_ent_angle)) {
|
|
||||||
xf = xform_with_rotation(xf, final_ent_angle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ent->xform = xf;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
@ -862,7 +862,7 @@ INTERNAL void user_update(void)
|
|||||||
if (slice.has_ray) {
|
if (slice.has_ray) {
|
||||||
struct v2 ray = xform_basis_mul_v2(ent->sprite_xform_world, slice.dir);
|
struct v2 ray = xform_basis_mul_v2(ent->sprite_xform_world, slice.dir);
|
||||||
ray = xform_basis_mul_v2(G.world_view, ray);
|
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));
|
draw_solid_arrow_ray(G.viewport_canvas, center, ray, 2, 10, RGBA_32_F(1, 0, 0.5, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user