MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / SetModelAngles

Function SetModelAngles

model/polymodel.cpp:2417–2530  ·  view source on GitHub ↗

Given a model pointer and an array of floats that go from 0..1, calculate the angles of each corresponding subobject

Source from the content-addressed store, hash-verified

2415// Given a model pointer and an array of floats that go from 0..1, calculate the angles of each
2416// corresponding subobject
2417void SetModelAngles(poly_model *po, const float *normalized_angles) {
2418 int i;
2419
2420 ASSERT(!(po->flags & PMF_NOT_RESIDENT));
2421
2422 if (po->num_key_angles > 0 && normalized_angles) {
2423 // get time per keyframe state
2424 float state_time = 1.0 / (po->num_key_angles - 1);
2425 float cur_state_time;
2426 int cur_state;
2427 float normal_state_time;
2428
2429 for (i = 0; i < po->n_models; i++) {
2430 // Don't rotate turrets or auto-rotators or weapon battery submodels
2431 if (!(po->submodel[i].flags & (SOF_ROTATE | SOF_TURRET))) {
2432
2433 // Find out which keyframe we're at
2434
2435 cur_state = normalized_angles[i] / state_time;
2436 matrix dest_matrix;
2437
2438 // Find out how far into that keyframe we are
2439 cur_state_time = normalized_angles[i] - ((float)cur_state * state_time);
2440 normal_state_time = cur_state_time / state_time;
2441
2442 // Now do a parametric adjustment on the angles
2443
2444 int cur_angle = 0;
2445
2446 // If we're already at the high point of the interpolation then just
2447 // stuff some values
2448 if (cur_state == po->num_key_angles - 1) {
2449 vm_ExtractAnglesFromMatrix(&po->submodel[i].angs, &po->submodel[i].keyframe_matrix[po->num_key_angles - 1]);
2450 continue;
2451 }
2452
2453 dest_matrix = po->submodel[i].keyframe_matrix[cur_state] +
2454 ((po->submodel[i].keyframe_matrix[cur_state + 1] - po->submodel[i].keyframe_matrix[cur_state]) *
2455 normal_state_time);
2456
2457 vm_ExtractAnglesFromMatrix(&po->submodel[i].angs, &dest_matrix);
2458 // po->submodel[i].mod_matrix=dest_matrix;
2459
2460 } else if (po->submodel[i].flags & SOF_ROTATE) {
2461 float flrot = Gametime * po->submodel[i].rps;
2462 int introt = flrot;
2463
2464 float fdiff = flrot - introt;
2465
2466 ASSERT(fdiff >= 0 && fdiff <= 1);
2467
2468 // fdiff now equals 0 to 1
2469 matrix temp_matrix;
2470 vector temp_vec;
2471 if (po->new_style)
2472 temp_vec = po->submodel[i].keyframe_axis[1];
2473 else
2474 temp_vec = po->submodel[i].norm;

Callers 2

SetModelAnglesAndPosFunction · 0.85
VisEffectMoveOneFunction · 0.85

Calls 2

BuildModelAngleMatrixFunction · 0.70

Tested by

no test coverage detected