| 253 | } |
| 254 | |
| 255 | void UpdateFireflySwarm() |
| 256 | { |
| 257 | constexpr auto FLEE_VEL = 1.5f; |
| 258 | constexpr auto ALPHA_PAUSE_DURATION = 100.0f; |
| 259 | |
| 260 | static const auto SPHERE = BoundingSphere(Vector3::Zero, BLOCK(1 / 8.0f)); |
| 261 | |
| 262 | if (FireflySwarm.empty()) |
| 263 | return; |
| 264 | |
| 265 | const auto& playerItem = *LaraItem; |
| 266 | static float frameCounter = 0.0f; |
| 267 | |
| 268 | // Increment the counter variable in each frame. |
| 269 | frameCounter += 1.0f; |
| 270 | |
| 271 | for (auto& firefly : FireflySwarm) |
| 272 | { |
| 273 | if (firefly.Life <= 0.0f || !firefly.on) |
| 274 | continue; |
| 275 | |
| 276 | auto targetItem = firefly.TargetItemPtr; |
| 277 | |
| 278 | if (targetItem->ItemFlags[FirefliesItemFlags::RemoveFliesEffect]) |
| 279 | { |
| 280 | firefly.r = 0; |
| 281 | firefly.g = 0; |
| 282 | firefly.b = 0; |
| 283 | continue; |
| 284 | } |
| 285 | |
| 286 | firefly.StoreInterpolationData(); |
| 287 | |
| 288 | firefly.PositionTarget = Random::GeneratePointInSphere(SPHERE); |
| 289 | |
| 290 | int multiplierX = CLICK(targetItem->ItemFlags[FirefliesItemFlags::TriggerFlags] * 2); |
| 291 | int multiplierY = CLICK(targetItem->ItemFlags[FirefliesItemFlags::TriggerFlags] * 4); |
| 292 | int multiplierZ = CLICK(targetItem->ItemFlags[FirefliesItemFlags::TriggerFlags] * 2); |
| 293 | |
| 294 | auto spheroidAxis = Vector3(multiplierX, multiplierY, multiplierZ); |
| 295 | auto itemPos = Vector3i(targetItem->Pose.Position.x, targetItem->Pose.Position.y - FIREFLY_RISE_UP_FACTOR, targetItem->Pose.Position.z); |
| 296 | |
| 297 | // Calculate desired position based on target object and random offsets. |
| 298 | auto desiredPos = itemPos + Random::GeneratePointInSpheroid(firefly.PositionTarget, EulerAngles::Identity, spheroidAxis); |
| 299 | auto dir = desiredPos - firefly.Position; |
| 300 | |
| 301 | auto dirs = dir.ToVector3(); |
| 302 | dirs.Normalize(); |
| 303 | auto dirNorm = dirs; |
| 304 | |
| 305 | // Define cohesion factor to keep fireflies close together. |
| 306 | float distToTarget = dirs.Length(); |
| 307 | |
| 308 | float targetVel = (distToTarget * FIREFLY_COHESION_FACTOR) + Random::GenerateFloat(3.0f, 5.0f); |
| 309 | firefly.Velocity = std::min(targetVel, targetItem->Animation.Velocity.z - 21.0f); |
| 310 | |
| 311 | // If firefly is too far from target, increase velocity to catch up. |
| 312 | if (distToTarget > FIREFLY_TARGET_DISTANCE_MAX) |
no test coverage detected