Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timleader committed Oct 21, 2023
1 parent 5564ae7 commit 0be6178
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
8 changes: 8 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

## todo

- State_Model
- better camera controls
- animation playback support
- Model / Texturing improvements
- Polygon sorting
- rendering optimizations
- floor mesh crash
- Create alternative characters

-------------------------------------

Expand Down
1 change: 0 additions & 1 deletion source/common/graphics/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,5 @@ animation_t* model_find_animation_from_name(model_ptr model, const char* name);

int16_t model_find_animation_index_of(model_ptr model, const char* name);


#endif // !MODEL_H

27 changes: 22 additions & 5 deletions source/common/states/debug/state_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ typedef struct st_model_context_s
model_ptr g_character;
image_ptr g_character_img;

uint32_t frame_idx;
int32_t animation_idx;
int32_t frame_idx;

} st_model_context_t;

Expand Down Expand Up @@ -56,12 +57,22 @@ void st_modelviewer_update(st_model_context_ptr context, fixed16_t dt)

if (key_is_down(KI_L))
{
context->frame_idx--;
context->animation_idx--;

if (context->animation_idx < 0)
context->animation_idx = context->g_character->animation_count - 1;

context->frame_idx = 0;
}

if (key_is_down(KI_R))
{
context->frame_idx++;
context->animation_idx++;

if (context->animation_idx > context->g_character->animation_count - 1)
context->animation_idx = 0;

context->frame_idx = 0;
}

if (key_hit(KI_B))
Expand All @@ -78,6 +89,11 @@ void st_modelviewer_update(st_model_context_ptr context, fixed16_t dt)
state_push(&st_analysis, 0);
}

animation_t* animation = model_find_animation(context->g_character, context->animation_idx);

context->frame_idx++;
if (context->frame_idx > animation->frame_count - 1)
context->frame_idx = 0;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -110,7 +126,7 @@ void st_modelviewer_draw(st_model_context_ptr context, fixed16_t dt)

mathMatrix4x4Multiply(&M, &context->WVP, &M);

graphics_draw_model(context->g_character, 0, context->frame_idx, &M);
graphics_draw_model(context->g_character, (uint16_t)context->animation_idx, (uint16_t)context->frame_idx, &M);

graphics_pageflip();
}
Expand All @@ -135,11 +151,12 @@ void st_modelviewer_enter(st_model_context_ptr context, uint32_t parameter)
mathVector3MakeFromElements(&context->character_rotation, fixed16_mul(fixed16_zero, deg2rad), fixed16_mul(fixed16_from_int(-180), deg2rad), fixed16_zero);

context->g_character = resources_find_model(resource_id);
context->g_character_img = resources_find_image(4);// context->g_character->image_id); // these ids will normally be acquired from a levels resource
context->g_character_img = resources_find_image(context->g_character->image_id);

palette_ptr pal = resources_find_palette(context->g_character_img->palette_id);
graphics_write_palette(pal);

context->animation_idx = 0;
context->frame_idx = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/7days/entities/model_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void entity_draw(entity_ptr entity, matrix4x4_t* wvp)

// move this palette write to only happen once
palette_ptr pal = resources_find_palette(img->palette_id);
graphics_write_palette(pal);
graphics_write_palette(pal); // this can't happen here, due to potential conflicts

graphics_draw_model(model, entity->animation_id, fixed16_to_int(entity->frame_precise), &M);
}
Expand Down

0 comments on commit 0be6178

Please sign in to comment.