diff --git a/source/cl_main.c b/source/cl_main.c index 13aebf6..8d3a16c 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -476,6 +476,60 @@ SetPal(2); return frac; } +float mdlflag_poweruprotate_duration = 0.0f; +float mdlflag_poweruprotate_starttime = 0.0f; + +vec3_t mdlflag_poweruprotate_startangles; +vec3_t mdlflag_poweruprotate_differenceangles; +vec3_t mdlflag_poweruprotate_currentangles; + +double last_puframetime = 0.0f; + +/* +=============== +CL_UpdatePowerUpAngles +=============== +*/ +void CL_UpdatePowerUpAngles (void) +{ + // Don't update more than once per frame. + if (last_puframetime != host_frametime) { + // New cycle, dictate new rotation time and target angle. + if (mdlflag_poweruprotate_duration <= cl.time) { + mdlflag_poweruprotate_starttime = cl.time; + mdlflag_poweruprotate_duration = cl.time + (float)((rand() % 25 + 25)/10.0f); // Take between 2.5 and 5 seconds. + + mdlflag_poweruprotate_startangles[0] = mdlflag_poweruprotate_currentangles[0]; + mdlflag_poweruprotate_startangles[1] = mdlflag_poweruprotate_currentangles[1]; + mdlflag_poweruprotate_startangles[2] = mdlflag_poweruprotate_currentangles[2]; + + int target_pitch = rand() % 120 - 60; + int target_yaw = rand() % 240 + 60; + int target_roll = rand() % 90 - 45; + + vec3_t target_angles; + target_angles[0] = target_pitch; + target_angles[1] = target_yaw; + target_angles[2] = target_roll; + + // Calculate the difference from our start to our target. + for(int i = 0; i < 2; i++) { + if (mdlflag_poweruprotate_currentangles[i] > target_angles[i]) + mdlflag_poweruprotate_differenceangles[i] = (mdlflag_poweruprotate_currentangles[i] - target_angles[i]) * -1; + else + mdlflag_poweruprotate_differenceangles[i] = fabs(mdlflag_poweruprotate_currentangles[i] - target_angles[i]); + } + } + + float percentage_complete = (cl.time - mdlflag_poweruprotate_starttime) / (mdlflag_poweruprotate_duration - mdlflag_poweruprotate_starttime); + + for(int j = 0; j < 2; j++) { + mdlflag_poweruprotate_currentangles[j] = mdlflag_poweruprotate_startangles[j] + (mdlflag_poweruprotate_differenceangles[j] * percentage_complete); + } + + last_puframetime = host_frametime; + } +} /* =============== @@ -488,13 +542,14 @@ void CL_RelinkEntities (void) int i, j; float frac, f, d; vec3_t delta; - float bobjrotate; vec3_t oldorg; dlight_t *dl; // determine partial update time frac = CL_LerpPoint (); + CL_UpdatePowerUpAngles(); + cl_numvisedicts = 0; cl_numstaticbrushmodels = 0; @@ -587,8 +642,11 @@ void CL_RelinkEntities (void) } // rotate binary objects locally - if (ent->model->flags & EF_ROTATE) - ent->angles[1] = bobjrotate; + if (ent->model->flags & EF_ROTATE) { + ent->angles[0] = mdlflag_poweruprotate_currentangles[0]; + ent->angles[1] = mdlflag_poweruprotate_currentangles[1]; + ent->angles[2] = mdlflag_poweruprotate_currentangles[2]; + } if (ent->effects & EF_MUZZLEFLASH) {