Skip to content

Commit

Permalink
Good progress. Ditch the damping and whatever was offsetting the dire…
Browse files Browse the repository at this point in the history
…ction, but this is on the Unity side.
  • Loading branch information
eggrobin committed Mar 12, 2014
1 parent 0206b16 commit 3821349
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ModelMultiParticlePersistFX.cs
Expand Up @@ -249,9 +249,14 @@ public void FixedUpdate()
double volumeChange = currentVolume - estimatedInitialVolume;
double density = (estimatedInitialVolume * initialDensity + volumeChange) / currentVolume;
double atmosphericDensity = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(pPos));
double dragCoefficient = .5; // Computed by Pifomètre (R). Make it a setting?
double mass = density * currentVolume;
// Weight and buoyancy.
Vector3d acceleration = (1 - (atmosphericDensity / density)) * FlightGlobals.getGeeForceAtPosition(pPos);
// Drag. TODO(robin): simplify.
acceleration += - 0.5 * atmosphericDensity * pVel * pVel.magnitude * dragCoefficient * Math.PI * r * r / mass;
// Euler is good enough for graphics.
// pVel = pVel + acceleration * TimeWarp.fixedDeltaTime;
pVel = pVel + acceleration * TimeWarp.fixedDeltaTime;
particles[j].velocity = (peristantEmitters[i].pe.useWorldSpace ? (Vector3)pVel : peristantEmitters[i].pe.transform.InverseTransformDirection(pVel));
}

Expand All @@ -264,14 +269,14 @@ public void FixedUpdate()
if (hit.collider.name != "Launch Pad Grate")
{
Vector3 hVel = Vector3.Exclude(hit.normal, pVel);
Vector3 reflectedNormalVelocity = collideRatio * (hVel - pVel);
Vector3 reflectedNormalVelocity = hVel - pVel;
float residualFlow = reflectedNormalVelocity.magnitude * (1 - collideRatio);
// An attempt at a better velocity change; the blob collides with some
// restitution coefficient collideRatio << 1 and we add a random horizonal term
// for flow conservation---randomness handwaved in through fluid dynamics:
float randomAngle = UnityEngine.Random.value * 360.0f;
Vector3d flowConservationTerm = Quaternion.AngleAxis(randomAngle, hit.normal) * hVel.normalized * residualFlow;
pVel = hVel + reflectedNormalVelocity + flowConservationTerm;
pVel = hVel + collideRatio * reflectedNormalVelocity + flowConservationTerm;
particles[j].velocity = (peristantEmitters[i].pe.useWorldSpace ? pVel : peristantEmitters[i].pe.transform.InverseTransformDirection(pVel));
}
else
Expand Down

0 comments on commit 3821349

Please sign in to comment.