Skip to content

Commit

Permalink
Support velocity for droid dying animation effect
Browse files Browse the repository at this point in the history
Based on droid's last movement direction and speed
  • Loading branch information
past-due committed Aug 21, 2023
1 parent 7c59375 commit f1b9959
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ int droidReloadBar(const BASE_OBJECT *psObj, const WEAPON *psWeap, int weapon_sl

void addDroidDeathAnimationEffect(DROID *psDroid)
{
// DERIVED from moveCalcNormalSpeed and moveGetDroidPosDiffs:

uint16_t iDroidDir = psDroid->rot.direction;
uint16_t adiff = (uint16_t)(iDroidDir - psDroid->sMove.moveDir); // Cast wrapping intended.
int move = iCosR(adiff, psDroid->sMove.speed);
Vector3f velocity(iSinR(iDroidDir, move), iCosR(iDroidDir, move), 0.f);

// DERIVED FROM displayComponentObject:

Vector3i position, rotation;
Expand Down Expand Up @@ -252,7 +259,7 @@ void addDroidDeathAnimationEffect(DROID *psDroid)

SetEffectForPlayer(psDroid->player);
effectSetSize(100);
addEffect(&position, EFFECT_DROID_ANIMEVENT_DYING, type, true, strImd, 0, graphicsTime, &rotation);
addEffect(&position, EFFECT_DROID_ANIMEVENT_DYING, type, true, strImd, 0, graphicsTime, &rotation, &velocity);
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,20 @@ void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool s
return addEffect(pos, group, type, specified, imd, lit, graphicsTime);
}

static bool updateDroidDeathAnimationEffect(const EFFECT *psEffect)
static bool updateDroidDeathAnimationEffect(EFFECT *psEffect)
{
iIMDShape *imd = psEffect->imd;
if (!imd)
{
return false;
}

/* Move it */
auto deltaX = graphicsTimeAdjustedIncrement(psEffect->velocity.x);
auto deltaY = graphicsTimeAdjustedIncrement(psEffect->velocity.y);
psEffect->position.x += deltaX;
psEffect->position.z += deltaY;

// NOTE: We actually store the timeAnimationStarted (in gameTime) in psEffect->lastFrame
UDWORD timeAnimationStarted = psEffect->lastFrame;
int objanimcycles = (imd->objanimcycles > 0) ? imd->objanimcycles : 1; // do not allow infinite looping for death animations
Expand Down Expand Up @@ -347,7 +354,7 @@ static void renderDroidDeathAnimationEffect(const EFFECT *psEffect, const glm::m
}
}

void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit, unsigned effectTime, Vector3i *rot /*= nullptr*/)
void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit, unsigned effectTime, Vector3i *rot /*= nullptr*/, Vector3f *velocity /*= nullptr*/)
{
if (gamePaused())
{
Expand All @@ -369,6 +376,11 @@ void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool s
psEffect->rotation.z = rot->z;
}

if (velocity)
{
psEffect->velocity = *velocity;
}

/* Now, note group and type */
psEffect->group = group;
psEffect->type = type;
Expand Down
2 changes: 1 addition & 1 deletion src/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void initEffectsSystem();
void shutdownEffectsSystem();
void processEffects(const glm::mat4 &perspectiveViewMatrix);
void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit);
void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit, unsigned effectTime, Vector3i *rot = nullptr);
void addEffect(const Vector3i *pos, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, int lit, unsigned effectTime, Vector3i *rot = nullptr, Vector3f *velocity = nullptr);
void addMultiEffect(const Vector3i *basePos, Vector3i *scatter, EFFECT_GROUP group, EFFECT_TYPE type, bool specified, iIMDShape *imd, unsigned int number, bool lit, unsigned int size, unsigned effectTime);

void renderEffect(const EFFECT *psEffect, const glm::mat4 &viewMatrix);
Expand Down

0 comments on commit f1b9959

Please sign in to comment.