set local xform when applying child attachment
This commit is contained in:
parent
4ce85c1bef
commit
bdcc6a8c81
15
src/game.c
15
src/game.c
@ -145,6 +145,8 @@ INTERNAL void spawn_test_entities(void)
|
|||||||
e->mass_unscaled = 70;
|
e->mass_unscaled = 70;
|
||||||
e->ground_friction = 1000;
|
e->ground_friction = 1000;
|
||||||
|
|
||||||
|
entity_enable_prop(e, ENTITY_PROP_TEST);
|
||||||
|
|
||||||
player_ent = e;
|
player_ent = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,24 +480,22 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
|||||||
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
||||||
struct entity *ent = &store->entities[entity_index];
|
struct entity *ent = &store->entities[entity_index];
|
||||||
if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue;
|
if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue;
|
||||||
|
if (!entity_has_prop(ent, ENTITY_PROP_ATTACHED)) continue;
|
||||||
|
|
||||||
if (entity_has_prop(ent, ENTITY_PROP_ATTACHED)) {
|
|
||||||
struct entity *parent = entity_from_handle(store, ent->parent);
|
struct entity *parent = entity_from_handle(store, ent->parent);
|
||||||
struct sprite_tag parent_sprite = parent->sprite;
|
struct sprite_tag parent_sprite = parent->sprite;
|
||||||
struct sprite_sheet *parent_sheet = sprite_sheet_from_tag_await(sprite_frame_scope, parent_sprite);
|
struct sprite_sheet *parent_sheet = sprite_sheet_from_tag_await(sprite_frame_scope, parent_sprite);
|
||||||
|
|
||||||
struct xform parent_xf = entity_get_xform(parent);
|
struct xform parent_sprite_xf = parent->sprite_local_xform;
|
||||||
struct xform parent_sprite_xf = xform_mul(parent_xf, parent->sprite_local_xform);
|
|
||||||
|
|
||||||
struct sprite_sheet_slice attach_slice = sprite_sheet_get_slice(parent_sheet, ent->attach_slice, parent->animation_frame);
|
struct sprite_sheet_slice attach_slice = sprite_sheet_get_slice(parent_sheet, ent->attach_slice, parent->animation_frame);
|
||||||
struct v2 attach_pos = xform_mul_v2(parent_sprite_xf, attach_slice.center);
|
struct v2 attach_pos = xform_mul_v2(parent_sprite_xf, attach_slice.center);
|
||||||
struct v2 attach_dir = xform_basis_mul_v2(parent_sprite_xf, attach_slice.dir);
|
struct v2 attach_dir = xform_basis_mul_v2(parent_sprite_xf, attach_slice.dir);
|
||||||
|
|
||||||
struct xform xf = entity_get_xform(ent);
|
struct xform xf = entity_get_local_xform(ent);
|
||||||
xf.og = attach_pos;
|
xf.og = attach_pos;
|
||||||
xf = xform_rotated_to(xf, v2_angle(attach_dir) + PI / 2);
|
xf = xform_rotated_to(xf, v2_angle(attach_dir) + PI / 2);
|
||||||
entity_set_xform(ent, xf);
|
entity_set_local_xform(ent, xf);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
@ -566,8 +566,8 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
|||||||
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
for (u64 entity_index = 0; entity_index < store->reserved; ++entity_index) {
|
||||||
struct entity *ent = &store->entities[entity_index];
|
struct entity *ent = &store->entities[entity_index];
|
||||||
if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue;
|
if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue;
|
||||||
|
if (!entity_has_prop(ent, ENTITY_PROP_TEST)) continue;
|
||||||
|
|
||||||
if (entity_has_prop(ent, ENTITY_PROP_TEST)) {
|
|
||||||
if (!ent->test_initialized) {
|
if (!ent->test_initialized) {
|
||||||
ent->test_initialized = true;
|
ent->test_initialized = true;
|
||||||
ent->test_start_local_xform = entity_get_local_xform(ent);
|
ent->test_start_local_xform = entity_get_local_xform(ent);
|
||||||
@ -592,7 +592,6 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
|
|||||||
xf = xform_scaled_to(xf, s);
|
xf = xform_scaled_to(xf, s);
|
||||||
entity_set_local_xform(ent, xf);
|
entity_set_local_xform(ent, xf);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Trigger equipped
|
* Trigger equipped
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user