예제 #1
0
파일: color.c 프로젝트: FrMo/gravit
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);

    }

}
예제 #2
0
파일: color.c 프로젝트: FrMo/gravit
void setColoursByMass() {

    int i;
    particle_t *p;
    particleDetail_t *pd;
    float d;

    for (i = 0; i < state.particleCount; i++) {

        p = getParticleCurrentFrame(i);
        pd = getParticleDetail(i);

        if (i == 0) {

            state.massRange[0] = pd->mass;
            state.massRange[1] = pd->mass;

        } else {

            if (pd->mass < state.massRange[0])
                state.massRange[0] = pd->mass;

            if (pd->mass > state.massRange[1])
                state.massRange[1] = pd->mass;

        }

    }

    for (i = 0; i < state.particleCount; i++) {

        p = getParticleCurrentFrame(i);
        pd = getParticleDetail(i);

        d = pd->mass / state.massRange[1];
        colourFromNormal(pd->col, (float)fabs(d));

        if (d < 0) {

            pd->col[0] = 1 - pd->col[0];
            pd->col[1] = 1 - pd->col[1];
            pd->col[2] = 1 - pd->col[2];

        }
        pd->particleSprite = colourSprite(pd->col, pd->mass);
    }

}
예제 #3
0
파일: color.c 프로젝트: FrMo/gravit
void setColoursByAcceleration() {

    int i;
    particle_t *p, *plast;
    particleDetail_t *pd;
    float d;
    float accMax = 0;
    float accCurrent;
    float velSpeed1;
    float velSpeed2;

    VectorNew(zero);
    VectorZero(zero);

    if (state.currentFrame == 0)
        return;

    for (i = 0; i < state.particleCount; i++) {

        p = getParticleCurrentFrame(i);
        plast = state.particleHistory + state.particleCount * (state.currentFrame-1) + i;
        distance(zero, p->vel, velSpeed1);
        distance(p->vel, plast->vel, velSpeed2);
        accCurrent = abs(velSpeed2 - velSpeed1);

        if (i == 0) {

            accMax = accCurrent;

        } else {

            if (accCurrent > accMax)
                accMax = accCurrent;

        }

    }

    for (i = 0; i < state.particleCount; i++) {

        p = getParticleCurrentFrame(i);
        plast = state.particleHistory + state.particleCount * (state.currentFrame-1) + i;
        distance(zero, p->vel, velSpeed1);
        distance(p->vel, plast->vel, velSpeed2);
        accCurrent = velSpeed2 - velSpeed1;
        pd = getParticleDetail(i);

        d = accCurrent / accMax;
        colourFromNormal(pd->col, (float)fabs((double)d));
        pd->particleSprite = colourSprite(pd->col, pd->mass);

    }

}
예제 #4
0
파일: color.c 프로젝트: FrMo/gravit
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);

    }

}
예제 #5
0
파일: lua.c 프로젝트: dsturnbull/gravit
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;

}
예제 #6
0
파일: spawn.c 프로젝트: Kodomo/Gravit-Fork
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;

}