| 217 | } |
| 218 | |
| 219 | void UpdateDebris() |
| 220 | { |
| 221 | auto updateDebris = [&](int start, int end) |
| 222 | { |
| 223 | for (int i = start; i < end; i++) |
| 224 | { |
| 225 | auto& deb = DebrisFragments[i]; |
| 226 | |
| 227 | if (!deb.active) |
| 228 | continue; |
| 229 | |
| 230 | deb.StoreInterpolationData(); |
| 231 | |
| 232 | deb.velocity *= deb.linearDrag; |
| 233 | deb.velocity += deb.gravity; |
| 234 | deb.velocity = XMVector3ClampLength(deb.velocity, 0, deb.terminalVelocity); |
| 235 | deb.rotation *= Quaternion::CreateFromYawPitchRoll(deb.angularVelocity.x, deb.angularVelocity.y, deb.angularVelocity.z); |
| 236 | deb.worldPosition += deb.velocity; |
| 237 | deb.angularVelocity *= deb.angularDrag; |
| 238 | |
| 239 | short roomNumber = deb.roomNumber; |
| 240 | auto* floor = GetFloor(deb.worldPosition.x, deb.worldPosition.y, deb.worldPosition.z, &roomNumber); |
| 241 | |
| 242 | if (deb.worldPosition.y < floor->GetSurfaceHeight(deb.worldPosition.x, deb.worldPosition.z, false)) |
| 243 | { |
| 244 | auto roomNumber = floor->GetNextRoomNumber(deb.worldPosition, false); |
| 245 | if (roomNumber.has_value()) |
| 246 | deb.roomNumber = *roomNumber; |
| 247 | } |
| 248 | |
| 249 | if (deb.worldPosition.y > floor->GetSurfaceHeight(deb.worldPosition.x, deb.worldPosition.z, true)) |
| 250 | { |
| 251 | auto roomNumber = floor->GetNextRoomNumber(deb.worldPosition, true); |
| 252 | if (roomNumber.has_value()) |
| 253 | { |
| 254 | deb.roomNumber = *roomNumber; |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | if (deb.numBounces > 3) |
| 259 | { |
| 260 | deb.active = false; |
| 261 | continue; |
| 262 | } |
| 263 | |
| 264 | deb.velocity.y *= -deb.restitution; |
| 265 | deb.velocity.x *= deb.friction; |
| 266 | deb.velocity.z *= deb.friction; |
| 267 | deb.numBounces++; |
| 268 | } |
| 269 | |
| 270 | deb.UpdateTransform(); |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | bool debrisActive = false; |
| 275 | |
| 276 | for (auto& deb : DebrisFragments) |
no test coverage detected