mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-07-31 13:40:12 +02:00
Use vector math in cyclone.
This commit is contained in:
@@ -16,19 +16,23 @@ int Tool_Cycl::Perform(Simulation * sim, Particle * cpart, int x, int y, int bru
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Air velocity calculation.
|
Air velocity calculation.
|
||||||
Air velocity X = cosine of cell angle
|
(x, y) -- turn 90 deg -> (-y, x)
|
||||||
Angle of cell is calculated via cells X/Y relation to the brush center and arctangent
|
|
||||||
Angle has 1.57 radians added to it (90 degrees) in order to make the velocity be at 90 degrees to the centerpoint.
|
|
||||||
Ditto for Y, except Y uses sine
|
|
||||||
*/
|
*/
|
||||||
// only trigger once per cell (less laggy)
|
// only trigger once per cell (less laggy)
|
||||||
if ((x%CELL) == 0 && (y%CELL) == 0)
|
if ((x%CELL) == 0 && (y%CELL) == 0)
|
||||||
{
|
{
|
||||||
|
if(brushX == x && brushY == y)
|
||||||
|
return 1;
|
||||||
|
|
||||||
float *vx = &sim->air->vx[y / CELL][x / CELL];
|
float *vx = &sim->air->vx[y / CELL][x / CELL];
|
||||||
float *vy = &sim->air->vy[y / CELL][x / CELL];
|
float *vy = &sim->air->vy[y / CELL][x / CELL];
|
||||||
|
|
||||||
*vx -= (strength / 16) * (tpt::cos(1.57f + (tpt::atan2(brushY - y, brushX - x))));
|
float dvx = brushX - x;
|
||||||
*vy -= (strength / 16) * (tpt::sin(1.57f + (tpt::atan2(brushY - y, brushX - x))));
|
float dvy = brushY - y;
|
||||||
|
float invsqr = 1/sqrtf(dvx*dvx + dvy*dvy);
|
||||||
|
|
||||||
|
*vx -= (strength / 16) * (-dvy)*invsqr;
|
||||||
|
*vy -= (strength / 16) * dvx*invsqr;
|
||||||
|
|
||||||
// Clamp velocities
|
// Clamp velocities
|
||||||
if (*vx > 256.0f)
|
if (*vx > 256.0f)
|
||||||
|
Reference in New Issue
Block a user