From 6ff41c431132706d0f844f88df78650551aac925 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Mon, 21 Aug 2023 18:06:15 -0400 Subject: [PATCH] Support velocity for droid dying animation effect Based on droid's last movement direction and speed --- src/droid.cpp | 9 ++++++++- src/effects.cpp | 16 ++++++++++++++-- src/effects.h | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/droid.cpp b/src/droid.cpp index a8e0bde6bd1..10406411e2e 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -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; @@ -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); } } } diff --git a/src/effects.cpp b/src/effects.cpp index dcacbd37873..00ff6d7b9c8 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -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 @@ -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()) { @@ -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; diff --git a/src/effects.h b/src/effects.h index af864d89d36..1e9261644a9 100644 --- a/src/effects.h +++ b/src/effects.h @@ -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);