Skip to content

Commit 95ef947

Browse files
committed
more accurate impulse estimation
1 parent b6368c7 commit 95ef947

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Source/Entities/AEmitter.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,23 @@ void AEmitter::EnableEmission(bool enable) {
259259
float AEmitter::EstimateImpulse(bool burst) {
260260
// Calculate the impulse generated by the emissions, once and store the result
261261
if ((!burst && m_AvgImpulse < 0) || (burst && m_AvgBurstImpulse < 0)) {
262-
float impulse = 0;
262+
float impulse = 0.0F;
263263
float velMin, velMax, velRange, spread;
264264

265265
// Go through all emissions and emit them according to their respective rates
266266
for (auto eItr = m_EmissionList.begin(); eItr != m_EmissionList.end(); ++eItr) {
267267
// Only check emissions that push the emitter
268268
if ((*eItr).PushesEmitter()) {
269-
double emissions = (*eItr).GetRate() * g_TimerMan.GetDeltaTimeSecs() / 60.0f;
269+
float emissions = ((*eItr).GetRate() / 60.0f) * g_TimerMan.GetDeltaTimeSecs();
270+
float scale = 1.0F;
270271
if (burst) {
271272
emissions *= (*eItr).GetBurstSize();
273+
scale = m_BurstScale;
272274
}
273275

274-
velMin = std::min((*eItr).GetMinVelocity(), (*eItr).GetMaxVelocity());
275-
velMax = std::max((*eItr).GetMinVelocity(), (*eItr).GetMaxVelocity());
276-
velRange = (velMax - velMin) * 0.5;
277-
spread = std::max(static_cast<float>(c_PI) - (*eItr).GetSpread(), .0f) / c_PI; // A large spread will cause the forces to cancel eachother out
276+
velMin = (*eItr).GetMinVelocity() * scale;
277+
velRange = ((*eItr).GetMaxVelocity() - (*eItr).GetMinVelocity()) * 0.5F * scale;
278+
spread = (std::max(static_cast<float>(c_PI) - (*eItr).GetSpread(), 0.0F) / c_PI) * scale; // A large spread will cause the forces to cancel eachother out
278279

279280
// Add to accumulative recoil impulse generated, F = m * a.
280281
impulse += (velMin + velRange) * spread * (*eItr).m_pEmission->GetMass() * emissions;
@@ -446,7 +447,7 @@ void AEmitter::Update() {
446447

447448
for (int i = 0; i < emissionCount; ++i) {
448449
velMin = emission.GetMinVelocity() * scale;
449-
velRange = emission.GetMaxVelocity() - emission.GetMinVelocity() * scale;
450+
velRange = (emission.GetMaxVelocity() - emission.GetMinVelocity()) * scale;
450451
spread = emission.GetSpread() * scale;
451452
// Make a copy after the reference particle
452453
pParticle = dynamic_cast<MovableObject*>(emission.GetEmissionParticlePreset()->Clone());

Source/Entities/PEmitter.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,26 @@ void PEmitter::EnableEmission(bool enable) {
219219
float PEmitter::EstimateImpulse(bool burst) {
220220
// Calculate the impulse generated by the emissions, once and store the result
221221
if ((!burst && m_AvgImpulse < 0) || (burst && m_AvgBurstImpulse < 0)) {
222-
float impulse = 0;
222+
float impulse = 0.0F;
223223
float velMin, velMax, velRange, spread;
224224

225225
// Go through all emissions and emit them according to their respective rates
226226
for (auto eItr = m_EmissionList.begin(); eItr != m_EmissionList.end(); ++eItr) {
227227
// Only check emissions that push the emitter
228-
if (eItr->PushesEmitter()) {
229-
double emissions = eItr->GetRate() * g_TimerMan.GetDeltaTimeSecs() / 60.0f;
230-
if (burst)
231-
emissions *= eItr->GetBurstSize();
228+
if ((*eItr).PushesEmitter()) {
229+
float emissions = ((*eItr).GetRate() / 60.0f) * g_TimerMan.GetDeltaTimeSecs();
230+
float scale = 1.0F;
231+
if (burst) {
232+
emissions *= (*eItr).GetBurstSize();
233+
scale = m_BurstScale;
234+
}
232235

233-
velMin = std::min(eItr->GetMinVelocity(), eItr->GetMaxVelocity());
234-
velMax = std::max(eItr->GetMinVelocity(), eItr->GetMaxVelocity());
235-
velRange = (velMax - velMin) * 0.5;
236-
spread = std::max(static_cast<float>(c_PI) - eItr->GetSpread(), .0f) / c_PI; // A large spread will cause the forces to cancel eachother out
236+
velMin = (*eItr).GetMinVelocity() * scale;
237+
velRange = ((*eItr).GetMaxVelocity() - (*eItr).GetMinVelocity()) * 0.5F * scale;
238+
spread = (std::max(static_cast<float>(c_PI) - (*eItr).GetSpread(), 0.0F) / c_PI) * scale; // A large spread will cause the forces to cancel eachother out
237239

238240
// Add to accumulative recoil impulse generated, F = m * a.
239-
impulse += (velMin + velRange) * spread * eItr->m_pEmission->GetMass() * emissions;
241+
impulse += (velMin + velRange) * spread * (*eItr).m_pEmission->GetMass() * emissions;
240242
}
241243
}
242244

0 commit comments

Comments
 (0)