TPT: Gravity modes and Newtonian gravity for fireworks 31ce22f122

This commit is contained in:
Simon Robertshaw 2012-07-25 17:44:29 +01:00
parent 811c2cb26b
commit e36bc8e4ae
5 changed files with 76 additions and 22 deletions

View File

@ -1665,10 +1665,10 @@ char * GameSave::serialiseOPS(int & dataLength)
{
fieldDesc |= 1 << 10;
partsData[partsDataLen++] = particles[i].tmp2;
if(partsptr[i].tmp2 > 255)
if(particles[i].tmp2 > 255)
{
fieldDesc |= 1 << 11;
partsData[partsDataLen++] = partsptr[i].tmp2 >> 8;
partsData[partsDataLen++] = particles[i].tmp2 >> 8;
}
}

View File

@ -2875,6 +2875,28 @@ int Simulation::create_part(int p, int x, int y, int tv)//the function for creat
return i;
}
void Simulation::GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY)
{
pGravX = newtonGrav*gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
pGravY = newtonGrav*gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
switch (gravityMode)
{
default:
case 0: //normal, vertical gravity
pGravY += particleGrav;
break;
case 1: //no gravity
break;
case 2: //radial gravity
if (x-XCNTR != 0 || y-YCNTR != 0)
{
float pGravMult = particleGrav/sqrtf((x-XCNTR)*(x-XCNTR) + (y-YCNTR)*(y-YCNTR));
pGravX -= pGravMult * (float)(x - XCNTR);
pGravY -= pGravMult * (float)(y - YCNTR);
}
}
}
void Simulation::create_gain_photon(int pp)//photons from PHOT going through GLOW
{
float xx, yy;

View File

@ -179,6 +179,8 @@ public:
void ApplyDecorationLine(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode, Brush * cBrush = NULL);
void ApplyDecorationBox(int x1, int y1, int x2, int y2, int colR, int colG, int colB, int colA, int mode);
void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float & pGravX, float & pGravY);
void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate);
inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[]);
inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[]);

View File

@ -13,11 +13,11 @@ Element_FIRW::Element_FIRW()
MenuSection = SC_EXPLOSIVE;
Enabled = 1;
Advection = 0.7f;
Advection = 0.4f;
AirDrag = 0.02f * CFDS;
AirLoss = 0.96f;
Loss = 0.80f;
Collision = -0.99f;
Loss = 0.95f;
Collision = -0.5f;
Gravity = 0.1f;
Diffusion = 0.00f;
HotAir = 0.000f * CFDS;
@ -65,8 +65,19 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS)
rt = parts[r>>8].type;
if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR)
{
float gx, gy, multiplier;
sim->GetGravityField(x, y, sim->elements[PT_FIRW].Gravity, 1.0f, gx, gy);
if (gx*gx+gy*gy < 0.001f)
{
float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
gx += sinf(angle)*sim->elements[PT_FIRW].Gravity*0.5f;
gy += cosf(angle)*sim->elements[PT_FIRW].Gravity*0.5f;
}
parts[i].tmp = 1;
parts[i].life = rand()%40+60;
parts[i].life = rand()%10+20;
multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy);
parts[i].vx -= gx*multiplier;
parts[i].vy -= gy*multiplier;
}
}
}
@ -74,8 +85,7 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS)
if (parts[i].life<=0) {
parts[i].tmp=2;
} else {
// TODO: different gravity modes + Newtonian gravity
parts[i].vy = -parts[i].life*0.04f - 0.1f;
parts[i].flags &= ~FLAG_STAGNANT;
}
}
else if (parts[i].tmp>=2)
@ -91,8 +101,8 @@ int Element_FIRW::update(UPDATE_FUNC_ARGS)
{
magnitude = ((rand()%60)+40)*0.05f;
angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
parts[np].vx = parts[i].vx + cosf(angle)*magnitude;
parts[np].vy = parts[i].vy + sinf(angle)*magnitude - 2.5f;
parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude;
parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude;
parts[np].ctype = col;
parts[np].tmp = 1;
parts[np].life = rand()%40+70;

View File

@ -50,22 +50,42 @@ Element_FWRK::Element_FWRK()
int Element_FWRK::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, np;
if ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&parts[i].life==0&&!pmap[y-1][x])||parts[i].ctype==PT_DUST)
if (parts[i].life==0 && ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&surround_space)||parts[i].ctype==PT_DUST))
{
np = sim->create_part(-1, x , y-1 , PT_FWRK);
if (np!=-1)
float gx, gy, multiplier, gmax;
int randTmp;
sim->GetGravityField(x, y, sim->elements[PT_FWRK].Gravity, 1.0f, gx, gy);
if (gx*gx+gy*gy < 0.001f)
{
parts[np].vy = rand()%8-22;
parts[np].vx = rand()%20-rand()%20;
parts[np].life=rand()%15+25;
parts[np].dcolour = parts[i].dcolour;
sim->kill_part(i);
return 1;
float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
gx += sinf(angle)*sim->elements[PT_FWRK].Gravity*0.5f;
gy += cosf(angle)*sim->elements[PT_FWRK].Gravity*0.5f;
}
gmax = fmaxf(fabsf(gx), fabsf(gy));
if (sim->eval_move(PT_FWRK, (int)(x-(gx/gmax)+0.5f), (int)(y-(gy/gmax)+0.5f), NULL))
{
multiplier = 15.0f/sqrtf(gx*gx+gy*gy);
//Some variation in speed parallel to gravity direction
randTmp = (rand()%200)-100;
gx += gx*randTmp*0.002f;
gy += gy*randTmp*0.002f;
//and a bit more variation in speed perpendicular to gravity direction
randTmp = (rand()%200)-100;
gx += -gy*randTmp*0.005f;
gy += gx*randTmp*0.005f;
parts[i].life=rand()%10+18;
parts[i].ctype=0;
parts[i].vx -= gx*multiplier;
parts[i].vy -= gy*multiplier;
parts[i].dcolour = parts[i].dcolour;
return 0;
}
}
if (parts[i].life>=45)
parts[i].life=0;
if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0))
if (parts[i].life<3&&parts[i].life>0)
{
int r = (rand()%245+11);
int g = (rand()%245+11);
@ -80,8 +100,8 @@ int Element_FWRK::update(UPDATE_FUNC_ARGS)
{
magnitude = ((rand()%60)+40)*0.05f;
angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
parts[np].vx = parts[i].vx + cosf(angle)*magnitude;
parts[np].vy = parts[i].vy + sinf(angle)*magnitude - 2.5f;
parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude;
parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude;
parts[np].ctype = col;
parts[np].tmp = 1;
parts[np].life = rand()%40+70;