From 7ce88772db2b2ed443cfbfff1bdf1775e1123619 Mon Sep 17 00:00:00 2001 From: Raildex Date: Sun, 16 Aug 2020 16:01:24 +0200 Subject: [PATCH] Adjusted GunSmoke --- TR5Main/Game/smoke.cpp | 31 ++++++++++++++++--------------- TR5Main/Game/smoke.h | 1 - TR5Main/Game/trmath.cpp | 20 +++++++++++++++++++- TR5Main/Game/trmath.h | 2 ++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/TR5Main/Game/smoke.cpp b/TR5Main/Game/smoke.cpp index d4e060949..9e7913db1 100644 --- a/TR5Main/Game/smoke.cpp +++ b/TR5Main/Game/smoke.cpp @@ -10,7 +10,14 @@ namespace T5M { namespace Effects { namespace Smoke { std::array SmokeParticles; - + SmokeParticle& getFreeSmokeParticle() + { + for(int i = 0; i < SmokeParticles.size(); i++){ + if(!SmokeParticles[i].active) + return SmokeParticles[i]; + } + return SmokeParticles[0]; + } void UpdateSmokeParticles() { for (int i = 0; i < SmokeParticles.size(); i++) { @@ -70,23 +77,15 @@ namespace T5M { s.room = room; } - SmokeParticle& getFreeSmokeParticle() - { - for (int i = 0; i < SmokeParticles.size(); i++) { - if (!SmokeParticles[i].active) - return SmokeParticles[i]; - } - return SmokeParticles[0]; - } - void TriggerGunSmokeParticles(int x, int y, int z, short xv, short yv, short zv, byte initial, int weaponType, byte count) { SmokeParticle& s = getFreeSmokeParticle(); s = {}; s.active = true; s.position = Vector3(x, y, z); - Vector3(xv, yv, zv).Normalize(s.velocity); - s.velocity *= frand() * 24 + 16; + Vector3 dir = Vector3(xv, yv, zv); + dir.Normalize(); + s.velocity = dir; s.gravity = -.1f; s.affectedByWind = g_Level.Rooms[LaraItem->roomNumber].flags & ENV_FLAG_WIND; s.sourceColor = Vector4(.4, .4, .4, 1); @@ -98,9 +97,10 @@ namespace T5M { s.sourceSize = size *2; s.destinationSize = size * 8; s.terminalVelocity = 0; - s.friction = 0.90f; + s.friction = 0.88f; s.life = frand() * 30 + 60; - + s.velocity = getRandomVectorInCone(s.velocity, 10); + s.velocity *= frand() * 14 + 16; } else { @@ -111,13 +111,14 @@ namespace T5M { s.terminalVelocity = 0; s.friction = 0.97f; s.life = frand() * 20 + 42; + s.velocity *= frand() * 24 + 16; } s.position = Vector3(x, y, z); s.position += Vector3(frandMinMax(-8, 8), frandMinMax(-8, 8), frandMinMax(-8, 8)); s.angularVelocity = frandMinMax(-PI / 4, PI / 4); - s.angularDrag = 0.8f; + s.angularDrag = 0.95f; s.room = LaraItem->roomNumber; } diff --git a/TR5Main/Game/smoke.h b/TR5Main/Game/smoke.h index 879712e59..30cca65ce 100644 --- a/TR5Main/Game/smoke.h +++ b/TR5Main/Game/smoke.h @@ -32,7 +32,6 @@ namespace T5M{ void UpdateSmokeParticles(); void TriggerFlareSmoke(const DirectX::SimpleMath::Vector3& pos, DirectX::SimpleMath::Vector3& direction, int age, int room); - SmokeParticle& getFreeSmokeParticle(); void TriggerGunSmokeParticles(int x, int y, int z, short xv, short yv, short zv, byte initial, int weaponType, byte count); } diff --git a/TR5Main/Game/trmath.cpp b/TR5Main/Game/trmath.cpp index d13766ffb..2f9c1aea7 100644 --- a/TR5Main/Game/trmath.cpp +++ b/TR5Main/Game/trmath.cpp @@ -1325,7 +1325,7 @@ float TO_RAD(short angle) const float frand() { - float result = float((float)rand() / RAND_MAX); + float result = float(static_cast(rand()) / RAND_MAX); return result; } @@ -1339,6 +1339,24 @@ const float lerp(float v0, float v1, float t) return (1 - t) * v0 + t * v1; } +const Vector3 getRandomVector() +{ + Vector3 v = {frandMinMax(-1,1),frandMinMax(-1,1),frandMinMax(-1,1)}; + v.Normalize(); + return v; +} + +const Vector3 getRandomVectorInCone(const Vector3& direction, const float angleDegrees) +{ + float x = frandMinMax(-angleDegrees, angleDegrees) * RADIAN; + float y = frandMinMax(-angleDegrees, angleDegrees) * RADIAN; + float z = frandMinMax(-angleDegrees, angleDegrees) * RADIAN; + Matrix m = Matrix::CreateRotationX(x)* Matrix::CreateRotationY(y) * Matrix::CreateRotationZ(z); + Vector3 result = direction.TransformNormal(direction, m); + result.Normalize(); + return result; +} + // FIXME: game code still expects << 2 >> W2V_SHIFT so we multiply by 16384.0f int phd_sin(short a) { diff --git a/TR5Main/Game/trmath.h b/TR5Main/Game/trmath.h index 69436b035..0bd2da3bd 100644 --- a/TR5Main/Game/trmath.h +++ b/TR5Main/Game/trmath.h @@ -45,6 +45,8 @@ int phd_cos(short a); const float frand(); const float frandMinMax(float min, float max); const float lerp(float v0, float v1, float t); +const Vector3 getRandomVector(); +const Vector3 getRandomVectorInCone(const Vector3& direction,const float angleDegrees); int mGetAngle(int x1, int y1, int x2, int y2); int phd_atan(int dz, int dx); void phd_GetVectorAngles(int x, int y, int z, short* angles);