void keyboard(unsigned char c, int iXPos, int iYPos)
{
	switch(c)
	{
	case 'w':
		camInputTravel(g_Input, tri_pos);
		break;
	case 's':
		camInputTravel(g_Input, tri_neg);
		break;
	case 'a':
		pushTail(seedPlanetValues(createNewElement()));
		break;
	case 'd': {
		jrPlanet* pDel = popTail();

		if (pDel == g_pFollowing) {
			resetFollow();
		}

		destroy(pDel);
		break; }
	case 'q':
		g_bMaintainPlanets = !g_bMaintainPlanets;
		break;

	}
}
void reset() {
	resetFollow();
	while (g_pHead != 0) {
		destroy(popTail());
	}
	pushTail(initSun(createNewElement())); //init sun
}
예제 #3
0
// {{{ copyList
List * copyList(List * l) {
  List * res = allocList();
  if (nb(l) !=0) {
    Item * it = begin(l);
    while (it != NULL) {
      pushTail(res, num(it), val(it));
      it = next(it);
    }
  }
  return res;    
}
void myInit()
{
	initMaths();
	camInit(g_Camera);
	camInputInit(g_Input);
	camInputExplore(g_Input, true);

	glClearColor(0.01f, 0.01f, 0.01f, 0.0f); //sets the colour values to use when clearing the colours, essentially sets the canvas colour
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHT0); //sets the colour of the light (0 == white)
	glEnable(GL_LIGHTING); //allows GL to make lighting calculations
	glEnableClientState(GL_VERTEX_ARRAY);

	pushTail(initSun(createNewElement())); //init sun

	loadTextures();
}
예제 #5
0
// {{{ insertNum
void insertNum(List * l, int num, int val) {
  if (val == 0) popNum(l,num);
  else if (nb(l) == 0 || num(begin(l)) > num) pushHead(l, num, val);
  else if (num(end(l)) < num) pushTail(l, num, val);
  else {
    Item * it = begin(l);
    while (num(it) < num) it = next(it);
    if (num(it) == num) val(it) = val;
    else {
      Item * i = (Item*) malloc(SIZE_ITEM);
      num(i) = num; val(i) = val;
      prev(i) = prev(it); next(i) = it;
      next(prev(it)) = i; prev(it) = i;
      nb(l)++;
    }
  }
}
void rightClickMenu(int iCommand) {


	switch (iCommand) { //change to constants

	case PAUSE:
		g_bPlaying = false;
		break;
	case PLAY:
		g_bPlaying = true;
		break;
	case RESET:
		reset();
		break;
	case LONG_TRAILS: {
		resetTrails();
		g_iHistoryVariableLength = iHistoryMax;
		break; }
	case SHORT_TRAILS: {
		resetTrails();
		g_iHistoryVariableLength = g_iHistoryVariableLength / 3;

		if (g_iHistoryVariableLength < 300) {
			g_iHistoryVariableLength = 300; //with alpha, any shorter and they are basically off
		}

		break; }
	case TRAILS_OFF:
		g_bTrailsOn = false;
		break;
	case TRAILS_ON:
		g_bTrailsOn = true;
		break;
	case INCREASE_FPS:
		g_fFPSMultiplier += 0.2f;
		break;
	case DECREASE_FPS: {
		g_fFPSMultiplier -= 0.2f;

		if (g_fFPSMultiplier < 0.2f) { //stops it from having 0 fps, which currently would cause a crash
			g_fFPSMultiplier = 0.2f;
		}
		break; }
	case SAVE:
		saveFile();
		break;
	case LOAD:
		loadFile();
		break;
	case INCREASE_POPCAP:
		g_iMaintainPlanetNumber = g_iMaintainPlanetNumber * 2;
		break;
	case DECREASE_POPCAP:
		g_iMaintainPlanetNumber = g_iMaintainPlanetNumber / 2;
		break;
	case TEXTURES_ON:
		g_bTexturesOn = true;
		break;
	case TEXTURES_OFF:
		g_bTexturesOn = false;
		break;
	case PARTICLES_ON:
		g_bParticlesOn = true;
		break;
	case PARTICLES_OFF:
		g_bParticlesOn = false;
		break;
	case INCREASE_VELOCITY: 
		g_fVelocityMultiplier *= 2.0f;
		break;
	case DECREASE_VELOCITY:
		g_fVelocityMultiplier /= 2.0f;
		break; 
	case REVERSE_VELOCITY:
		g_fVelocityMultiplier *= -1.0f;
		break;
	case INCREASE_SIZE: {
		if (g_pFollowing) {
			g_pFollowing->fMass *= 2.0f;
			g_pFollowing->fSize *= 2.0f;
			g_pFollowing->iSlices += 5;
			g_pFollowing->iSegments += 5;
		}
		break; }
	case DECREASE_SIZE: {
		if (g_pFollowing) {
			g_pFollowing->fMass /= 2.0f;
			g_pFollowing->fSize /= 2.0f;
			g_pFollowing->iSlices = 20;
			g_pFollowing->iSegments = 20;
		}
		break; }
	case REMOVE_VELOCITY: {
		if (g_pFollowing) {
			vecInitDVec(g_pFollowing->afVelocity);
			vecInitDVec(g_pFollowing->afAcceleration);
		}
		break; }
	case CHANGE_COLOUR: {
		if (g_pFollowing) {
			g_pFollowing->afDiffuse[0] = randFloat(0.3f, 0.8f);
			g_pFollowing->afDiffuse[1] = randFloat(0.3f, 0.8f);
			g_pFollowing->afDiffuse[2] = randFloat(0.3f, 0.8f);
			g_pFollowing->afAmbient[0] = g_pFollowing->afDiffuse[0] / 2.0f;
			g_pFollowing->afAmbient[1] = g_pFollowing->afDiffuse[1] / 2.0f;
			g_pFollowing->afAmbient[2] = g_pFollowing->afDiffuse[2] / 2.0f;
		}
		break; }
	case STOP_FOLLOWING: 
		resetFollow();
		break;
	case SPHERE:
		pushTail(seedPlanetValues(createNewElement()));
		break;
	case CUBE:
		pushTail(seedCubeValues(createNewElement()));
		break;
	case CONE:
		pushTail(seedConeValues(createNewElement()));
		break;
	case TEAPOT:
		pushTail(seedTeapotValues(createNewElement()));
		break;
	case VERY_LARGE_SPHERE: {
		jrPlanet* pPlanet = seedPlanetValues(createNewElement()); 
		pPlanet->fSize = randFloat(50.0f, 100.0f);
		pPlanet->fMass = pPlanet->fSize * 20;
		pPlanet->iSegments = 30;
		pPlanet->iSlices = 30;
		pushTail(pPlanet);
		break; }
	case COMET: {
		jrPlanet* pPlanet = seedPlanetValues(createNewElement()); 
		pPlanet->fSize = pPlanet->fSize / 2;
		pPlanet->fMass = pPlanet->fSize * 20;
		pPlanet->m_bParticles = true;
		pushTail(pPlanet);
		break; }
	case SUN: {
		jrPlanet* pSun = initSun(createNewElement());
		pSun->afPosition[0] = randFloat(-3000.0f, 3000.0f);
		pSun->afPosition[1] = randFloat(-3000.0f, 3000.0f);
		pSun->afPosition[2] = randFloat(-3000.0f, 3000.0f);
		pushTail(pSun);
		break; }
	case EARTH: {
		jrPlanet* pPlanet = seedPlanetValues(createNewElement());
		pPlanet->fMass *= 1.5f;
		pPlanet->fSize *= 1.5f;

		pPlanet->iSegments = 20;
		pPlanet->iSlices = 20;

		pPlanet->afDiffuse[0] = 0.2f;
		pPlanet->afDiffuse[1] = 0.4f;
		pPlanet->afDiffuse[2] = 0.8f;

		pPlanet->afAmbient[0] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[1] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[2] = pPlanet->afDiffuse[0] / 2.0f;

		pPlanet->iType = EARTH;
		pushTail(pPlanet);
		break; }
	case MOON: {
		jrPlanet* pPlanet = seedPlanetValues(createNewElement());
		pPlanet->fMass *= 1.5f;
		pPlanet->fSize *= 1.5f;

		pPlanet->iSegments = 20;
		pPlanet->iSlices = 20;

		pPlanet->afDiffuse[0] = 0.8f;
		pPlanet->afDiffuse[1] = 0.8f;
		pPlanet->afDiffuse[2] = 0.8f;

		pPlanet->afAmbient[0] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[1] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[2] = pPlanet->afDiffuse[0] / 2.0f;

		pPlanet->iType = MOON;
		pushTail(pPlanet);
		break; }
	case MARS: {
		jrPlanet* pPlanet = seedPlanetValues(createNewElement());
		pPlanet->fMass *= 1.5f;
		pPlanet->fSize *= 1.5f;

		pPlanet->iSegments = 20;
		pPlanet->iSlices = 20;

		pPlanet->afDiffuse[0] = 0.8f;
		pPlanet->afDiffuse[1] = 0.3f;
		pPlanet->afDiffuse[2] = 0.3f;

		pPlanet->afAmbient[0] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[1] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[2] = pPlanet->afDiffuse[0] / 2.0f;

		pPlanet->iType = MARS;
		pushTail(pPlanet);
		break; }
	case DEATH_STAR: {
		jrPlanet* pPlanet = seedPlanetValues(createNewElement());
		pPlanet->fMass *= 1.5f;
		pPlanet->fSize *= 1.5f;

		pPlanet->iSegments = 20;
		pPlanet->iSlices = 20;

		pPlanet->afDiffuse[0] = 0.2f;
		pPlanet->afDiffuse[1] = 0.2f;
		pPlanet->afDiffuse[2] = 0.2f;

		pPlanet->afAmbient[0] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[1] = pPlanet->afDiffuse[0] / 2.0f;
		pPlanet->afAmbient[2] = pPlanet->afDiffuse[0] / 2.0f;

		pPlanet->iType = DEATH_STAR;
		pushTail(pPlanet);
		break; }
	}
}
void loadFile() {

	g_bMaintainPlanets = false; //create a blank canvas
	reset();
	popTail();

	char sFileName[512];
	strcpy(sFileName, "savefile.sav\0");
	printf("Loading %s\n", sFileName);

	FILE *pFile = fopen(sFileName, "r");
	if (pFile) {
		while(!feof(pFile)) {
			char sFileContents[32768];
			fscanf(pFile, " %s ", sFileContents);

			char *cToken = strtok(sFileContents, ",");

			while(cToken != '\0') {

				jrPlanet* pPlanet = createNewElement();

				pPlanet->fSize = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->fMass = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->fRotationAngle = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->afPosition[0] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afPosition[1] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afPosition[2] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afPosition[3] = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->iHistoryCount = 0;

				pPlanet->afAmbient[0] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afAmbient[1] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afAmbient[2] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afAmbient[3] = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->afDiffuse[0] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afDiffuse[1] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afDiffuse[2] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afDiffuse[3] = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->afVelocity[0] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afVelocity[1] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afVelocity[2] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afVelocity[3] = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->afAcceleration[0] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afAcceleration[1] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afAcceleration[2] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afAcceleration[3] = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->afForce[0] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afForce[1] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afForce[2] = atof(cToken);
				cToken = strtok(0, ",");
				pPlanet->afForce[3] = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->iSegments = atoi(cToken);
				cToken = strtok(0, ",");

				pPlanet->iSlices = atoi(cToken);
				cToken = strtok(0, ",");

				for (int i = 0; i < iHistoryMax; i++) {
					pPlanet->afPositionHistory[i] = pPlanet->afPosition[0];
					i++;
					pPlanet->afPositionHistory[i] = pPlanet->afPosition[1];
					i++;
					pPlanet->afPositionHistory[i] = pPlanet->afPosition[2];
				}

				pPlanet->iType = atof(cToken);
				cToken = strtok(0, ",");

				pPlanet->m_bParticles = !!atoi(cToken);
				cToken = strtok(0, ",");

				pPlanet->m_bFixed = !!atoi(cToken);
				cToken = strtok(0, ",");

				pushTail(pPlanet);
			}
		}

		fclose(pFile);
	}

}
void maintainPlanetNumber() {
	if (getNumberOfPlanets() < g_iMaintainPlanetNumber) {
		pushTail(seedPlanetValues(createNewElement()));
	}
}