Skip to content

Commit 0fd4455

Browse files
committed
Smoke particle fx
1 parent 984b5d2 commit 0fd4455

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

Client/game_sa/CFxSA.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ class FxSystem_c;
3232
#define FUNC_CFx_TriggerFootSplash 0x4a1150
3333
#define FUNC_FXSystem_c_AddParticle 0x4AA440
3434

35+
struct FxPrtMult_c
36+
{
37+
struct
38+
{
39+
float red;
40+
float green;
41+
float blue;
42+
float alpha;
43+
} m_color;
44+
45+
float m_fSize;
46+
float unk;
47+
float m_fLife;
48+
};
49+
3550
class CFxSAInterface
3651
{
3752
public:
@@ -61,6 +76,8 @@ class CFxSA : public CFx
6176
public:
6277
CFxSA(CFxSAInterface* pInterface) { m_pInterface = pInterface; }
6378

79+
CFxSAInterface* GetInterface() noexcept { return m_pInterface; }
80+
6481
void AddBlood(CVector& vecPosition, CVector& vecDirection, int iCount, float fBrightness);
6582
void AddWood(CVector& vecPosition, CVector& vecDirection, int iCount, float fBrightness);
6683
void AddSparks(CVector& vecPosition, CVector& vecDirection, float fForce, int iCount, CVector vecAcrossLine, unsigned char ucBlurIf0, float fSpread,
@@ -80,19 +97,4 @@ class CFxSA : public CFx
8097

8198
private:
8299
CFxSAInterface* m_pInterface;
83-
84-
struct FxPrtMult_c
85-
{
86-
struct
87-
{
88-
float red;
89-
float green;
90-
float blue;
91-
float alpha;
92-
} m_color;
93-
94-
float m_fSize;
95-
float unk;
96-
float m_fLife;
97-
};
98100
};

Client/game_sa/CProjectileInfoSA.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "CColModelSA.h"
2323

2424
#include "CExplosionManagerSA.h"
25+
#include "CFxSA.h"
2526

2627
extern CGameSA* pGame;
2728

@@ -336,7 +337,42 @@ void CProjectileInfoSA::Update()
336337

337338
if (projectileInfo->m_weaponType == eWeaponType::WEAPONTYPE_ROCKET || projectileInfo->m_weaponType == eWeaponType::WEAPONTYPE_ROCKET_HS)
338339
{
339-
// fx particle
340+
FxPrtMult_c fxPrt{{0.3f, 0.3f, 0.3f, 0.3f}, 0.5f, 1.0f, 0.08f};
341+
const CVector& pos = projectile->matrix ? projectile->matrix->vPos : projectile->m_transform.m_translate;
342+
343+
CVector velocity = projectile->m_vecLinearVelocity * pGame->GetTimeStep();
344+
float len = velocity.Length();
345+
int particleCount = 1;
346+
if (len >= 1.0f)
347+
particleCount = static_cast<int>(len);
348+
349+
for (std::size_t i = 0; i < particleCount; i++)
350+
{
351+
fxPrt.m_color.red = rand() * 0.000030518509f * 0.25f + 0.25f;
352+
fxPrt.m_color.green = fxPrt.m_color.red;
353+
fxPrt.m_color.blue = fxPrt.m_color.red;
354+
355+
fxPrt.m_fLife = rand() * 0.000030518509f * 0.04f + 0.08f;
356+
357+
float t = 1.0f - (static_cast<float>(i) / static_cast<float>(particleCount));
358+
359+
CVector prtPos = pos - velocity * t;
360+
361+
int rand1 = rand();
362+
int rand2 = rand();
363+
int rand3 = rand();
364+
CVector prtVel = CVector(rand1 * 0.000030518509f + rand1 * 0.000030518509f - 1.0f, rand2 * 0.000030518509f + rand2 * 0.000030518509f - 1.0f, rand3 * 0.000030518509f + rand3 * 0.000030518509f - 1.0f);
365+
prtVel.Normalize();
366+
367+
CVector objectVelocity = projectile->m_vecLinearVelocity;
368+
objectVelocity.Normalize();
369+
370+
objectVelocity.CrossProduct(&prtVel);
371+
objectVelocity *= 1.5f;
372+
373+
// Call FxSystem_c::AddParticle
374+
((int(__thiscall*)(FxSystem_c*, const CVector*, const CVector*, float, FxPrtMult_c*, float, float, float, int))FUNC_FXSystem_c_AddParticle)(pGame->GetFx()->GetInterface()->m_fxSysSmokeHuge, &prtPos, &objectVelocity, 0, &fxPrt, -1.0f, 1.2f, 0.6f, 0);
375+
}
340376
}
341377

342378
if (projectileInfo->m_counter > 0 && pGame->GetSystemTime() > projectileInfo->m_counter)

Client/sdk/game/CFx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#pragma once
1313
#include "enums/FxParticleSystems.h"
1414

15+
class CFxSAInterface;
1516
class CEntity;
1617
class CVector;
1718
class CVehicle;
@@ -20,6 +21,8 @@ struct RwColor;
2021
class CFx
2122
{
2223
public:
24+
virtual CFxSAInterface* GetInterface() = 0;
25+
2326
virtual void AddBlood(CVector& vecPosition, CVector& vecDirection, int iCount, float fBrightness) = 0;
2427
virtual void AddWood(CVector& vecPosition, CVector& vecDirection, int iCount, float fBrightness) = 0;
2528
virtual void AddSparks(CVector& vecPosition, CVector& vecDirection, float fForce, int iCount, CVector vecAcrossLine, unsigned char ucBlurIf0, float fSpread,

0 commit comments

Comments
 (0)