mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-25 09:11:09 +02:00
Reduce gravity effects on ambient heat.
This commit is contained in:
@@ -153,18 +153,40 @@ void Air::update_airh(void)
|
|||||||
// We use the Boussinesq approximation, i.e. we assume density to be nonconstant only
|
// We use the Boussinesq approximation, i.e. we assume density to be nonconstant only
|
||||||
// near the gravity term of the fluid equation, and we suppose that it depends linearly on the
|
// near the gravity term of the fluid equation, and we suppose that it depends linearly on the
|
||||||
// difference between the current temperature (hv[y][x]) and some "stationary" temperature (ambientAirTemp).
|
// difference between the current temperature (hv[y][x]) and some "stationary" temperature (ambientAirTemp).
|
||||||
|
float dvx, dvy;
|
||||||
|
dvx = vx[y][x];
|
||||||
|
dvy = vy[y][x];
|
||||||
|
|
||||||
if (x>=2 && x<XCELLS-2 && y>=2 && y<YCELLS-2)
|
if (x>=2 && x<XCELLS-2 && y>=2 && y<YCELLS-2)
|
||||||
{
|
{
|
||||||
float convGravX, convGravY;
|
float convGravX, convGravY;
|
||||||
sim.GetGravityField(x*CELL, y*CELL, -1.0f, -1.0f, convGravX, convGravY);
|
sim.GetGravityField(x*CELL, y*CELL, -1.0f, -1.0f, convGravX, convGravY);
|
||||||
|
|
||||||
|
// Cap the gravity field
|
||||||
|
float gravMagn = std::sqrt(convGravX*convGravX + convGravY*convGravY);
|
||||||
|
if (gravMagn > 10.0f)
|
||||||
|
{
|
||||||
|
convGravX /= 0.1f*gravMagn;
|
||||||
|
convGravY /= 0.1f*gravMagn;
|
||||||
|
}
|
||||||
|
|
||||||
auto weight = (hv[y][x] - ambientAirTemp) / 10000.0f;
|
auto weight = (hv[y][x] - ambientAirTemp) / 10000.0f;
|
||||||
|
|
||||||
// Our approximation works best when the temperature difference is small, so we cap it from above.
|
// Our approximation works best when the temperature difference is small, so we cap it from above.
|
||||||
if (weight > 0.01f) weight = 0.01f;
|
if (weight > 0.01f) weight = 0.01f;
|
||||||
|
|
||||||
vx[y][x] += weight * convGravX;
|
dvx += weight * convGravX;
|
||||||
vy[y][x] += weight * convGravY;
|
dvy += weight * convGravY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Velocity cap
|
||||||
|
if (dvx > MAX_PRESSURE) dvx = MAX_PRESSURE;
|
||||||
|
if (dvx < MIN_PRESSURE) dvx = MIN_PRESSURE;
|
||||||
|
if (dvy > MAX_PRESSURE) dvy = MAX_PRESSURE;
|
||||||
|
if (dvy < MIN_PRESSURE) dvy = MIN_PRESSURE;
|
||||||
|
|
||||||
|
vx[y][x] = dvx;
|
||||||
|
vy[y][x] = dvy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(hv, ohv, sizeof(hv));
|
memcpy(hv, ohv, sizeof(hv));
|
||||||
|
Reference in New Issue
Block a user