Given a model pointer and an array of floats that go from 0..1, calculate the interpolated position of each corresponding subobject
| 2532 | // Given a model pointer and an array of floats that go from 0..1, calculate the interpolated |
| 2533 | // position of each corresponding subobject |
| 2534 | void SetModelInterpPos(poly_model *po, const float *normalized_pos) { |
| 2535 | int i; |
| 2536 | |
| 2537 | ASSERT(!(po->flags & PMF_NOT_RESIDENT)); |
| 2538 | |
| 2539 | if (normalized_pos && po->num_key_pos > 0) { |
| 2540 | for (i = 0; i < po->n_models; i++) { |
| 2541 | bsp_info *sm = &po->submodel[i]; |
| 2542 | |
| 2543 | // get time per keyframe state |
| 2544 | float state_time = 1.0 / (po->num_key_pos - 1); |
| 2545 | float cur_state_time; |
| 2546 | int cur_state; |
| 2547 | float normal_state_time; |
| 2548 | |
| 2549 | // Find out which keyframe we're at |
| 2550 | cur_state = normalized_pos[i] / state_time; |
| 2551 | |
| 2552 | // Find out how far into that keyframe we are |
| 2553 | cur_state_time = normalized_pos[i] - ((float)cur_state * state_time); |
| 2554 | normal_state_time = cur_state_time / state_time; |
| 2555 | |
| 2556 | // Now do a parametric adjustment on the positions |
| 2557 | |
| 2558 | vector total_delta_pos = {0, 0, 0}; |
| 2559 | vector subpos; |
| 2560 | vector final_pos; |
| 2561 | |
| 2562 | // If we're already at the high point of the interpolation then just |
| 2563 | // stuff some values |
| 2564 | if (cur_state == sm->num_key_pos - 1) { |
| 2565 | po->submodel[i].mod_pos = po->submodel[i].keyframe_pos[po->num_key_pos - 1]; |
| 2566 | continue; |
| 2567 | } |
| 2568 | |
| 2569 | if (cur_state == 0) |
| 2570 | po->submodel[i].mod_pos = normal_state_time * po->submodel[i].keyframe_pos[1]; |
| 2571 | else { |
| 2572 | vm_SubVectors(&subpos, &po->submodel[i].keyframe_pos[cur_state + 1], &po->submodel[i].keyframe_pos[cur_state]); |
| 2573 | final_pos = po->submodel[i].keyframe_pos[cur_state] + (subpos * normal_state_time); |
| 2574 | po->submodel[i].mod_pos = final_pos; |
| 2575 | } |
| 2576 | } |
| 2577 | } else { |
| 2578 | for (i = 0; i < po->n_models; i++) { |
| 2579 | po->submodel[i].mod_pos.x = 0; |
| 2580 | po->submodel[i].mod_pos.y = 0; |
| 2581 | po->submodel[i].mod_pos.z = 0; |
| 2582 | } |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | // Sets the effect used by a polymodel |
| 2587 | void SetPolymodelEffect(polymodel_effect *poly_effect) { Polymodel_effect = *poly_effect; } |
no test coverage detected