void setColoursByKinetic() { int i; particle_t *p; particleDetail_t *pd; float d; float kinMax = 0; float kinValue; float velocity; VectorNew(zero); VectorZero(zero); for (i = 0; i < state.particleCount; i++) { p = getParticleCurrentFrame(i); pd = getParticleDetail(i); distance(zero, p->vel, velocity); velocity = fabs(velocity); kinValue = velocity * velocity * pd->mass * 0.5; if (i == 0) { kinMax = kinValue; } else { if (kinValue > kinMax) kinMax = kinValue; } } for (i = 0; i < state.particleCount; i++) { p = getParticleFirstFrame(i); pd = getParticleDetail(i); distance(zero, p->vel, velocity); kinValue = velocity * velocity * pd->mass * 0.5; d = kinValue / kinMax; colourFromNormal(pd->col, (float)fabs((double)d)); pd->particleSprite = colourSprite(pd->col, pd->mass); } }
void setColoursByVel() { int i; particle_t *p; particleDetail_t *pd; float d; float velMax = 0; float velSpeed; VectorNew(zero); VectorZero(zero); // works out the highest velocity for (i = 0; i < state.particleCount; i++) { p = getParticleCurrentFrame(i); distance(zero, p->vel, velSpeed); velSpeed = fabs(velSpeed); if (i == 0) { velMax = velSpeed; } else { if (velSpeed > velMax) velMax = velSpeed; } } // applies velocity based on the highest for (i = 0; i < state.particleCount; i++) { p = getParticleFirstFrame(i); pd = getParticleDetail(i); distance(zero, p->vel, velSpeed); d = velSpeed / velMax; colourFromNormal(pd->col, (float)fabs((double)d)); pd->particleSprite = colourSprite(pd->col, pd->mass); } }
int luag_spawn(lua_State *L) { particle_t *p; particleDetail_t *pd; VectorNew(pos); VectorNew(vel); float mass; int id; VectorZero(pos); VectorZero(vel); mass = lua_tonumber(L, -1); id = -1; lua_pop(L, 1); luag_TableToVector(L, vel); lua_pop(L, 1); luag_TableToVector(L, pos); lua_pop(L, 1); id = lua_tonumber(L, -1); if (id < 0 || id >= state.particleCount) { conAdd(LERR, "Particle %i out of range", id); return 0; } p = getParticleFirstFrame(id); pd = getParticleDetail(id); VectorCopy(pos, p->pos); VectorCopy(vel, p->vel); pd->mass = mass; doVideoUpdateInSpawn(); return 0; }
int pickPositions() { int gals; VectorNew(galPos[100]); VectorNew(galVel[100]); VectorNew(shit); float galSize[100]; float galMassMin[100]; float galMassMax[100]; float spawnRange; int i; int g; particle_t *p; particleDetail_t *pd; float totalMass = 0; float angle; float angle2; float radius; gals = (rand() % (1 + spawnVars.maxGalCount-spawnVars.minGalCount)) + spawnVars.minGalCount; if (gals <= 0) { conAdd(LERR, "For some reason galaxies to spawn is 0 or less. Not possible!"); return 0; } if (gals >= 100) { conAdd(LERR, "Maximum galaxies to spawn is 100"); return 0; } spawnRange = frand(spawnVars.minSpawnRange, spawnVars.maxSpawnRange); conAdd(LNORM, "Spawning new simulation..."); conAdd(LLOW, "- %i particles...", state.particleCount); conAdd(LLOW, "- %i galaxies...", gals); for (g = 0; g < gals; g++) { galMassMin[g] = frand(spawnVars.minGalMass, spawnVars.maxGalMass); galMassMax[g] = frand(spawnVars.minGalMass, spawnVars.maxGalMass); galSize[g] = frand(spawnVars.minGalSize, spawnVars.maxGalSize); setRangePosition(galPos[g], spawnRange); setRangePosition(galVel[g], frand(0,1) * frand(0,1) * frand(spawnVars.minGalVel, spawnVars.maxGalVel)); } for (i = 0; i < state.particleCount; i++) { if (!(i % 100)) { view.recordParticlesDone = i; doVideoUpdateInSpawn(); } if (state.restartSpawning) { return 0; } p = getParticleFirstFrame(i); pd = getParticleDetail(i); g = rand() % gals; pd->mass = frand(galMassMin[g], galMassMax[g]); // if (g % 2 == 0) // pd->mass = -pd->mass; totalMass += pd->mass; // position VectorCopy(galPos[g], p->pos); setRangePosition((float *)&shit, galSize[g]); VectorAdd(p->pos, shit, p->pos); // galaxy structured position angle = frand(0, PI*2); radius = frand(0, galSize[g]); VectorZero(p->pos); p->pos[0] = cos(angle) * radius; p->pos[1] = sin(angle) * radius; p->pos[2] = frand(-radius/10, radius/10); VectorAdd(galPos[g], p->pos, p->pos); angle2 = angle + PI / 2; p->vel[0] = cos(angle2) * radius * 0.05f; p->vel[1] = sin(angle2) * radius * 0.05f; p->vel[2] = 0; VectorAdd(galVel[g], p->vel, p->vel); if (g & 2) { p->vel[0] = -p->vel[0]; p->vel[1] = -p->vel[1]; p->vel[2] = -p->vel[2]; } } conAdd(LLOW, "- %f total mass...", totalMass); conAdd(LLOW, "- %f galaxy mass...", totalMass / gals); conAdd(LLOW, "- %f particle mass...", totalMass / state.particleCount); return 0; }