Given a model pointer and an array of floats that go from 0..1, calculate the interpolated position/angle of each corresponding subobject
| 2589 | // Given a model pointer and an array of floats that go from 0..1, calculate the interpolated |
| 2590 | // position/angle of each corresponding subobject |
| 2591 | void SetModelAnglesAndPosTimed(poly_model *po, float *normalized_time, uint32_t subobj_flags) { |
| 2592 | int i; |
| 2593 | |
| 2594 | ASSERT(!(po->flags & PMF_NOT_RESIDENT)); |
| 2595 | |
| 2596 | if (normalized_time) { |
| 2597 | // get time per keyframe state |
| 2598 | |
| 2599 | for (i = 0; i < po->n_models; i++) { |
| 2600 | bsp_info *sm = &po->submodel[i]; |
| 2601 | int int_tick, current_frame, total_ticks; |
| 2602 | float normal_state_time, current_tick; |
| 2603 | |
| 2604 | if (!(subobj_flags & (1 << i))) |
| 2605 | continue; |
| 2606 | |
| 2607 | if (sm->num_key_pos <= 1) { |
| 2608 | vm_MakeZero(&sm->mod_pos); |
| 2609 | goto do_angles; |
| 2610 | } |
| 2611 | |
| 2612 | if (normalized_time[i] == 1.0) { |
| 2613 | sm->mod_pos = sm->keyframe_pos[sm->num_key_pos - 1]; |
| 2614 | goto do_angles; |
| 2615 | } |
| 2616 | |
| 2617 | // Find out which keyframe we're at |
| 2618 | total_ticks = sm->pos_track_max - sm->pos_track_min; |
| 2619 | current_tick = (normalized_time[i] * total_ticks) + sm->pos_track_min; |
| 2620 | int_tick = current_tick; |
| 2621 | current_frame = sm->tick_pos_remap[int_tick - sm->pos_track_min]; |
| 2622 | |
| 2623 | ASSERT(current_frame >= 0 && current_frame <= sm->num_key_pos - 1); |
| 2624 | |
| 2625 | if (current_frame == sm->num_key_pos - 1) { |
| 2626 | sm->mod_pos = sm->keyframe_pos[sm->num_key_pos - 1]; |
| 2627 | goto do_angles; |
| 2628 | } else { |
| 2629 | int ticks_between_frames = sm->pos_start_time[current_frame + 1] - sm->pos_start_time[current_frame]; |
| 2630 | float this_tick = current_tick - sm->pos_start_time[current_frame]; |
| 2631 | normal_state_time = (float)this_tick / (float)ticks_between_frames; |
| 2632 | |
| 2633 | vector subpos; |
| 2634 | vm_SubVectors(&subpos, &sm->keyframe_pos[current_frame + 1], &sm->keyframe_pos[current_frame]); |
| 2635 | sm->mod_pos = sm->keyframe_pos[current_frame] + (subpos * normal_state_time); |
| 2636 | } |
| 2637 | |
| 2638 | // Now do angle stuff here |
| 2639 | do_angles: |
| 2640 | // Don't rotate turrets or auto-rotators |
| 2641 | if (!(sm->flags & (SOF_TURRET | SOF_ROTATE))) { |
| 2642 | if (sm->num_key_angles <= 1) { |
| 2643 | sm->angs.p = 0; |
| 2644 | sm->angs.h = 0; |
| 2645 | sm->angs.b = 0; |
| 2646 | continue; |
| 2647 | } |
| 2648 |
no test coverage detected