Skip to content

Commit

Permalink
NX/VITA: Replace standard EF_ROTATE with one that mimicks Power-Up …
Browse files Browse the repository at this point in the history
…behavior
  • Loading branch information
MotoLegacy authored Apr 8, 2024
1 parent 637bc87 commit 3f55696
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions source/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,61 @@ float CL_LerpPoint (void)
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;
}
}

/*
===============
CL_RelinkEntities
Expand All @@ -434,13 +489,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;

//
Expand All @@ -464,8 +520,6 @@ void CL_RelinkEntities (void)
}
}

bobjrotate = anglemod(100*cl.time);

// start on the entity after the world
for (i=1,ent=cl_entities+1 ; i<cl.num_entities ; i++,ent++)
{
Expand Down Expand Up @@ -525,8 +579,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)
{
Expand Down

0 comments on commit 3f55696

Please sign in to comment.