Esempio n. 1
0
void starBurst::restart(float* position){
	int i;

	for(i=0; i<SB_NUM_STARS; i++){  // don't restart if any star is still active
		if(stars_active[i])
			return;
	}
	if(size < 3.0f)  // or if flare hasn't faded out completely
		return;

	float color[3];
	color[0] = rsRandf(1.0f);
	color[1] = rsRandf(1.0f);
	color[2] = rsRandf(1.0f);
	color[rsRandi(3)] = 1.0f;
	for(i=0; i<SB_NUM_STARS; i++){
		stars_active[i] = 1;
		stars[i]->pos[0] = position[0];
		stars[i]->pos[1] = position[1];
		stars[i]->pos[2] = position[2];
		stars[i]->color[0] = color[0];
		stars[i]->color[1] = color[1];
		stars[i]->color[2] = color[2];
	}

	size = 0.0f;
	pos[0] = position[0];
	pos[1] = position[1];
	pos[2] = position[2];
}
Esempio n. 2
0
bool CScreensaverCyclone::Start()
{
  int i, j;

  std::string fraqShader = kodi::GetAddonPath("resources/shaders/frag.glsl");
  std::string vertShader = kodi::GetAddonPath("resources/shaders/vert.glsl");
  if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink())
    return false;

  gCycloneSettings.Load();

  srand((unsigned)time(nullptr));

  // Window initialization
  glViewport(X(), Y(), Width(), Height());

  glEnable(GL_DEPTH_TEST);
  glFrontFace(GL_CCW);
  glEnable(GL_CULL_FACE);
  glClearColor(0.0, 0.0, 0.0, 1.0);

  m_modelMat = glm::mat4(1.0f);
  m_projMat = glm::perspective(glm::radians(80.0f), (GLfloat)Height() / (GLfloat)Width(), 50.0f, 3000.0f);
  if (!rsRandi(500))  // Easter egg view
  {
    m_projMat = glm::rotate(m_projMat, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
    m_projMat = glm::translate(m_projMat, glm::vec3(0.0f, -(WIDTH * 2), 0.0f));
  }
  else  // Normal view
    m_projMat = glm::translate(m_projMat, glm::vec3(0.0f, 0.0f, -(WIDTH * 2)));

  Sphere(float(gCycloneSettings.dSize) / 4.0f, 3, 2);
  m_lightingEnabled = 1;

  // Initialize cyclones and their particles
  for (i = 0; i < 13; i++)
    m_fact[i] = float(factorial(i));
  m_cyclones = new CCyclone*[gCycloneSettings.dCyclones];
  m_particles = new CParticle*[gCycloneSettings.dParticles * gCycloneSettings.dCyclones];
  for (i = 0; i < gCycloneSettings.dCyclones; i++)
  {
    m_cyclones[i] = new CCyclone;
    for (j=i*gCycloneSettings.dParticles; j<((i+1)*gCycloneSettings.dParticles); j++)
      m_particles[j] = new CParticle(m_cyclones[i]);
  }

  glGenBuffers(1, &m_vertexVBO);
  glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO);

  m_lastTime = kodi::time::GetTimeSec<double>();
  m_startOK = true;
  return true;
}
Esempio n. 3
0
void SceneManager::Render()
{
 
   // super fast easter egg
   static int superFast = rsRandi(1000);
   if(!superFast) frameTime *= 5.0f;


   m_Camera.Setup();//设置照像机

   // 更新 billboard矩阵
   glPushMatrix();
   glLoadIdentity();
   glRotatef(m_Camera.heading, 0, 1, 0);
   glRotatef(m_Camera.pitch, 1, 0, 0);
   glGetFloatv(GL_MODELVIEW_MATRIX, billboardMat);
   glPopMatrix();

   // clear the screen
   glClear(GL_COLOR_BUFFER_BIT);

   //绘制世界
   theWorld.draw();

   m_Terrain.Render(&m_Camera);

   //绘制粒子
   glEnable(GL_BLEND);

   for(unsigned int i=0; i<m_ParticleSystem.last_particle; i++) m_ParticleSystem.particles[i].draw(billboardMat,&theWorld);

   //绘制光晕
   if(dFlare)
   {
	makeFlareList();
	for(int i=0; i<numFlares; ++i)
	m_Flare.flare(&m_Camera,lensFlares[i].x, lensFlares[i].y, lensFlares[i].r,lensFlares[i].g, lensFlares[i].b, lensFlares[i].a);
	numFlares = 0;
   }
	
   wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);

   //更新声音

   float listenerOri[6];
		listenerOri[0] = float(-m_Camera.modelMat[2]);
		listenerOri[1] = float(-m_Camera.modelMat[6]);
		listenerOri[2] = float(-m_Camera.modelMat[10]);
		listenerOri[3] = float(m_Camera.modelMat[1]);
		listenerOri[4] = float(m_Camera.modelMat[5]);
		listenerOri[5] = float(m_Camera.modelMat[9]);
		soundengine->update(m_Camera.cameraPos.v, m_Camera.cameraVel.v, listenerOri, frameTime, false);
}
Esempio n. 4
0
void changeSettings ()
{
	do {
		equationBase = rsRandf (10) - 5;
	} while (equationBase <= 2 && equationBase >= -2); // we don't want between 1 and -1

	blurColor[0] = rsRandi (100) / 50.0;
	blurColor[1] = rsRandi (100) / 50.0;
	blurColor[2] = rsRandi (100) / 50.0;

	lineColor[0] = rsRandi (100) / 50.0;
	lineColor[1] = rsRandi (100) / 50.0;
	lineColor[2] = rsRandi (100) / 50.0;

	SUBLOOPS = rsRandi (3) + 2;
	graphTo = rsRandi (16) + 15;
	speed = (rsRandi (225) + 75) / 1000000.0;

	if (rsRandi (2) == 1) {
		speed *= -1;
	}
}
Esempio n. 5
0
// For building mountain sillohettes in sunset
void makeHeights (int first, int last, int *h)
{
	int middle;
	int diff;

	diff = last - first;
	if (diff <= 1)
		return;
	middle = (first + last) / 2;
	h[middle] = (h[first] + h[last]) / 2;
	h[middle] += rsRandi (diff / 2) - (diff / 4);
	if (h[middle] < 1)
		h[middle] = 1;

	makeHeights (first, middle, h);
	makeHeights (middle, last, h);
}
Esempio n. 6
0
void reconfigure ()
{
	int i, j;
	int newBorder, positive;

	/*
	 * End of old path = start of new path 
	 */
	for (i = 0; i < 6; i++)
		path[0][i] = path[segments][i];

	/*
	 * determine if direction of motion is positive or negative 
	 */
	/*
	 * update global position 
	 */
	if (lastBorder < 6) {
		if ((path[0][3] + path[0][4] + path[0][5]) > 0.0f) {
			positive = 1;
			globalxyz[lastBorder / 2]++;
		} else {
			positive = 0;
			globalxyz[lastBorder / 2]--;
		}
	} else {
		if (path[0][3] > 0.0f) {
			positive = 1;
			globalxyz[0]++;
		} else {
			positive = 0;
			globalxyz[0]--;
		}

		if (path[0][4] > 0.0f)
			globalxyz[1]++;
		else
			globalxyz[1]--;

		if (path[0][5] > 0.0f)
			globalxyz[2]++;
		else
			globalxyz[2]--;
	}

	if (!rsRandi (11 - dPathrand)) {	/* Change directions */
		if (!positive)
			lastBorder += 10;

		newBorder = transitions[lastBorder][rsRandi (6)];
		positive = 0;
		if (newBorder < 10)
			positive = 1;
		else
			newBorder -= 10;

		for (i = 0; i < 6; i++)	/* set the new border point */
			path[1][i] = bPnt[newBorder][i];

		if (!positive) {	/* flip everything if direction is
					 * negative */
			if (newBorder < 6)
				path[1][newBorder / 2] *= -1.0f;
			else
				for (i = 0; i < 3; i++)
					path[1][i] *= -1.0f;
			for (i = 3; i < 6; i++)
				path[1][i] *= -1.0f;
		}

		for (i = 0; i < 3; i++)	/* reposition the new border */
			path[1][i] += globalxyz[i];

		lastBorder = newBorder;
		segments = 1;
	} else {		/* Just keep going straight */
		newBorder = lastBorder;

		for (i = 0; i < 6; i++)
			path[1][i] = bPnt[newBorder][i];

		i = newBorder / 2;

		if (!positive) {
			if (newBorder < 6)
				path[1][i] *= -1.0f;
			else {
				path[1][0] *= -1.0f;
				path[1][1] *= -1.0f;
				path[1][2] *= -1.0f;
			}

			path[1][3] *= -1.0f;
			path[1][4] *= -1.0f;
			path[1][5] *= -1.0f;
		}

		for (j = 0; j < 3; j++) {
			path[1][j] += globalxyz[j];
			if ((newBorder < 6) && (j != 1))
				path[1][j] += rsRandf (0.15f) - 0.075f;
		}

		if (newBorder >= 6)
			path[1][0] += rsRandf (0.1f) - 0.05f;

		segments = 1;
	}
}
Esempio n. 7
0
/*
 * Build the lattice display lists 
 */
void makeLatticeObjects ()
{
	int i, d = 0;
	float thick = (float)dThick * 0.001f;

	list_base = glGenLists(NUMOBJECTS);

	for (i = 1; i <= NUMOBJECTS; i++) {
		glNewList (list_base + i, GL_COMPILE);

		if (dTexture >= 2)
			glBindTexture (GL_TEXTURE_2D, texture_id[0]);

		if (d < dDensity) {
			glPushMatrix ();

			setMaterialAttribs();

			glTranslatef (-0.25f, -0.25f, -0.25f);

			if (rsRandi (2))
				glRotatef (180.0f, 1, 0, 0);

			makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);

			glPopMatrix ();
		}

		d = (d + 37) % 100;

		if (d < dDensity) {
			glPushMatrix ();

			setMaterialAttribs();

			glTranslatef (0.25f, -0.25f, -0.25f);

			if (rsRandi (2))
				glRotatef (90.0f, 1, 0, 0);
			else
				glRotatef (-90.0f, 1, 0, 0);

			makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);

			glPopMatrix ();
		}

		d = (d + 37) % 100;

		if (d < dDensity) {
			glPushMatrix ();

			setMaterialAttribs();

			glTranslatef (0.25f, -0.25f, 0.25f);

			if (rsRandi (2))
				glRotatef (90.0f, 0, 1, 0);
			else
				glRotatef (-90.0f, 0, 1, 0);

			makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);

			glPopMatrix ();
		}

		d = (d + 37) % 100;

		if (d < dDensity) {
			glPushMatrix ();

			setMaterialAttribs();

			glTranslatef (0.25f, 0.25f, 0.25f);

			if (rsRandi (2))
				glRotatef (180.0f, 1, 0, 0);

			makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);

			glPopMatrix ();
		}

		d = (d + 37) % 100;

		if (d < dDensity) {
			glPushMatrix ();

			setMaterialAttribs();

			glTranslatef (-0.25f, 0.25f, 0.25f);

			if (rsRandi (2))
				glRotatef (90.0f, 1, 0, 0);
			else
				glRotatef (-90.0f, 1, 0, 0);

			makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);

			glPopMatrix ();
		}

		d = (d + 37) % 100;
		if (d < dDensity) {
			glPushMatrix ();

			setMaterialAttribs();

			glTranslatef (-0.25f, 0.25f, -0.25f);

			if (rsRandi (2))
				glRotatef (90.0f, 0, 1, 0);
			else
				glRotatef (-90.0f, 0, 1, 0);

			makeTorus (dSmooth, dLongitude, dLatitude, 0.36f - thick, thick);

			glPopMatrix ();
		}

		glEndList ();

		d = (d + 37) % 100;
	}
}
Esempio n. 8
0
void setMaterialAttribs(){
	if(dTexture == 0 || dTexture >= 5)
		glColor3f(rsRandf(1.0f), rsRandf(1.0f), rsRandf(1.0f));
	if(dTexture == 1)
		glBindTexture(GL_TEXTURE_2D, texture_id[rsRandi(2)]);
}
Esempio n. 9
0
void hack_handle_opts (int argc, char **argv)
{
	int change_flag = 0;

	setDefaults (PRESET_REGULAR);

	while (1) {
		int c;

#ifdef HAVE_GETOPT_H
		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			DRIVER_OPTIONS_LONG
			{"preset", 1, 0, 'p'},
			{"regular", 0, 0, 10},
			{"chainmail", 0, 0, 11},
			{"brassmesh", 0, 0, 12},
			{"computer", 0, 0, 13},
			{"slick", 0, 0, 14},
			{"tasty", 0, 0, 15},
			{"longitude", 1, 0, 'l'},
			{"latitude", 1, 0, 'L'},
			{"thick", 1, 0, 't'},
			{"density", 1, 0, 'd'},
			{"drawdepth", 1, 0, 'D'},
			{"fov", 1, 0, 'o'},
			{"pathrand", 1, 0, 'P'},
			{"speed", 1, 0, 'e'},
			{"texture", 1, 0, 'T'},
			{"industrial", 0, 0, 1},
			{"crystal", 0, 0, 2},
			{"chrome", 0, 0, 3},
			{"brass", 0, 0, 4},
			{"shiny", 0, 0, 5},
			{"ghostly", 0, 0, 6},
			{"circuits", 0, 0, 7},
			{"doughnuts", 0, 0, 8},
			{"smooth", 0, 0, 's'},
			{"no-smooth", 0, 0, 'S'},
			{"fog", 0, 0, 'f'},
			{"no-fog", 0, 0, 'F'},
			{0, 0, 0, 0}
		};

		c = getopt_long (argc, argv, DRIVER_OPTIONS_SHORT "hp:l:L:t:d:D:o:P:e:T:sSfF", long_options, NULL);
#else
		c = getopt (argc, argv, DRIVER_OPTIONS_SHORT "hp:l:L:t:d:D:o:P:e:T:sSfF");
#endif
		if (c == -1)
			break;

		switch (c) {
		DRIVER_OPTIONS_CASES case 'h':
			printf ("%s:"
#ifndef HAVE_GETOPT_H
				" Not built with GNU getopt.h, long options *NOT* enabled."
#endif
				"\n" DRIVER_OPTIONS_HELP 
				"\t--preset/-p <arg>\n" "\t--regular\n" "\t--chainmail\n" "\t--brassmesh\n" "\t--computer\n" "\t--slick\n" "\t--tasty\n"
				"\t--longitude/-l <arg>\n" "\t--latitude/-L <arg>\n" 
				"\t--thick/-t <arg>\n" "\t--density/-d <arg>\n" 
				"\t--drawdepth/-D <arg>\n" "\t--fov/-o <arg>\n" 
				"\t--pathrand/-P <arg>\n" "\t--speed/-e <arg>\n" 
				"\t--texture/-T <arg>\n" "\t--industrial\n" "\t--crystal\n" "\t--chrome\n" "\t--brass\n" "\t--shiny\n" "\t--ghostly\n" "\t--circuits\n" "\t--doughnuts\n"
				"\t--smooth/-s\n" "\t--no-smooth/-S\n" 
				"\t--fog/-f\n" " \t--no-fog/-F\n", argv[0]);
			exit (1);
		case 'p':
			change_flag = 1;
			setDefaults (strtol_minmaxdef (optarg, 10, 1, 6, 0, 1, "--preset: "));
			break;
		case 10:
		case 11:
		case 12:
		case 13:
		case 14:
		case 15:
			change_flag = 1;
			setDefaults (c - 9);
			break;
		case 'l':
			change_flag = 1;
			dLongitude = strtol_minmaxdef (optarg, 10, 4, 100, 1, 16, "--longitude: ");
			break;
		case 'L':
			change_flag = 1;
			dLatitude = strtol_minmaxdef (optarg, 10, 2, 100, 1, 8, "--latitude: ");
			break;
		case 't':
			change_flag = 1;
			dThick = strtol_minmaxdef (optarg, 10, 1, 100, 1, 50, "--thick: ");
			break;
		case 'd':
			change_flag = 1;
			dDensity = strtol_minmaxdef (optarg, 10, 1, 100, 1, 50, "--density: ");
			break;
		case 'D':
			change_flag = 1;
			dDrawdepth = strtol_minmaxdef (optarg, 10, 1, 8, 1, 4, "--drawdepth: ");
			break;
		case 'o':
			change_flag = 1;
			dFov = strtol_minmaxdef (optarg, 10, 10, 150, 1, 90, "--fov: ");
			break;
		case 'P':
			change_flag = 1;
			dPathrand = strtol_minmaxdef (optarg, 10, 1, 10, 1, 1, "--pathrand: ");
			break;
		case 'e':
			change_flag = 1;
			dSpeed = strtol_minmaxdef (optarg, 10, 1, 100, 1, 1, "--speed: ");
			break;
		case 'T':
			change_flag = 1;
			dTexture = strtol_minmaxdef (optarg, 10, 0, 9, 0, 0, "--texture: ");
			break;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
			change_flag = 1;
			dTexture = c;
			break;
		case 's':
			change_flag = 1;
			dSmooth = 1;
			break;
		case 'S':
			change_flag = 1;
			dSmooth = 0;
			break;
		case 'f':
			change_flag = 1;
			dFog = 1;
			break;
		case 'F':
			change_flag = 1;
			dFog = 0;
			break;
		}
	}

	if (!change_flag) {
		setDefaults (rsRandi (6) + 1);
	}
}
Esempio n. 10
0
void hack_handle_opts (int argc, char **argv)
{
	int change_flag = 0;

	dTexture = 1;
	dCoarse = 0;
	dSinHole = 0;
	dWireframe = 0;

	while (1) {
		int c;

#ifdef HAVE_GETOPT_H
		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			DRIVER_OPTIONS_LONG 
			{"texture", 1, 0, 't'},
			{"swirl", 0, 0, 1},
			{"marble", 0, 0, 2},
			{"coarseness", 1, 0, 'c'},
			{"sinusoide", 0, 0, 's'},
			{"no-sinusoide", 0, 0, 'S'},
			{"wireframe", 0, 0, 'w'},
			{"no-wireframe", 0, 0, 'W'},
			{0, 0, 0, 0}
		};

		c = getopt_long (argc, argv, DRIVER_OPTIONS_SHORT "hc:t:sSwW", long_options, NULL);
#else
		c = getopt (argc, argv, DRIVER_OPTIONS_SHORT "hc:t:sSwW");
#endif
		if (c == -1)
			break;

		switch (c) {
		DRIVER_OPTIONS_CASES case 'h':
			printf ("%s:"
#ifndef HAVE_GETOPT_H
				" Not built with GNU getopt.h, long options *NOT* enabled."
#endif
				"\n" DRIVER_OPTIONS_HELP "\t--texture/-t <arg>\n" "\t--swirl\n" "\t--marble\n" "\t--coarseness/-c <arg>\n" "\t--sinusoide/-s\n" "\t--no-sinusoide/-S\n" 
				"\t--wireframe/-w\n" "\t--no-wireframe/-W\n", argv[0]);
			exit (1);
		case 't':
			change_flag = 1;
			dTexture = strtol_minmaxdef (optarg, 10, 0, 2, 0, 1, "--texture: ");
			break;
		case 1:
			change_flag = 1;
			dTexture = 1;
			break;
		case 2:
			change_flag = 1;
			dTexture = 2;
			break;
		case 'c':
			change_flag = 1;
			dCoarse = 1 << (3 - strtol_minmaxdef (optarg, 10, 0, 3, 1, 0, "--coarseness: "));

			if (dCoarse == 8)
				dCoarse = 0;

			break;
		case 's':
			change_flag = 1;
			dSinHole = 1;
			break;
		case 'S':
			change_flag = 1;
			dSinHole = 0;
			break;
		case 'w':
			change_flag = 1;
			dWireframe = 1;
			break;
		case 'W':
			change_flag = 1;
			dWireframe = 0;
			break;
		}
	}

	if (!change_flag) {
		dTexture = rsRandi (2) + 1;
		dCoarse = 1 << (3 - rsRandi (4));

		if (dCoarse == 8)
			dCoarse = 0;

		dSinHole = rsRandi (2);
		dWireframe = (rsRandi (10) == 0);
	}
}
Esempio n. 11
0
void hack_draw (xstuff_t * XStuff, double currentTime, float frameTime)
{
	int i;
	static int ionsReleased = 0;
	static float releaseTime = 0.0f;
	Display *dpy = XStuff->display;
#ifdef BENCHMARK
	static int a = 1;
#endif

	Window window = XStuff->window;

	elapsedTime = frameTime;

#ifdef BENCHMARK
	if (a++ == 1000)
		exit(0);
	elapsedTime = 0.1f;
#endif

	// Camera movements
	// first do translation (distance from center)
	static float oldCameraDistance;
	static float cameraDistance;
	static float targetCameraDistance = -1000.0f;
	static float preCameraInterp = PI;
	float cameraInterp;

	preCameraInterp += float (dCameraspeed) * elapsedTime * 0.01f;

	cameraInterp = 0.5f - (0.5f * cos (preCameraInterp));
	cameraDistance = (1.0f - cameraInterp) * oldCameraDistance + cameraInterp * targetCameraDistance;

	if (preCameraInterp >= PI) {
		oldCameraDistance = targetCameraDistance;
		targetCameraDistance = -rsRandf (1300.0f) - 200.0f;
		preCameraInterp = 0.0f;
	}

	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
	glTranslatef (0.0, 0.0, cameraDistance);

	// then do rotation
	static rsVec radialVel = rsVec (0.0f, 0.0f, 0.0f);
	static rsVec targetRadialVel = radialVel;
	static rsQuat rotQuat = rsQuat (0.0f, 0.0f, 0.0f, 1.0f);

	rsVec radialVelDiff = targetRadialVel - radialVel;
	float changeRemaining = radialVelDiff.normalize ();
	float change = float (dCameraspeed) * 0.0002f * elapsedTime;

	if (changeRemaining > change) {
		radialVelDiff *= change;
		radialVel += radialVelDiff;
	} else {
		radialVel = targetRadialVel;
		if (rsRandi (2)) {
			targetRadialVel = rsVec (rsRandf (1.0f), rsRandf (1.0f), rsRandf (1.0f));
			targetRadialVel.normalize ();
			targetRadialVel *= float (dCameraspeed) * rsRandf (0.002f);
		} else
			targetRadialVel = rsVec (0.0f, 0.0f, 0.0f);
	}

	rsVec tempRadialVel = radialVel;
	float angle = tempRadialVel.normalize ();

	rsQuat radialQuat;

	radialQuat.make (angle, tempRadialVel[0], tempRadialVel[1], tempRadialVel[2]);
	rotQuat.preMult (radialQuat);
	rsMatrix rotMat;

	rotMat.fromQuat (rotQuat);

	// make billboard matrix for rotating particles when they are drawn
	rotMat.get (billboardMat);

	// Calculate new color
	static rsVec oldHsl, newHsl = rsVec (rsRandf (1.0f), 1.0f, 1.0f), targetHsl;
	static float colorInterp = 1.0f, colorChange;

	colorInterp += elapsedTime * colorChange;
	if (colorInterp >= 1.0f) {
		if (!rsRandi (3) && dIons >= 100)	// change color suddenly
			newHsl = rsVec (rsRandf (1.0f), 1.0f - (rsRandf (1.0f) * rsRandf (1.0f)), 1.0f);
		oldHsl = newHsl;
		targetHsl = rsVec (rsRandf (1.0f), 1.0f - (rsRandf (1.0f) * rsRandf (1.0f)), 1.0f);
		colorInterp = 0.0f;
		// amount by which to change colorInterp each second
		colorChange = rsRandf (0.005f * float (dSpeed)) + (0.002f * float (dSpeed));
	} else {
		float diff = targetHsl[0] - oldHsl[0];

		if (diff < -0.5f || (diff > 0.0f && diff < 0.5f))
			newHsl[0] = oldHsl[0] + colorInterp * diff;
		else
			newHsl[0] = oldHsl[0] - colorInterp * diff;
		diff = targetHsl[1] - oldHsl[1];
		newHsl[1] = oldHsl[1] + colorInterp * diff;
		if (newHsl[0] < 0.0f)
			newHsl[0] += 1.0f;
		if (newHsl[0] > 1.0f)
			newHsl[0] -= 1.0f;
		hsl2rgb (newHsl[0], newHsl[1], 1.0f, newRgb[0], newRgb[1], newRgb[2]);
	}

	// Release ions
	if (ionsReleased < dIons) {
		releaseTime -= elapsedTime;
		while (ionsReleased < dIons && releaseTime <= 0.0f) {
			ilist[ionsReleased].start ();
			ionsReleased++;
			// all ions released after 2 minutes
			releaseTime += 120.0f / float (dIons);
		}
	}
	// Set interpolation value for emitters and attracters
	static float wait = 0.0f;
	static float preinterp = PI, interp;
	static float interpconst = 0.001f;

	wait -= elapsedTime;
	if (wait <= 0.0f) {
		preinterp += elapsedTime * float (dSpeed) * interpconst;

		interp = 0.5f - (0.5f * cos (preinterp));
	}
	if (preinterp >= PI) {
		// select new taget points (not the same pattern twice in a row)
		static int newTarget = 0, lastTarget;

		lastTarget = newTarget;
		newTarget = rsRandi (10);
		if (newTarget == lastTarget)
			newTarget++;
		setTargets (newTarget);
		preinterp = 0.0f;
		interp = 0.0f;
		wait = 10.0f;	// pause after forming each new pattern
		interpconst = 0.001f;
		if (!rsRandi (4))	// interpolate really fast sometimes
			interpconst = 0.1f;
	}
	// Update particles
	for (i = 0; i < dEmitters; i++) {
		elist[i].interppos (interp);
		elist[i].update ();
	}
	for (i = 0; i < dAttracters; i++) {
		alist[i].interppos (interp);
		alist[i].update ();
	}
	for (i = 0; i < ionsReleased; i++)
		ilist[i].update ();

	// Calculate surface
	if (dSurface) {
		for (i = 0; i < dEmitters; i++)
			spheres[i].setPosition (elist[i].pos[0], elist[i].pos[1], elist[i].pos[2]);
		for (i = 0; i < dAttracters; i++)
			spheres[dEmitters + i].setPosition (alist[i].pos[0], alist[i].pos[1], alist[i].pos[2]);

		impCrawlPointVector cpv;
		for(i=0; i<dEmitters+dAttracters; i++)
			spheres[i].addCrawlPoint(cpv);

		surface->reset ();

		static float valuetrig = 0.0f;
		valuetrig += elapsedTime;

		volume->setSurfaceValue(0.45f + 0.05f * cosf(valuetrig));
		volume->makeSurface(cpv);
	}
	// Draw
	// clear the screen
	if (dBlur) {		// partially
		glMatrixMode (GL_PROJECTION);
		glPushMatrix ();
			glLoadIdentity();
			glOrtho(0.0, 1.0, 0.0, 1.0, 1.0, -1.0);
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
				glLoadIdentity();
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				glColor4f(0.0f, 0.0f, 0.0f, 0.5f - (float(sqrtf(sqrtf(float(dBlur)))) * 0.15495f));
				glBegin(GL_TRIANGLE_STRIP);
					glVertex3f(0.0f, 0.0f, 0.0f);
					glVertex3f(1.0f, 0.0f, 0.0f);
					glVertex3f(0.0f, 1.0f, 0.0f);
					glVertex3f(1.0f, 1.0f, 0.0f);
			glEnd();
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	} else			// completely
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Draw ions
	glMatrixMode(GL_MODELVIEW);
	glBlendFunc (GL_ONE, GL_ONE);
	glBindTexture (GL_TEXTURE_2D, 1);
	for (i = 0; i < ionsReleased; i++)
		ilist[i].draw ();

	// Draw surfaces
	float brightFactor = 0;
	float surfaceColor[3] = {
		0.0f,
		0.0f,
		0.0f
	};

	if (dSurface) {
		glBindTexture (GL_TEXTURE_2D, 2);
		glEnable (GL_TEXTURE_GEN_S);
		glEnable (GL_TEXTURE_GEN_T);
		// find color for surfaces
		if (dIons >= 100) {
			if (dWireframe)
				brightFactor = 2.0f / (float (dBlur + 30) * float (dBlur + 30));
			else
				brightFactor = 4.0f / (float (dBlur + 30) * float (dBlur + 30));
			for (i = 0; i < 100; i++) {
				surfaceColor[0] += ilist[i].rgb[0] * brightFactor;
				surfaceColor[1] += ilist[i].rgb[1] * brightFactor;
				surfaceColor[2] += ilist[i].rgb[2] * brightFactor;
			}
			glColor3fv (surfaceColor);
		} else {
			if (dWireframe)
				brightFactor = 200.0f / (float (dBlur + 30) * float (dBlur + 30));
			else
				brightFactor = 400.0f / (float (dBlur + 30) * float (dBlur + 30));
			glColor3f (newRgb[0] * brightFactor, newRgb[1] * brightFactor, newRgb[2] * brightFactor);
		}
		// draw the surface
		glPushMatrix ();
		glMultMatrixf (billboardMat);
		if (dWireframe) {
			glDisable (GL_TEXTURE_2D);
			surface->draw_wireframe ();
			glEnable (GL_TEXTURE_2D);
		} else
			surface->draw ();
		glPopMatrix ();
		glDisable (GL_TEXTURE_GEN_S);
		glDisable (GL_TEXTURE_GEN_T);
	}
	// If graphics card does a true buffer swap instead of a copy swap
	// then everything must get drawn on both buffers
	if (dBlur & pfd_swap_exchange) {
		glXSwapBuffers (dpy, window);
		// wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glColor4f (0.0f, 0.0f, 0.0f, 0.5f - (float (sqrt (sqrt (double (dBlur)))) * 0.15495f));

		glPushMatrix ();
		glLoadIdentity ();
		glBegin (GL_TRIANGLE_STRIP);
		glVertex3f (-5.0f, -4.0f, -3.0f);
		glVertex3f (5.0f, -4.0f, -3.0f);
		glVertex3f (-5.0f, 4.0f, -3.0f);
		glVertex3f (5.0f, 4.0f, -3.0f);
		glEnd ();
		glPopMatrix ();

		// Draw ions
		glBlendFunc (GL_ONE, GL_ONE);
		glBindTexture (GL_TEXTURE_2D, 1);
		for (i = 0; i < ionsReleased; i++)
			ilist[i].draw ();

		// Draw surfaces
		if (dSurface) {
			glBindTexture (GL_TEXTURE_2D, 2);
			glEnable (GL_TEXTURE_GEN_S);
			glEnable (GL_TEXTURE_GEN_T);
			if (dIons >= 100)
				glColor3fv (surfaceColor);
			else
				glColor3f (newRgb[0] * brightFactor, newRgb[1] * brightFactor, newRgb[2] * brightFactor);
			glPushMatrix ();
			glMultMatrixf (billboardMat);
			if (dWireframe) {
				glDisable (GL_TEXTURE_2D);
				surface->draw_wireframe ();
				glEnable (GL_TEXTURE_2D);
			} else
				surface->draw ();
			glPopMatrix ();
			glDisable (GL_TEXTURE_GEN_S);
			glDisable (GL_TEXTURE_GEN_T);
		}
	}
}
Esempio n. 12
0
void initWorld ()
{
	int i, j;
	float x, y, z;
	unsigned int startex;
	unsigned int moontex;
	unsigned int moonglowtex;
	unsigned int sunsettex;
	unsigned char *tex;

	// Initialize cloud texture object even if clouds are not turned on.
	// Sunsets and shockwaves can also use cloud texture.
	glGenTextures (1, &cloudtex);
	glBindTexture (GL_TEXTURE_2D, cloudtex);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	LOAD_TEXTURE (tex, cloudmap, cloudmap_compressedsize, cloudmap_size)
		gluBuild2DMipmaps (GL_TEXTURE_2D, 2, CLOUDTEXSIZE, CLOUDTEXSIZE, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, tex);
	FREE_TEXTURE (tex)
		// initialize star texture
		if (dStardensity) {
		unsigned char starmap[STARTEXSIZE][STARTEXSIZE][3];

		for (i = 0; i < STARTEXSIZE; i++) {
			for (j = 0; j < STARTEXSIZE; j++) {
				starmap[i][j][0] = starmap[i][j][1] = starmap[i][j][2] = 0;
			}
		}
		int u, v;
		unsigned int rgb[3];

		for (i = 0; i < (dStardensity * 20); i++) {
			u = rsRandi (STARTEXSIZE - 4) + 2;
			v = rsRandi (STARTEXSIZE - 4) + 2;
			rgb[0] = 220 + rsRandi (36);
			rgb[1] = 220 + rsRandi (36);
			rgb[2] = 220 + rsRandi (36);
			rgb[rsRandi (3)] = 255;
			starmap[u][v][0] = rgb[0];
			starmap[u][v][1] = rgb[1];
			starmap[u][v][2] = rgb[2];
			switch (rsRandi (6)) {	// different stars
			case 0:	// small
			case 1:
			case 2:
				starmap[u][v][0] /= 2;
				starmap[u][v][1] /= 2;
				starmap[u][v][2] /= 2;
				starmap[u + 1][v][0] = starmap[u - 1][v][0] = starmap[u][v + 1][0] = starmap[u][v - 1][0] = rgb[0] / (3 + rsRandi (6));
				starmap[u + 1][v][1] = starmap[u - 1][v][1] = starmap[u][v + 1][1] = starmap[u][v - 1][1] = rgb[1] / (3 + rsRandi (6));
				starmap[u + 1][v][2] = starmap[u - 1][v][2] = starmap[u][v + 1][2] = starmap[u][v - 1][2] = rgb[2] / (3 + rsRandi (6));
				break;
			case 3:	// medium
			case 4:
				starmap[u + 1][v][0] = starmap[u - 1][v][0] = starmap[u][v + 1][0] = starmap[u][v - 1][0] = rgb[0] / 2;
				starmap[u + 1][v][1] = starmap[u - 1][v][1] = starmap[u][v + 1][1] = starmap[u][v - 1][1] = rgb[1] / 2;
				starmap[u + 1][v][2] = starmap[u - 1][v][2] = starmap[u][v + 1][2] = starmap[u][v - 1][2] = rgb[2] / 2;
				break;
			case 5:	// large
				starmap[u + 1][v][0] = starmap[u - 1][v][0] = starmap[u][v + 1][0] = starmap[u][v - 1][0] = char (float (rgb[0]) * 0.75f);
				starmap[u + 1][v][1] = starmap[u - 1][v][1] = starmap[u][v + 1][1] = starmap[u][v - 1][1] = char (float (rgb[1]) * 0.75f);
				starmap[u + 1][v][2] = starmap[u - 1][v][2] = starmap[u][v + 1][2] = starmap[u][v - 1][2] = char (float (rgb[2]) * 0.75f);

				starmap[u + 1][v + 1][0] = starmap[u + 1][v - 1][0] = starmap[u - 1][v + 1][0] = starmap[u - 1][v - 1][0] = rgb[0] / 4;
				starmap[u + 1][v + 1][1] = starmap[u + 1][v - 1][1] = starmap[u - 1][v + 1][1] = starmap[u - 1][v - 1][1] = rgb[1] / 4;
				starmap[u + 1][v + 1][2] = starmap[u + 1][v - 1][2] = starmap[u - 1][v + 1][2] = starmap[u - 1][v - 1][2] = rgb[2] / 4;
			}
		}
		glGenTextures (1, &startex);
		glBindTexture (GL_TEXTURE_2D, startex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		gluBuild2DMipmaps (GL_TEXTURE_2D, 3, STARTEXSIZE, STARTEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, starmap);
	}
	//initialize moon texture
	if (dMoon) {
		unsigned char moonmap[MOONTEXSIZE][MOONTEXSIZE][4];
		unsigned char *mtint;
		unsigned char *malpha;

		LOAD_TEXTURE (mtint, moontint, moontint_compressedsize, moontint_size)
			LOAD_TEXTURE (malpha, moonalpha, moonalpha_compressedsize, moonalpha_size)

			for (i = 0; i < MOONTEXSIZE; i++) {
			for (j = 0; j < MOONTEXSIZE; j++) {
				moonmap[i][j][0] = moonmap[i][j][1] = moonmap[i][j][2] = mtint[i * MOONTEXSIZE + j];
				moonmap[i][j][3] = malpha[i * MOONTEXSIZE + j];
			}
		}

		FREE_TEXTURE (mtint)
			FREE_TEXTURE (malpha)

			glGenTextures (1, &moontex);
		glBindTexture (GL_TEXTURE_2D, moontex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		gluBuild2DMipmaps (GL_TEXTURE_2D, 4, MOONTEXSIZE, MOONTEXSIZE, GL_RGBA, GL_UNSIGNED_BYTE, moonmap);
	}
	//initialize moon glow texture
	if (dMoonglow) {
		unsigned char moonglowmap[MOONGLOWTEXSIZE][MOONGLOWTEXSIZE][4];

		float temp1, temp2, temp3, u, v;

		for (i = 0; i < MOONGLOWTEXSIZE; i++) {
			for (j = 0; j < MOONGLOWTEXSIZE; j++) {
				u = float (i - MOONGLOWTEXSIZE / 2) / float (MOONGLOWTEXSIZE / 2);
				v = float (j - MOONGLOWTEXSIZE / 2) / float (MOONGLOWTEXSIZE / 2);

				temp1 = 4.0f * ((u * u) + (v * v)) * (1.0f - ((u * u) + (v * v)));
				if (temp1 > 1.0f)
					temp1 = 1.0f;
				if (temp1 < 0.0f)
					temp1 = 0.0f;
				temp1 = temp1 * temp1 * temp1 * temp1;
				u *= 1.2f;
				v *= 1.2f;
				temp2 = 4.0f * ((u * u) + (v * v)) * (1.0f - ((u * u) + (v * v)));
				if (temp2 > 1.0f)
					temp2 = 1.0f;
				if (temp2 < 0.0f)
					temp2 = 0.0f;
				temp2 = temp2 * temp2 * temp2 * temp2;
				u *= 1.25f;
				v *= 1.25f;
				temp3 = 4.0f * ((u * u) + (v * v)) * (1.0f - ((u * u) + (v * v)));
				if (temp3 > 1.0f)
					temp3 = 1.0f;
				if (temp3 < 0.0f)
					temp3 = 0.0f;
				temp3 = temp3 * temp3 * temp3 * temp3;
				moonglowmap[i][j][0] = char (255.0f * (temp1 * 0.4f + temp2 * 0.4f + temp3 * 0.48f));
				moonglowmap[i][j][1] = char (255.0f * (temp1 * 0.4f + temp2 * 0.48f + temp3 * 0.38f));
				moonglowmap[i][j][2] = char (255.0f * (temp1 * 0.48f + temp2 * 0.4f + temp3 * 0.38f));
				moonglowmap[i][j][3] = char (255.0f * (temp1 * 0.48f + temp2 * 0.48f + temp3 * 0.48f));
			}
		}
		glGenTextures (1, &moonglowtex);
		glBindTexture (GL_TEXTURE_2D, moonglowtex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		gluBuild2DMipmaps (GL_TEXTURE_2D, 4, MOONGLOWTEXSIZE, MOONGLOWTEXSIZE, GL_RGBA, GL_UNSIGNED_BYTE, moonglowmap);

	}
	// do a sunset?
	doSunset = 1;
	if (!rsRandi (4))
		doSunset = 0;

	// initialize sunset texture
	if (doSunset) {
		unsigned char *sunsetmap;
		unsigned char rgb[3];
		float temp;

		sunsetmap = (unsigned char *)malloc (CLOUDTEXSIZE * CLOUDTEXSIZE * 3);

		if (rsRandi (3))
			rgb[0] = 60 + rsRandi (42);
		else
			rgb[0] = rsRandi (102);
		rgb[1] = rsRandi (rgb[0]);
		rgb[2] = 0;
		if (rgb[1] < 50)
			rgb[2] = 100 - rsRandi (rgb[0]);
		for (j = 0; j < CLOUDTEXSIZE; j++) {
			for (i = 0; i < CLOUDTEXSIZE; i++) {
				sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 0] = rgb[0];
				sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 1] = rgb[1];
				sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 2] = rgb[2];
			}
		}
		// clouds in sunset
		if (rsRandi (3)) {
			float cloudinf;	// influence of clouds
			int xoffset = rsRandi (CLOUDTEXSIZE);
			int yoffset = rsRandi (CLOUDTEXSIZE);
			int x, y;

			for (i = 0; i < CLOUDTEXSIZE; i++) {
				for (j = 0; j < CLOUDTEXSIZE; j++) {
					x = (i + xoffset) % CLOUDTEXSIZE;
					y = (j + yoffset) % CLOUDTEXSIZE;
					cloudinf = float (cloudmap[x * CLOUDTEXSIZE * 2 + y * 2 + 1]) / 256.0f;
					temp = float (sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 0]) / 256.0f;

					temp *= cloudinf;
					sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 0] = char (temp * 256.0f);
					cloudinf *= float (cloudmap[x * CLOUDTEXSIZE * 2 + y * 2]) / 256.0f;
					temp = float (sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 1]) / 256.0f;

					temp *= cloudinf;
					sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 1] = char (temp * 256.0f);
				}
			}
		}
		// Fractal mountain generation
		int mountains[CLOUDTEXSIZE + 1];

		mountains[0] = mountains[CLOUDTEXSIZE] = rsRandi (10) + 5;
		makeHeights (0, CLOUDTEXSIZE, mountains);
		for (i = 0; i < CLOUDTEXSIZE; i++) {
			for (j = 0; j <= mountains[i]; j++) {
				sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 0] = 0;
				sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 1] = 0;
				sunsetmap[i * CLOUDTEXSIZE * 3 + j * 3 + 2] = 0;
			}
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 1) * 3 + 0] /= 4;
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 1) * 3 + 1] /= 4;
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 1) * 3 + 2] /= 4;
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 2) * 3 + 0] /= 2;
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 2) * 3 + 1] /= 2;
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 2) * 3 + 2] /= 2;
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 3) * 3 + 0] = char (float (sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 3) * 3 + 0]) * 0.75f);
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 3) * 3 + 1] = char (float (sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 3) * 3 + 1]) * 0.75f);
			sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 3) * 3 + 2] = char (float (sunsetmap[i * CLOUDTEXSIZE * 3 + (mountains[i] + 3) * 3 + 2]) * 0.75f);
		}
		// build texture object
		glGenTextures (1, &sunsettex);
		glBindTexture (GL_TEXTURE_2D, sunsettex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		gluBuild2DMipmaps (GL_TEXTURE_2D, 3, CLOUDTEXSIZE, CLOUDTEXSIZE, GL_RGB, GL_UNSIGNED_BYTE, sunsetmap);

		free (sunsetmap);
	}
	//initialize earth texture
	if (dEarth) {
		glGenTextures (1, &earthneartex);
		glBindTexture (GL_TEXTURE_2D, earthneartex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		LOAD_TEXTURE (tex, earthnearmap, earthnearmap_compressedsize, earthnearmap_size)
			gluBuild2DMipmaps (GL_TEXTURE_2D, 3, EARTHNEARSIZE, EARTHNEARSIZE, GL_RGB, GL_UNSIGNED_BYTE, tex);
		FREE_TEXTURE (tex)
			glGenTextures (1, &earthfartex);
		glBindTexture (GL_TEXTURE_2D, earthfartex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		LOAD_TEXTURE (tex, earthfarmap, earthfarmap_compressedsize, earthfarmap_size)
			gluBuild2DMipmaps (GL_TEXTURE_2D, 3, EARTHFARSIZE, EARTHFARSIZE, GL_RGB, GL_UNSIGNED_BYTE, tex);
		FREE_TEXTURE (tex)
			glGenTextures (1, &earthlighttex);
		glBindTexture (GL_TEXTURE_2D, earthlighttex);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		LOAD_TEXTURE (tex, earthlightmap, earthlightmap_compressedsize, earthlightmap_size)
			gluBuild2DMipmaps (GL_TEXTURE_2D, 3, EARTHFARSIZE, EARTHFARSIZE, GL_RGB, GL_UNSIGNED_BYTE, tex);
		FREE_TEXTURE (tex)
	}
	// initialize star geometry
	if (dStardensity) {
		float stars[STARMESH + 1][STARMESH / 2][6];	// 6 = x,y,z,u,v,bright

		for (j = 0; j < STARMESH / 2; j++) {
			y = sin (RS_PIo2 * float (j) / float (STARMESH / 2));

			for (i = 0; i <= STARMESH; i++) {
				x = cos (RS_PIx2 * float (i) / float (STARMESH)) * cos (RS_PIo2 * float (j) / float (STARMESH / 2));
				z = sin (RS_PIx2 * float (i) / float (STARMESH)) * cos (RS_PIo2 * float (j) / float (STARMESH / 2));

				// positions
				stars[i][j][0] = x * 20000.0f;
				stars[i][j][1] = 1500.0f + 18500.0f * y;
				stars[i][j][2] = z * 20000.0f;
				// tex coords
				stars[i][j][3] = 1.2f * x * (2.5f - y);
				stars[i][j][4] = 1.2f * z * (2.5f - y);
				// brightness
				if (stars[i][j][1] < 1501.0f)
					stars[i][j][5] = 0.0f;
				else
					stars[i][j][5] = 1.0f;
			}
		}
		starlist = glGenLists (1);
		glNewList (starlist, GL_COMPILE);
		glBindTexture (GL_TEXTURE_2D, startex);
		for (j = 0; j < (STARMESH / 2 - 1); j++) {
			glBegin (GL_TRIANGLE_STRIP);
			for (i = 0; i <= STARMESH; i++) {
				glColor3f (stars[i][j + 1][5], stars[i][j + 1][5], stars[i][j + 1][5]);
				glTexCoord2f (stars[i][j + 1][3], stars[i][j + 1][4]);
				glVertex3fv (stars[i][j + 1]);
				glColor3f (stars[i][j][5], stars[i][j][5], stars[i][j][5]);
				glTexCoord2f (stars[i][j][3], stars[i][j][4]);
				glVertex3fv (stars[i][j]);
			}
			glEnd ();
		}
		j = STARMESH / 2 - 1;
		glBegin (GL_TRIANGLE_FAN);
		glColor3f (1.0f, 1.0f, 1.0f);
		glTexCoord2f (0.0f, 0.0f);
		glVertex3f (0.0f, 20000.0f, 0.0f);
		for (i = 0; i <= STARMESH; i++) {
			glColor3f (stars[i][j][5], stars[i][j][5], stars[i][j][5]);
			glTexCoord2f (stars[i][j][3], stars[i][j][4]);
			glVertex3fv (stars[i][j]);
		}
		glEnd ();
		glEndList ();
	}
	// initialize moon geometry
	if (dMoon) {
		moonlist = glGenLists (1);
		glNewList (moonlist, GL_COMPILE);
		glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
		glBindTexture (GL_TEXTURE_2D, moontex);
		glBegin (GL_TRIANGLE_STRIP);
		glTexCoord2f (0.0f, 0.0f);
		glVertex3f (-800.0f, -800.0f, 0.0f);
		glTexCoord2f (1.0f, 0.0f);
		glVertex3f (800.0f, -800.0f, 0.0f);
		glTexCoord2f (0.0f, 1.0f);
		glVertex3f (-800.0f, 800.0f, 0.0f);
		glTexCoord2f (1.0f, 1.0f);
		glVertex3f (800.0f, 800.0f, 0.0f);
		glEnd ();
		glEndList ();
	}
	// initialize moon glow geometry
	if (dMoonglow) {
		moonglowlist = glGenLists (1);
		glNewList (moonglowlist, GL_COMPILE);
		glBindTexture (GL_TEXTURE_2D, moonglowtex);
		glBegin (GL_TRIANGLE_STRIP);
		glTexCoord2f (0.0f, 0.0f);
		glVertex3f (-7000.0f, -7000.0f, 0.0f);
		glTexCoord2f (1.0f, 0.0f);
		glVertex3f (7000.0f, -7000.0f, 0.0f);
		glTexCoord2f (0.0f, 1.0f);
		glVertex3f (-7000.0f, 7000.0f, 0.0f);
		glTexCoord2f (1.0f, 1.0f);
		glVertex3f (7000.0f, 7000.0f, 0.0f);
		glEnd ();
		glEndList ();
	}
	// initialize cloud geometry
	if (dClouds) {
		for (j = 0; j <= CLOUDMESH; j++) {
			for (i = 0; i <= CLOUDMESH; i++) {
				x = float (i - (CLOUDMESH / 2));
				z = float (j - (CLOUDMESH / 2));

				clouds[i][j][0] = x * (40000.0f / float (CLOUDMESH));
				clouds[i][j][2] = z * (40000.0f / float (CLOUDMESH));
				x = float (fabs (x / float (CLOUDMESH / 2)));
				z = float (fabs (z / float (CLOUDMESH / 2)));
				clouds[i][j][1] = 2000.0f - 1000.0f * float (x * x + z * z);
				clouds[i][j][3] = float (-i) / float (CLOUDMESH / 6);	// tex coords
				clouds[i][j][4] = float (-j) / float (CLOUDMESH / 6);
				clouds[i][j][5] = (clouds[i][j][1] - 1000.0f) * 0.00001f * float (dAmbient);	// brightness

				if (clouds[i][j][5] < 0.0f)
					clouds[i][j][5] = 0.0f;
			}
		}
	}
	// initialize sunset geometry
	if (doSunset) {
		sunsetlist = glGenLists (1);
		float vert[6] = { 0.0f, 7654.0f, 8000.0f, 14142.0f, 18448.0f, 20000.0f };

		glNewList (sunsetlist, GL_COMPILE);
		glBindTexture (GL_TEXTURE_2D, sunsettex);
		glBegin (GL_TRIANGLE_STRIP);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.0f);
		glVertex3f (vert[0], vert[2], vert[5]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (0.0f, 0.0f);
		glVertex3f (vert[0], vert[0], vert[5]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.125f);
		glVertex3f (-vert[1], vert[2], vert[4]);
		glColor3f (0.25f, 0.25f, 0.25f);
		glTexCoord2f (0.0f, 0.125f);
		glVertex3f (-vert[1], vert[0], vert[4]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.25f);
		glVertex3f (-vert[3], vert[2], vert[3]);
		glColor3f (0.5f, 0.5f, 0.5f);
		glTexCoord2f (0.0f, 0.25f);
		glVertex3f (-vert[3], vert[0], vert[3]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.375f);
		glVertex3f (-vert[4], vert[2], vert[1]);
		glColor3f (0.75f, 0.75f, 0.75f);
		glTexCoord2f (0.0f, 0.375f);
		glVertex3f (-vert[4], vert[0], vert[1]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.5f);
		glVertex3f (-vert[5], vert[2], vert[0]);
		glColor3f (1.0f, 1.0f, 1.0f);
		glTexCoord2f (0.0f, 0.5f);
		glVertex3f (-vert[5], vert[0], vert[0]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.625f);
		glVertex3f (-vert[4], vert[2], -vert[1]);
		glColor3f (0.75f, 0.75f, 0.75f);
		glTexCoord2f (0.0f, 0.625f);
		glVertex3f (-vert[4], vert[0], -vert[1]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.75f);
		glVertex3f (-vert[3], vert[2], -vert[3]);
		glColor3f (0.5f, 0.5f, 0.5f);
		glTexCoord2f (0.0f, 0.75f);
		glVertex3f (-vert[3], vert[0], -vert[3]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 0.875f);
		glVertex3f (-vert[1], vert[2], -vert[4]);
		glColor3f (0.25f, 0.25f, 0.25f);
		glTexCoord2f (0.0f, 0.875f);
		glVertex3f (-vert[1], vert[0], -vert[4]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (1.0f, 1.0f);
		glVertex3f (vert[0], vert[2], -vert[5]);
		glColor3f (0.0f, 0.0f, 0.0f);
		glTexCoord2f (0.0f, 1.0f);
		glVertex3f (vert[0], vert[0], -vert[5]);
		glEnd ();
		glEndList ();
	}
	// initialize earth geometry
	if (dEarth) {
		earthlist = glGenLists (1);
		earthnearlist = glGenLists (1);
		earthfarlist = glGenLists (1);
		float lit[] = { float (dAmbient) * 0.01f, float (dAmbient) * 0.01f, float (dAmbient) * 0.01f };
		float unlit[] = { 0.0f, 0.0f, 0.0f };
		float vert[2] = { 839.68f, 8396.8f };
		float tex[4] = { 0.0f, 0.45f, 0.55f, 1.0f };

		glNewList (earthnearlist, GL_COMPILE);
		glColor3fv (lit);
		glBegin (GL_TRIANGLE_STRIP);
		glTexCoord2f (tex[0], tex[0]);
		glVertex3f (-vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[0], tex[3]);
		glVertex3f (-vert[0], 0.0f, vert[0]);
		glTexCoord2f (tex[3], tex[0]);
		glVertex3f (vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[3], tex[3]);
		glVertex3f (vert[0], 0.0f, vert[0]);
		glEnd ();
		glEndList ();
		glNewList (earthfarlist, GL_COMPILE);
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[1], tex[1]);
		glVertex3f (-vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[2], tex[1]);
		glVertex3f (vert[0], 0.0f, -vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[0], tex[0]);
		glVertex3f (-vert[1], 0.0f, -vert[1]);
		glTexCoord2f (tex[3], tex[0]);
		glVertex3f (vert[1], 0.0f, -vert[1]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[1], tex[2]);
		glVertex3f (-vert[0], 0.0f, vert[0]);
		glTexCoord2f (tex[1], tex[1]);
		glVertex3f (-vert[0], 0.0f, -vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[0], tex[3]);
		glVertex3f (-vert[1], 0.0f, vert[1]);
		glTexCoord2f (tex[0], tex[0]);
		glVertex3f (-vert[1], 0.0f, -vert[1]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[2], tex[2]);
		glVertex3f (vert[0], 0.0f, vert[0]);
		glTexCoord2f (tex[1], tex[2]);
		glVertex3f (-vert[0], 0.0f, vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[3], tex[3]);
		glVertex3f (vert[1], 0.0f, vert[1]);
		glTexCoord2f (tex[0], tex[3]);
		glVertex3f (-vert[1], 0.0f, vert[1]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[2], tex[1]);
		glVertex3f (vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[2], tex[2]);
		glVertex3f (vert[0], 0.0f, vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[3], tex[0]);
		glVertex3f (vert[1], 0.0f, -vert[1]);
		glTexCoord2f (tex[3], tex[3]);
		glVertex3f (vert[1], 0.0f, vert[1]);
		glEnd ();
		glEndList ();
		glNewList (earthlist, GL_COMPILE);
		lit[0] = lit[1] = lit[2] = 0.4f;
		glColor3fv (lit);
		glBegin (GL_TRIANGLE_STRIP);
		glTexCoord2f (tex[1], tex[1]);
		glVertex3f (-vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[1], tex[2]);
		glVertex3f (-vert[0], 0.0f, vert[0]);
		glTexCoord2f (tex[2], tex[1]);
		glVertex3f (vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[2], tex[2]);
		glVertex3f (vert[0], 0.0f, vert[0]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[1], tex[1]);
		glVertex3f (-vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[2], tex[1]);
		glVertex3f (vert[0], 0.0f, -vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[0], tex[0]);
		glVertex3f (-vert[1], 0.0f, -vert[1]);
		glTexCoord2f (tex[3], tex[0]);
		glVertex3f (vert[1], 0.0f, -vert[1]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[1], tex[2]);
		glVertex3f (-vert[0], 0.0f, vert[0]);
		glTexCoord2f (tex[1], tex[1]);
		glVertex3f (-vert[0], 0.0f, -vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[0], tex[3]);
		glVertex3f (-vert[1], 0.0f, vert[1]);
		glTexCoord2f (tex[0], tex[0]);
		glVertex3f (-vert[1], 0.0f, -vert[1]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[2], tex[2]);
		glVertex3f (vert[0], 0.0f, vert[0]);
		glTexCoord2f (tex[1], tex[2]);
		glVertex3f (-vert[0], 0.0f, vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[3], tex[3]);
		glVertex3f (vert[1], 0.0f, vert[1]);
		glTexCoord2f (tex[0], tex[3]);
		glVertex3f (-vert[1], 0.0f, vert[1]);
		glEnd ();
		glBegin (GL_TRIANGLE_STRIP);
		glColor3fv (lit);
		glTexCoord2f (tex[2], tex[1]);
		glVertex3f (vert[0], 0.0f, -vert[0]);
		glTexCoord2f (tex[2], tex[2]);
		glVertex3f (vert[0], 0.0f, vert[0]);
		glColor3fv (unlit);
		glTexCoord2f (tex[3], tex[0]);
		glVertex3f (vert[1], 0.0f, -vert[1]);
		glTexCoord2f (tex[3], tex[3]);
		glVertex3f (vert[1], 0.0f, vert[1]);
		glEnd ();
		glEndList ();
	}
}
Esempio n. 13
0
void SceneManager::FrameMove()
{
   //更新时间
  static int index = 0; 
	
	if(m_Stop)return;//暂停动画

   frameTime = m_Timer.tick();

   
   //更新粒子系统
   // Slows fireworks, but not camera
   if(kSlowMotion) frameTime *= 0.5f;
  

   if(m_Fps!=0)
   {
    frameTime = 1/(float)m_Fps; 

   }
   //更新照像机
   m_Camera.Update(m_ParticleSystem.particles,frameTime,m_ParticleSystem.last_particle);


   m_ParticleSystem.AllocNewParticle();//增加新粒子空间
  
   //是否暂停动画
   if(!kFireworks) return; //如果暂停动画返回
	
   //更新世界
   theWorld.update(frameTime);
	
   //减淡
   static float ambientlight = float(dAmbient) * 0.01f;
   for(unsigned int i=0; i<m_ParticleSystem.last_particle; ++i)
   {
	 Particle* darkener(&(m_ParticleSystem.particles[i]));
	 if(darkener->type == SMOKE) darkener->rgb[0] = darkener->rgb[1] = darkener->rgb[2] = ambientlight;
   }

	//改变火箭发射速率
    static float rocketTimer[6] = {0,0,0,0,0,0};
	static float rocketTimeConst[6] = {5.0f,25,40,35,50,55};
	static float changeRocketTimeConst[6] ={25,50,65,65,50,50};
	

	for(int i=0;i<6;i++)
	{
     changeRocketTimeConst[i] -= frameTime;
     if(changeRocketTimeConst[i] <= 0.0f)
	{
	 float temp = rsRandf(4.0f);
	 //rocketTimeConst[i] = (temp * temp) + (10.0f / float(dMaxrockets));
	 changeRocketTimeConst[i] = rsRandf(30.0f) + 10.0f;
	}
     rocketTimer[i] -= frameTime;
	}

	//发射火箭
	
	if(rocketTimer[0] <= 0.0f)//生存期结束
	{
	   Particle* rock = m_ParticleSystem.AddParticle();//火箭粒子

	   //初始化火箭 //确定火箭类型
	   rock->xyz[0] = rsRandf(20.0f);// - 900.0f;
	   rock->xyz[1] = 5.0f;
	   rock->xyz[2] = rsRandf(20.0f);// - 900.0f;
	   rock->initRocket();
       int y =rsRandi(8);
	  

	   if(index==2)
	   {
         rock->explosiontype =6; 
	   }
	   else if(index==5)
	   {
         rock->explosiontype =6; 
	   }
	   else if(index==8)
	   {
         rock->explosiontype =6; 
	   }
	   else
	   {
	   rock->m_Fire = &m_CFire[index];
	   m_CFire[index].m_Exploded = false;//未爆炸
	    m_CFire[index].m_Boom = false; 
	   rock->explosiontype =22; 
	   }
	   index++;
	   index = index%11;
	   
	   
	 
	   if(dMaxrockets) rocketTimer[0] = rocketTimeConst[0];//火箭时间
		else rocketTimer[0] = 60.0f;  // arbitrary number since no rockets ever fire	
	}
   /*if(rocketTimer[1] <= 0.0f)//生存期结束
	{
	   Particle* rock = m_ParticleSystem.AddParticle();//火箭粒子

	   //初始化火箭 //确定火箭类型
	   rock->xyz[0] = rsRandf(200.0f);// + 800.0f;
	   rock->xyz[1] = 5.0f;
	   rock->xyz[2] = rsRandf(200.0f);// + 500.0f;
	   rock->initRocket();
	    if(rsRandi(2))
	   rock->m_Fire = &m_CFire[1];
		else rock->m_Fire = &m_CFire[5];
	   rock->explosiontype = 22; 
       if(dMaxrockets) rocketTimer[1] = rsRandf(rocketTimeConst[1]);//火箭时间
	   else rocketTimer[1] = 60.0f;  // arbitrary number since no rockets ever fire	

	   }
	if(rocketTimer[2] <= 0.0f)//生存期结束
	{
	  Particle* rock = m_ParticleSystem.AddParticle();//火箭粒子

	   //初始化火箭 //确定火箭类型
	   rock->xyz[0] = rsRandf(200.0f) + 700.0f;
	   rock->xyz[1] = 5.0f;
	   rock->xyz[2] = rsRandf(200.0f) - 500.0f;
	   rock->initRocket();
	   if(rsRandi(2))
	   rock->m_Fire = &m_CFire[2];
	   else rock->m_Fire = &m_CFire[6];
	   rock->explosiontype = 22; 
	   		 
	  
		if(dMaxrockets) rocketTimer[2] = rsRandf(rocketTimeConst[2]);//火箭时间
		else rocketTimer[2] = 60.0f;  // arbitrary number since no rockets ever fire	
	}
	if(rocketTimer[3] <= 0.0f)//生存期结束
	{
	   Particle* rock = m_ParticleSystem.AddParticle();//火箭粒子

	   //初始化火箭 //确定火箭类型
	   rock->xyz[0] = rsRandf(200.0f) - 500.0f;
	   rock->xyz[1] = 5.0f;
	   rock->xyz[2] = rsRandf(200.0f) + 700.0f;
	   rock->initRocket();
	   if(rsRandi(2))
	   rock->m_Fire = &m_CFire[3];
	   else rock->m_Fire = &m_CFire[7];
	   rock->explosiontype = 22; 
	   if(dMaxrockets) rocketTimer[3] = rsRandf(rocketTimeConst[3]);//火箭时间
		else rocketTimer[3] = 60.0f;  // arbitrary number since no rockets ever fire	
	}
	if(rocketTimer[4] <= 0.0f)//生存期结束
	{
	   Particle* rock = m_ParticleSystem.AddParticle();//火箭粒子

	   //初始化火箭 //确定火箭类型
	   rock->xyz[0] = rsRandf(200.0f) - 1000.0f;
	   rock->xyz[1] = 5.0f;
	   rock->xyz[2] = rsRandf(200.0f) + 500.0f;
	   rock->initRocket();
	   rock->explosiontype = 3; 
	   if(dMaxrockets) rocketTimer[4] = rsRandf(rocketTimeConst[4]);//火箭时间
		else rocketTimer[4] = 60.0f;  // arbitrary number since no rockets ever fire	
	}
	if(rocketTimer[5] <= 0.0f)//生存期结束
	{
	   Particle* rock = m_ParticleSystem.AddParticle();//火箭粒子

	   //初始化火箭 //确定火箭类型
	   rock->xyz[0] = rsRandf(200.0f) - 1300.0f;
	   rock->xyz[1] = 5.0f;
	   rock->xyz[2] = rsRandf(200.0f) + 500.0f;
	   rock->initRocket();
	   rock->explosiontype = 4; 
	   if(dMaxrockets) rocketTimer[5] = rsRandf(rocketTimeConst[5]);//火箭时间
		else rocketTimer[5] = 60.0f;  // arbitrary number since no rockets ever fire	
	}
	*/
	

		//更新粒子
		numRockets = 0;
		for(unsigned int i=0; i<m_ParticleSystem.last_particle; i++)
		{
		  Particle* curpart(&(m_ParticleSystem.particles[i]));
		  m_ParticleSystem.particles[i].update(frameTime,dSmoke,dClouds,dWind,dAmbient,dIllumination,&theWorld);
		  if(curpart->type == ROCKET) numRockets++;
		 
		  
		  // curpart->findDepth(m_Camera.cameraPos,billboardMat);
		  


		  if(curpart->type==IGNITOR&&curpart->life <0.93)
		  {
            if(!curpart->m_Fire->m_Exploded)//未爆炸
		{
     if(IsRecord())
	{
	  m_PlayTime.push_back(m_Frame*m_f);//记录时间
	  m_PlayStyle.push_back(BOOM1SOUND );//记录类型
	  m_PlayPos.push_back(m_Camera.cameraPos);
	  m_PlaySource.push_back(curpart->xyz);
	  soundengine->insertSoundNode(BOOM1SOUND , curpart->xyz, m_Camera.cameraPos);
      
	  m_PlayTime.push_back(m_Frame*m_f);//记录时间
	  m_PlayStyle.push_back(SUCKSOUND);//记录类型
	  m_PlayPos.push_back(m_Camera.cameraPos);
	  m_PlaySource.push_back(curpart->xyz);
      soundengine->insertSoundNode(SUCKSOUND, curpart->xyz,m_Camera.cameraPos);

	}
	else
	{
   //播放声音
  soundengine->insertSoundNode(BOOM1SOUND, curpart->xyz, m_Camera.cameraPos);
  soundengine->insertSoundNode(SUCKSOUND , curpart->xyz, m_Camera.cameraPos);
   } 
    curpart->m_Fire->m_Exploded = true;
   }
}

     if(curpart->m_Fire!=NULL&&curpart->type==ROCKET&&curpart->life <0.43)
	 {
       if(!curpart->m_Fire->m_Boom)//未爆炸
			  {
               if(IsRecord())
	        {
	         m_PlayTime.push_back(m_Frame*m_f);//记录时间
	         m_PlayStyle.push_back(BOOM1SOUND );//记录类型
	         m_PlayPos.push_back(m_Camera.cameraPos);
	         m_PlaySource.push_back(curpart->xyz);
	         soundengine->insertSoundNode(BOOM1SOUND , curpart->xyz, m_Camera.cameraPos);
     
	         }
	        else
	        {
             //播放声音
             soundengine->insertSoundNode(BOOM1SOUND, curpart->xyz, m_Camera.cameraPos);
 
           } 
                 curpart->m_Fire->m_Boom = true;
          }


	 }


		  //点燃烟花
		  if(curpart->life <= 0.0f || curpart->xyz[1] < 0.0f)
		  {
		   switch(curpart->type)
		   {
			case ROCKET:
			if(curpart->xyz[1] <= 0.0f)
			{
			  // move above ground for explosion so new particles aren't removed
			  curpart->xyz[1] = 0.1f;
			  curpart->vel[1] *= -0.7f;
			}
					
			if(curpart->explosiontype == 18)
			curpart->initSpinner();
			else
			{
			 
				
				curpart->initExplosion();
			


			}
			break;
				
			case IGNITOR:
            
	
			curpart->m_Fire->m_Ignitor++;
		    if(curpart->m_Fire->m_Ignitor==8)
			{
             curpart->m_Fire->m_Ignitor = 0;
			 curpart->explosiontype = 0;
			  curpart->initExplosion();		
			 curpart->explosiontype = 21;
			 curpart->initExplosion();
			}
			else
			{
              curpart->explosiontype = 0;
			  curpart->initExplosion();			
           
			}

			break;
			case POPPER:
			switch(curpart->explosiontype)
			{
			case 21:
            curpart->initExplosion();

				break;
			  case STAR:
			  curpart->explosiontype = 100;
			  curpart->initExplosion();
			  break;
					
			  case STREAMER:
			  curpart->explosiontype = 101;
			  curpart->initExplosion();
			  break;
					
			  case METEOR:
			  curpart->explosiontype = 102;
			  curpart->initExplosion();			
			  break;
		
			  case POPPER:
			  curpart->type = STAR;
			  curpart->rgb.set(1.0f, 0.8f, 0.6f);
			  curpart->t = m_ParticleSystem.particles[i].tr = m_ParticleSystem.particles[i].life = 0.2f;		
			}
			break;
				
			case SUCKER:
			  curpart->initShockwave();
			  break;
				
			case STRETCHER:
			  curpart->initBigmama();		
		   }
		  }
		}

   m_ParticleSystem.DeallocParticle();//删除粒子
		
}
Esempio n. 14
0
void initSaver(HWND hwnd){
	RECT rect;

	// Window initialization
	hdc = GetDC(hwnd);
	setBestPixelFormat(hdc);
	hglrc = wglCreateContext(hdc);
	GetClientRect(hwnd, &rect);
	wglMakeCurrent(hdc, hglrc);
	
	// setup viewport
	//viewport[0] = rect.left;
	//viewport[1] = rect.top;
	//viewport[2] = rect.right - rect.left;
	//viewport[3] = rect.bottom - rect.top;

	// initialize extensions
	if(!initExtensions())
		dShaders = 0;

	reshape(rect.right, rect.bottom);
#endif
//#ifdef RS_XSCREENSAVER
void initSaver(HyperspaceSaverSettings *inSettings){
//#endif
	// Seed random number generator
	srand((unsigned)time(NULL));

	// Limit memory consumption because the Windows previewer is just too darn slow
	/*if(doingPreview){
		dResolution = 6;
		if(dDepth > 3)
			dDepth = 3;
	};*/
	
	// Set up some other inSettings defaults...
	inSettings->camPos[0] = 0.0f;
	inSettings->camPos[1] = 0.0f;
	inSettings->camPos[2] = 0.0f;
	inSettings->numAnimTexFrames = 20;
	inSettings->whichTexture = 0;

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

	initFlares(inSettings);

	inSettings->thePath = new splinePath((inSettings->dDepth * 2) + 6);

	if(inSettings->dUseTunnels)
		inSettings->theTunnel = new tunnel(inSettings->thePath, 20);

	// To avoid popping, depth, which will be used for fogging, is set to
	// dDepth * goo grid size - size of one goo cubelet
	inSettings->depth = float(inSettings->dDepth) * 2.0f - 2.0f / float(inSettings->dResolution);

	if(inSettings->dUseGoo)
		inSettings->theGoo = new goo(inSettings->dResolution, inSettings->depth);

	inSettings->stars = new stretchedParticle*[inSettings->dStars];
	for(int i=0; i<inSettings->dStars; i++){
		inSettings->stars[i] = new stretchedParticle;
		inSettings->stars[i]->radius = rsRandf(float(inSettings->dStarSize) * 0.0005f) + float(inSettings->dStarSize) * 0.0005f;
		if(i % 10){  // usually bland stars
			inSettings->stars[i]->color[0] = 0.8f + rsRandf(0.2f);
			inSettings->stars[i]->color[1] = 0.8f + rsRandf(0.2f);
			inSettings->stars[i]->color[2] = 0.8f + rsRandf(0.2f);
		}
		else{  // occasionally a colorful one
			inSettings->stars[i]->color[0] = 0.3f + rsRandf(0.7f);
			inSettings->stars[i]->color[1] = 0.3f + rsRandf(0.7f);
			inSettings->stars[i]->color[2] = 0.3f + rsRandf(0.7f);
			inSettings->stars[i]->color[rsRandi(3)] = 1.0f;
		}
		inSettings->stars[i]->color[rsRandi(3)] = 1.0f;
		inSettings->stars[i]->pos[0] = rsRandf(2.0f * inSettings->depth) - inSettings->depth;
		inSettings->stars[i]->pos[1] = rsRandf(4.0f) - 2.0f;
		inSettings->stars[i]->pos[2] = rsRandf(2.0f * inSettings->depth) - inSettings->depth;
		inSettings->stars[i]->fov = float(inSettings->dFov);
	}

	inSettings->sunStar = new stretchedParticle;
	inSettings->sunStar->radius = float(inSettings->dStarSize) * 0.004f;
	inSettings->sunStar->pos[0] = 0.0f;
	inSettings->sunStar->pos[1] = 2.0f;
	inSettings->sunStar->pos[2] = 0.0f;
	inSettings->sunStar->fov = float(inSettings->dFov);

	inSettings->theStarBurst = new starBurst;
	for(int i=0; i<SB_NUM_STARS; i++)
		inSettings->theStarBurst->stars[i]->radius = rsRandf(float(inSettings->dStarSize) * 0.001f) + float(inSettings->dStarSize) * 0.001f;

	glGenTextures(1, &inSettings->nebulatex);
	if(inSettings->dShaders){
		initShaders();
		inSettings->numAnimTexFrames = 20;
		glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->nebulatex);
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
		gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
		gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
		gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
		gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
		gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
	}
	else{
		//unsigned char spheremap[NEBULAMAPSIZE][NEBULAMAPSIZE][3] = nebulamap;
		inSettings->numAnimTexFrames = 60;
		float x, y, temp;
		const int halfsize(NEBULAMAPSIZE / 2);
		for(int i=0; i<NEBULAMAPSIZE; ++i){
			for(int j=0; j<NEBULAMAPSIZE; ++j){
				x = float(i - halfsize) / float(halfsize);
				y = float(j - halfsize) / float(halfsize);
				temp = (x * x) + (y * y);
				if(temp > 1.0f)
					temp = 1.0f;
				if(temp < 0.0f)
					temp = 0.0f;
				temp = temp * temp;
				temp = temp * temp;
				nebulamap[i][j][0] = GLubyte(float(nebulamap[i][j][0]) * temp);
				nebulamap[i][j][1] = GLubyte(float(nebulamap[i][j][1]) * temp);
				nebulamap[i][j][2] = GLubyte(float(nebulamap[i][j][2]) * temp);
			}
		}
		glEnable(GL_NORMALIZE);
		glBindTexture(GL_TEXTURE_2D, inSettings->nebulatex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap);
	}

	glEnable(GL_FOG);
	float fog_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
	glFogfv(GL_FOG_COLOR, fog_color);
	glFogf(GL_FOG_MODE, GL_LINEAR);
	glFogf(GL_FOG_START, inSettings->depth * 0.7f);
	glFogf(GL_FOG_END, inSettings->depth);

	// Initialize text
	inSettings->textwriter = new rsText;

	//outfile.open("outfile");

	inSettings->readyToDraw = 1;
}
Esempio n. 15
0
void draw(HyperspaceSaverSettings *inSettings){
	if(inSettings->first){
		if(inSettings->dUseTunnels){  // only tunnels use caustic textures
			glDisable(GL_FOG);
			// Caustic textures can only be created after rendering context has been created
			// because they have to be drawn and then read back from the framebuffer.
#ifdef WIN32
			if(doingPreview) // super fast for Windows previewer
				inSettings->theCausticTextures = new causticTextures(8, inSettings->numAnimTexFrames, 32, 32, 1.0f, 0.01f, 10.0f);
			else  // normal
#endif
				inSettings->theCausticTextures = new causticTextures(8, inSettings->numAnimTexFrames, 100, 256, 1.0f, 0.01f, 20.0f);
			glEnable(GL_FOG);
		}
		if(inSettings->dShaders){
#ifdef WIN32
			if(doingPreview) // super fast for Windows previewer
				inSettings->theWNCM = new wavyNormalCubeMaps(inSettings->numAnimTexFrames, 32);
			else  // normal
#endif
				inSettings->theWNCM = new wavyNormalCubeMaps(inSettings->numAnimTexFrames, 128);
		}
		glViewport(inSettings->viewport[0], inSettings->viewport[1], inSettings->viewport[2], inSettings->viewport[3]);
		inSettings->first = 0;
	}

	// Variables for printing text
	static float computeTime = 0.0f;
	static float drawTime = 0.0f;
	//static rsTimer computeTimer, drawTimer;
	// start compute time timer
	//computeTimer.tick();

	glMatrixMode(GL_MODELVIEW);

	// Camera movements
	static float camHeading[3] = {0.0f, 0.0f, 0.0f};  // current, target, and last
	static int changeCamHeading = 1;
	static float camHeadingChangeTime[2] = {20.0f, 0.0f};  // total, elapsed
	static float camRoll[3] = {0.0f, 0.0f, 0.0f};  // current, target, and last
	static int changeCamRoll = 1;
	static float camRollChangeTime[2] = {1.0f, 0.0f};  // total, elapsed
	camHeadingChangeTime[1] += inSettings->frameTime;
	if(camHeadingChangeTime[1] >= camHeadingChangeTime[0]){  // Choose new direction
		camHeadingChangeTime[0] = rsRandf(15.0f) + 5.0f;
		camHeadingChangeTime[1] = 0.0f;
		camHeading[2] = camHeading[1];  // last = target
		if(changeCamHeading){
			// face forward most of the time
			if(rsRandi(6))
				camHeading[1] = 0.0f;
			// face backward the rest of the time
			else if(rsRandi(2))
				camHeading[1] = RS_PI;
			else
				camHeading[1] = -RS_PI;
			changeCamHeading = 0;
		}
		else
			changeCamHeading = 1;
	}
	float t = camHeadingChangeTime[1] / camHeadingChangeTime[0];
	t = 0.5f * (1.0f - cosf(RS_PI * t));
	camHeading[0] = camHeading[1] * t + camHeading[2] * (1.0f - t);
	camRollChangeTime[1] += inSettings->frameTime;
	if(camRollChangeTime[1] >= camRollChangeTime[0]){  // Choose new roll angle
		camRollChangeTime[0] = rsRandf(5.0f) + 10.0f;
		camRollChangeTime[1] = 0.0f;
		camRoll[2] = camRoll[1];  // last = target
		if(changeCamRoll){
			camRoll[1] = rsRandf(RS_PIx2*2) - RS_PIx2;
			changeCamRoll = 0;
		}
		else
			changeCamRoll = 1;
	}
	t = camRollChangeTime[1] / camRollChangeTime[0];
	t = 0.5f * (1.0f - cosf(RS_PI * t));
	camRoll[0] = camRoll[1] * t + camRoll[2] * (1.0f - t);

	static float pathDir[3] = {0.0f, 0.0f, -1.0f};
	inSettings->thePath->moveAlongPath(float(inSettings->dSpeed) * inSettings->frameTime * 0.04f);
	inSettings->thePath->update(inSettings->frameTime);
	inSettings->thePath->getPoint(inSettings->dDepth + 2, inSettings->thePath->step, inSettings->camPos);
	inSettings->thePath->getBaseDirection(inSettings->dDepth + 2, inSettings->thePath->step, pathDir);
	float pathAngle = atan2f(-pathDir[0], -pathDir[2]);

	glLoadIdentity();
	glRotatef((pathAngle + camHeading[0]) * RS_RAD2DEG, 0, 1, 0);
	glRotatef(camRoll[0] * RS_RAD2DEG, 0, 0, 1);
	glGetFloatv(GL_MODELVIEW_MATRIX, inSettings->billboardMat);
	glLoadIdentity();
	glRotatef(-camRoll[0] * RS_RAD2DEG, 0, 0, 1);
	glRotatef((-pathAngle - camHeading[0]) * RS_RAD2DEG, 0, 1, 0);
	glTranslatef(inSettings->camPos[0]*-1, inSettings->camPos[1]*-1, inSettings->camPos[2]*-1);
	glGetDoublev(GL_MODELVIEW_MATRIX, inSettings->modelMat);
	inSettings->unroll = camRoll[0] * RS_RAD2DEG;

	if(inSettings->dUseGoo){
		// calculate diagonal fov
		float diagFov = 0.5f * float(inSettings->dFov) / RS_RAD2DEG;
		diagFov = tanf(diagFov);
		diagFov = sqrtf(diagFov * diagFov + (diagFov * inSettings->aspectRatio * diagFov * inSettings->aspectRatio));
		diagFov = 2.0f * atanf(diagFov);
		inSettings->theGoo->update(inSettings->camPos[0], inSettings->camPos[2], pathAngle + camHeading[0], diagFov, inSettings);
	}

	// measure compute time
	//computeTime += computeTimer.tick();
	// start draw time timer
	//drawTimer.tick();

	// clear
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	// draw stars
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE2_ARB);
	glBindTexture(GL_TEXTURE_2D, NULL);
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glBindTexture(GL_TEXTURE_2D, NULL);
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glBindTexture(GL_TEXTURE_2D, inSettings->flaretex[0]);
	static float temppos[2];
	for(int i=0; i<inSettings->dStars; i++){
		temppos[0] = inSettings->stars[i]->pos[0] - inSettings->camPos[0];
		temppos[1] = inSettings->stars[i]->pos[2] - inSettings->camPos[2];
		if(temppos[0] > inSettings->depth){
			inSettings->stars[i]->pos[0] -= inSettings->depth * 2.0f;
			inSettings->stars[i]->lastPos[0] -= inSettings->depth * 2.0f;
		}
		if(temppos[0] < inSettings->depth*-1){
			inSettings->stars[i]->pos[0] += inSettings->depth * 2.0f;
			inSettings->stars[i]->lastPos[0] += inSettings->depth * 2.0f;
		}
		if(temppos[1] > inSettings->depth){
			inSettings->stars[i]->pos[2] -= inSettings->depth * 2.0f;
			inSettings->stars[i]->lastPos[2] -= inSettings->depth * 2.0f;
		}
		if(temppos[1] < inSettings->depth*-1){
			inSettings->stars[i]->pos[2] += inSettings->depth * 2.0f;
			inSettings->stars[i]->lastPos[2] += inSettings->depth * 2.0f;
		}
		inSettings->stars[i]->draw(inSettings->camPos, inSettings->unroll, inSettings->modelMat, inSettings->projMat, inSettings->viewport);
	}
	glDisable(GL_CULL_FACE);

	// pick animated texture frame
	static float textureTime = 0.0f;
	textureTime += inSettings->frameTime;
	// loop frames every 2 seconds
	const float texFrameTime(2.0f / float(inSettings->numAnimTexFrames));
	while(textureTime > texFrameTime){
		textureTime -= texFrameTime;
		inSettings->whichTexture ++;
	}
	while(inSettings->whichTexture >= inSettings->numAnimTexFrames)
		inSettings->whichTexture -= inSettings->numAnimTexFrames;

	// alpha component gets normalmap lerp value
	const float lerp = textureTime / texFrameTime;

	// draw goo
	if(inSettings->dUseGoo){
		// calculate color
		static float goo_rgb_phase[3] = {-0.1f, -0.1f, -0.1f};
		static float goo_rgb_speed[3] = {rsRandf(0.02f) + 0.02f, rsRandf(0.02f) + 0.02f, rsRandf(0.02f) + 0.02f};
		float goo_rgb[4];
		for(int i=0; i<3; i++){
			goo_rgb_phase[i] += goo_rgb_speed[i] * inSettings->frameTime;
			if(goo_rgb_phase[i] >= RS_PIx2)
				goo_rgb_phase[i] -= RS_PIx2;
			goo_rgb[i] = sinf(goo_rgb_phase[i]);
			if(goo_rgb[i] < 0.0f)
				goo_rgb[i] = 0.0f;
		}
		// setup textures
		if(inSettings->dShaders){
			goo_rgb[3] = lerp;
			glDisable(GL_TEXTURE_2D);
			glEnable(GL_TEXTURE_CUBE_MAP_ARB);
			glActiveTextureARB(GL_TEXTURE2_ARB);
			glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->nebulatex);
			glActiveTextureARB(GL_TEXTURE1_ARB);
			glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->theWNCM->texture[(inSettings->whichTexture + 1) % inSettings->numAnimTexFrames]);
			glActiveTextureARB(GL_TEXTURE0_ARB);
			glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->theWNCM->texture[inSettings->whichTexture]);
			glUseProgramObjectARB(gooProgram);
		}
		else{
			goo_rgb[3] = 1.0f;
			glBindTexture(GL_TEXTURE_2D, inSettings->nebulatex);
			glEnable(GL_TEXTURE_2D);
			glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
			glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
			glEnable(GL_TEXTURE_GEN_S);
			glEnable(GL_TEXTURE_GEN_T);
		}
		// draw it
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glEnable(GL_BLEND);
		glColor4fv(goo_rgb);
		inSettings->theGoo->draw();
		if(inSettings->dShaders){
			glDisable(GL_TEXTURE_CUBE_MAP_ARB);
			glUseProgramObjectARB(0);
		}
		else{
			glDisable(GL_TEXTURE_GEN_S);
			glDisable(GL_TEXTURE_GEN_T);
		}
	}

	// update starburst
	static float starBurstTime = 300.0f;  // burst after 5 minutes
	starBurstTime -= inSettings->frameTime;
	if(starBurstTime <= 0.0f){
		float pos[] = {inSettings->camPos[0] + (pathDir[0] * inSettings->depth * (0.5f + rsRandf(0.5f))),
			rsRandf(2.0f) - 1.0f,
			inSettings->camPos[2] + (pathDir[2] * inSettings->depth * (0.5f + rsRandf(0.5f)))};
		inSettings->theStarBurst->restart(pos);  // it won't actually restart unless it's ready to
		starBurstTime = rsRandf(240.0f) + 60.0f;  // burst again within 1-5 minutes
	}
	if(inSettings->dShaders)
		inSettings->theStarBurst->draw(lerp, inSettings);
	else
		inSettings->theStarBurst->draw(inSettings);

	// draw tunnel
	if(inSettings->dUseTunnels){
		inSettings->theTunnel->make(inSettings->frameTime, inSettings->dShaders);
		glCullFace(GL_BACK);
		glEnable(GL_CULL_FACE);
		glEnable(GL_TEXTURE_2D);
		if(inSettings->dShaders){
			glActiveTextureARB(GL_TEXTURE1_ARB);
			glBindTexture(GL_TEXTURE_2D, inSettings->theCausticTextures->caustictex[(inSettings->whichTexture + 1) % inSettings->numAnimTexFrames]);
			glActiveTextureARB(GL_TEXTURE0_ARB);
			glBindTexture(GL_TEXTURE_2D, inSettings->theCausticTextures->caustictex[inSettings->whichTexture]);
			glUseProgramObjectARB(tunnelProgram);
			inSettings->theTunnel->draw(lerp);
			glUseProgramObjectARB(0);
		}
		else{
			glBindTexture(GL_TEXTURE_2D, inSettings->theCausticTextures->caustictex[inSettings->whichTexture]);
			inSettings->theTunnel->draw();
		}
		glDisable(GL_CULL_FACE);
	}

	// draw sun with lens flare
	glDisable(GL_FOG);
	float flarepos[3] = {0.0f, 2.0f, 0.0f};
	glBindTexture(GL_TEXTURE_2D, inSettings->flaretex[0]);
	inSettings->sunStar->draw(inSettings->camPos, inSettings->unroll, inSettings->modelMat, inSettings->projMat, inSettings->viewport);
	float diff[3] = {flarepos[0] - inSettings->camPos[0], flarepos[1] - inSettings->camPos[1], flarepos[2] - inSettings->camPos[2]};
	float alpha = 0.5f - 0.005f * sqrtf(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]);
	if(alpha > 0.0f)
		flare(flarepos, 1.0f, 1.0f, 1.0f, alpha, inSettings);
	glEnable(GL_FOG);

	// measure draw time
	//drawTime += drawTimer.tick();

	// write text
	static float totalTime = 0.0f;
	totalTime += inSettings->frameTime;
	static std::vector<std::string> strvec;
	static int frames = 0;
	++frames;
	if(frames == 60){
		strvec.clear();
		std::string str1 = "         FPS = " + to_string(60.0f / totalTime);
		strvec.push_back(str1);
		std::string str2 = "compute time = " + to_string(computeTime / 60.0f);
		strvec.push_back(str2);
		std::string str3 = "   draw time = " + to_string(drawTime / 60.0f);
		strvec.push_back(str3);
		totalTime = 0.0f;
		computeTime = 0.0f;
		drawTime = 0.0f;
		frames = 0;
	}
	if(inSettings->kStatistics){
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0.0f, 50.0f * inSettings->aspectRatio, 0.0f, 50.0f, -1.0f, 1.0f);

		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(1.0f, 48.0f, 0.0f);

		glColor3f(1.0f, 0.6f, 0.0f);
		inSettings->textwriter->draw(strvec);

		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	}
	
#ifdef WIN32
	wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
#endif
#ifdef RS_XSCREENSAVER
	glXSwapBuffers(xdisplay, xwindow);
#endif
}
Esempio n. 16
0
void draw ()
{
	int i, j, k;
	int indexx, indexy, indexz;
	float xyz[4], dir[4], angvel[4], tempVec[4];
	static float oldxyz[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	static float oldDir[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	static float oldAngvel[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
	float angle, distance;
	float rotMat[16];
	float newQuat[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
	static float quat[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
	static int flymode = 1;
	static float flymodeChange = 20.0f;
	static int seg = 0;	/* Section of path */
	static float where = 0.0f;	/* Position on path */
	static float rollVel = 0.0f, rollAcc = 0.0f;
	int drawDepth = dDrawdepth + 2;
	static float rollChange = 0;	/* rsRandf (10.0f) + 2.0f; */

	where += (float)dSpeed * 0.05f * elapsedTime;
	if (where >= 1.0f) {
		where -= 1.0f;
		seg++;
	}

	if (seg >= segments) {
		seg = 0;
		reconfigure ();
	}

	/*
	 * Calculate position 
	 */
	xyz[0] = interpolate (path[seg][0], path[seg][3], path[seg + 1][0], path[seg + 1][3], where);
	xyz[1] = interpolate (path[seg][1], path[seg][4], path[seg + 1][1], path[seg + 1][4], where);
	xyz[2] = interpolate (path[seg][2], path[seg][5], path[seg + 1][2], path[seg + 1][5], where);

	/*
	 * Do rotation stuff 
	 */
	rsVec_subtract (xyz, oldxyz, (float *)&dir);
	rsVec_normalize ((float *)&dir);
	rsVec_cross ((float *)&angvel, dir, oldDir); /* Desired axis of rotation */

	/* Protect against mild "overflow" */
	float dot = MAX(MIN(rsVec_dot (oldDir, dir), -1.0), 1.0);
	float maxSpin = 0.25f * (float)dSpeed * elapsedTime;
	angle = MAX(MIN(acos(dot), -maxSpin), maxSpin);

	rsVec_scale ((float *)&angvel, angle); /* Desired angular velocity */
	rsVec_subtract (angvel, oldAngvel, (float *)&tempVec); /* Change in angular velocity */
	distance = rsVec_length (tempVec); /* Don't let angular velocity change too much */
	float rotationInertia = 0.007f * (float)dSpeed * elapsedTime;
	if (distance > rotationInertia * elapsedTime) {
		rsVec_scale ((float *)&tempVec, ((rotationInertia * elapsedTime) / distance));
		rsVec_add (oldAngvel, tempVec, (float *)&angvel);
	}

	flymodeChange -= elapsedTime;

	if (flymodeChange <= 1.0f)	/* prepare to transition */
		rsVec_scale ((float *)&angvel, flymodeChange);

	if (flymodeChange <= 0.0f) {	/* transition from one fly mode to 
					 * the other? */
		flymode = rsRandi (4);
		flymodeChange = rsRandf ((float)(150 - dSpeed)) + 5.0f;
	}

	rsVec_copy (angvel, (float *)&tempVec);	/* Recompute desired rotation */
	angle = rsVec_normalize ((float *)&tempVec);
	rsQuat_make ((float *)&newQuat, angle, tempVec[0], tempVec[1], tempVec[2]);	/* Use rotation */

	if (flymode)		/* fly normal (straight) */
		rsQuat_preMult ((float *)&quat, newQuat);
	else			/* don't fly normal (go backwards and stuff) */
		rsQuat_postMult ((float *)&quat, newQuat);

	/* Roll */
	rollChange -= elapsedTime;
	if (rollChange <= 0.0f) {
		rollAcc = rsRandf (0.02f * (float)dSpeed) - (0.01f * (float)dSpeed);
		rollChange = rsRandf (10.0f) + 2.0f;
	}

	rollVel += rollAcc * elapsedTime;

	if (rollVel > (0.04f * (float)dSpeed) && rollAcc > 0.0f)
		rollAcc = 0.0f;

	if (rollVel < (-0.04f * (float)dSpeed) && rollAcc < 0.0f)
		rollAcc = 0.0f;

	rsQuat_make ((float *)&newQuat, rollVel * elapsedTime, oldDir[0], oldDir[1], oldDir[2]);
	rsQuat_preMult ((float *)&quat, newQuat);

	/* quat.normalize(); */
	rsQuat_toMat ((float *)&quat, (float *)&rotMat);

	/*
	 * Save old stuff 
	 */
	rsVec_copy (xyz, (float *)&oldxyz);
	oldDir[0] = -rotMat[2];
	oldDir[1] = -rotMat[6];
	oldDir[2] = -rotMat[10];
	rsVec_copy (angvel, (float *)&oldAngvel);

	/*
	 * Apply transformations 
	 */
	glMatrixMode (GL_MODELVIEW);
	glLoadMatrixf (rotMat);
	glTranslatef (-xyz[0], -xyz[1], -xyz[2]);

	// Just in case display lists contain no colors
	glColor3f(1.0f, 1.0f, 1.0f);

	// Environment mapping for crystal, chrome, brass, shiny, and ghostly
	if(dTexture == 2 || dTexture == 3 || dTexture == 4  || dTexture == 5 || dTexture == 6){
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
	}

	/*
	 * Render everything 
	 */
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	for (i = globalxyz[0] - drawDepth; i <= globalxyz[0] + drawDepth; i++) {
		for (j = globalxyz[1] - drawDepth; j <= globalxyz[1] + drawDepth; j++) {
			for (k = globalxyz[2] - drawDepth; k <= globalxyz[2] + drawDepth; k++) {
				float tpos[4];	/* transformed position */

				tempVec[0] = (float)i - xyz[0];
				tempVec[1] = (float)j - xyz[1];
				tempVec[2] = (float)k - xyz[2];

				tpos[0] = tempVec[0] * rotMat[0] + tempVec[1] * rotMat[4] + tempVec[2] * rotMat[8];	/* + rotMat[12]; */
				tpos[1] = tempVec[0] * rotMat[1] + tempVec[1] * rotMat[5] + tempVec[2] * rotMat[9];	/* + rotMat[13]; */
				tpos[2] = tempVec[0] * rotMat[2] + tempVec[1] * rotMat[6] + tempVec[2] * rotMat[10];	/* + rotMat[14]; */

				#define radius 0.9f
				/* camera_inViewVolume */
				/*
				 * check back plane 
				 */
				if (!(tpos[2] < -(theCamera.farplane + radius))) {
					/*
					 * check bottom plane 
					 */
					if (!(rsVec_dot(tpos, theCamera.cullVec[0]) < -radius)) {
						/*
						 * check top plane 
						 */
						if (!(rsVec_dot(tpos, theCamera.cullVec[1]) < -radius)) {
							/*
							 * check left plane 
							 */
							if (!(rsVec_dot(tpos, theCamera.cullVec[2]) < -radius)) {
								/*
								 * check right plane 
								 */
								if (!(rsVec_dot(tpos, theCamera.cullVec[3]) < -radius)) {
									indexx = myMod (i);
									indexy = myMod (j);
									indexz = myMod (k);

									/*
									 * draw it 
									 */
									glPushMatrix ();
									glTranslatef ((float)i, (float)j, (float)k);
									glCallList (lattice[indexx][indexy][indexz]);
									glPopMatrix ();
								}
							}
						}
					}
				}
			}
		}
	}

	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);

	glFlush ();
}
Esempio n. 17
0
void hack_init (xstuff_t * XStuff)
{
	int i, j, k;

	hack_reshape (XStuff);

	if (dTexture == 9)	/* Choose random texture */
		dTexture = rsRandi (9);

	if (dTexture != 2 && dTexture != 6)	/* No z-buffering for crystal or ghostly */
		glEnable (GL_DEPTH_TEST);

	if (dTexture != 3 && dTexture != 4 && dTexture != 6) {	/* No lighting for chrome, brass, or ghostly */
		float ambient[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
		float diffuse[4] = { 1.0f, 1.0f, 1.0f, 0.0f };
		float specular[4] = { 1.0f, 1.0f, 1.0f, 0.0f };
		float position[4] = { 400.0f, 300.0f, 500.0f, 0.0f };

		/* float position[4] = {0.0f, 0.0f, 0.0f, 1.0f}; */

		glEnable (GL_LIGHTING);
		glEnable (GL_LIGHT0);
		glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

		glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
		glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
		glLightfv (GL_LIGHT0, GL_SPECULAR, specular);
		glLightfv (GL_LIGHT0, GL_POSITION, position);
	}
	glEnable (GL_COLOR_MATERIAL);
	if (dTexture == 0 || dTexture == 5 || dTexture >= 7) {
		glMaterialf (GL_FRONT, GL_SHININESS, 50.0f);
		glColorMaterial (GL_FRONT, GL_SPECULAR);
	}
	if (dTexture == 2) {
		glMaterialf (GL_FRONT, GL_SHININESS, 10.0f);
		glColorMaterial (GL_FRONT, GL_SPECULAR);
	}
	glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

	if (dFog) {
		float fog_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };

		glEnable (GL_FOG);
		glFogfv (GL_FOG_COLOR, fog_color);
		glFogf (GL_FOG_MODE, GL_LINEAR);
		glFogf (GL_FOG_START, (float)dDrawdepth * 0.3f);
		glFogf (GL_FOG_END, (float)dDrawdepth - 0.1f);
	}

	if (dTexture == 2 || dTexture == 6) {	/* Use blending for crystal and ghostly */
		glBlendFunc (GL_SRC_ALPHA, GL_ONE);
		glEnable (GL_BLEND);
	}

	if (dTexture == 7) {	/* Use blending for circuits */
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable (GL_BLEND);
	}

	if (dTexture) {
		glEnable (GL_TEXTURE_2D);
		initTextures ();
	}

	/*
	 * Initialize lattice objects and their positions in the lattice array 
	 */
	makeLatticeObjects ();
	for (i = 0; i < LATSIZE; i++) {
		for (j = 0; j < LATSIZE; j++) {
			for (k = 0; k < LATSIZE; k++) {
				lattice[i][j][k] = list_base + rsRandi (NUMOBJECTS);
			}
		}
	}

	/*
	 * Initialize border points horizontal border points 
	 */

	/*
	 * horizontal border points 
	 */
	for (i = 0; i < 6; i++) {
		for (j = 0; j < 6; j++) {
			bPnt[i][j] = 0.0f;
		}
	}

	bPnt[0][0] = 0.5f;
	bPnt[0][1] = -0.25f;
	bPnt[0][2] = 0.25f;
	bPnt[0][3] = 1.0f;	/* right */
	bPnt[1][0] = 0.5f;
	bPnt[1][1] = 0.25f;
	bPnt[1][2] = -0.25f;
	bPnt[1][3] = 1.0f;	/* right */
	bPnt[2][0] = -0.25f;
	bPnt[2][1] = 0.5f;
	bPnt[2][2] = 0.25f;
	bPnt[2][4] = 1.0f;	/* top */
	bPnt[3][0] = 0.25f;
	bPnt[3][1] = 0.5f;
	bPnt[3][2] = -0.25f;
	bPnt[3][4] = 1.0f;	/* top */
	bPnt[4][0] = -0.25f;
	bPnt[4][1] = -0.25f;
	bPnt[4][2] = 0.5f;
	bPnt[4][5] = 1.0f;	/* front */
	bPnt[5][0] = 0.25f;
	bPnt[5][1] = 0.25f;
	bPnt[5][2] = 0.5f;
	bPnt[5][5] = 1.0f;	/* front */

	/*
	 * diagonal border points 
	 */
	bPnt[6][0] = 0.5f;
	bPnt[6][1] = -0.5f;
	bPnt[6][2] = -0.5f;
	bPnt[6][3] = 1.0f;
	bPnt[6][4] = -1.0f;
	bPnt[6][5] = -1.0f;
	bPnt[7][0] = 0.5f;
	bPnt[7][1] = 0.5f;
	bPnt[7][2] = -0.5f;
	bPnt[7][3] = 1.0f;
	bPnt[7][4] = 1.0f;
	bPnt[7][5] = -1.0f;
	bPnt[8][0] = 0.5f;
	bPnt[8][1] = -0.5f;
	bPnt[8][2] = 0.5f;
	bPnt[8][3] = 1.0f;
	bPnt[8][4] = -1.0f;
	bPnt[8][5] = 1.0f;
	bPnt[9][0] = 0.5f;
	bPnt[9][1] = 0.5f;
	bPnt[9][2] = 0.5f;
	bPnt[9][3] = 1.0f;
	bPnt[9][4] = 1.0f;
	bPnt[9][5] = 1.0f;

	globalxyz[0] = 0;
	globalxyz[1] = 0;
	globalxyz[2] = 0;

	/*
	 * Set up first path section 
	 */
	path[0][0] = 0.0f;
	path[0][1] = 0.0f;
	path[0][2] = 0.0f;
	path[0][3] = 0.0f;
	path[0][4] = 0.0f;
	path[0][5] = 0.0f;

	j = rsRandi (12);
	k = j % 6;
	for (i = 0; i < 6; i++)
		path[1][i] = bPnt[k][i];

	if (j > 5) {		/* If we want to head in a negative direction */
		i = k / 2;	/* then we need to flip along the appropriate axis */
		path[1][i] *= -1.0f;
		path[1][i + 3] *= -1.0f;
	}

	lastBorder = k;
	segments = 1;
}
Esempio n. 18
0
void
  ion::start ()
{
	int i = rsRandi (dEmitters);
	float offset = elapsedTime * speed;

	pos = elist[i].pos;

	switch (rsRandi (14)) {
	case 0:
		pos[0] += offset;
		break;
	case 1:
		pos[0] -= offset;
		break;
	case 2:
		pos[1] += offset;
		break;
	case 3:
		pos[1] -= offset;
		break;
	case 4:
		pos[2] += offset;
		break;
	case 5:
		pos[2] -= offset;
		break;
	case 6:
		pos[0] += offset;
		pos[1] += offset;
		pos[2] += offset;
		break;
	case 7:
		pos[0] -= offset;
		pos[1] += offset;
		pos[2] += offset;
		break;
	case 8:
		pos[0] += offset;
		pos[1] -= offset;
		pos[2] += offset;
		break;
	case 9:
		pos[0] -= offset;
		pos[1] -= offset;
		pos[2] += offset;
		break;
	case 10:
		pos[0] += offset;
		pos[1] += offset;
		pos[2] -= offset;
		break;
	case 11:
		pos[0] -= offset;
		pos[1] += offset;
		pos[2] -= offset;
		break;
	case 12:
		pos[0] += offset;
		pos[1] -= offset;
		pos[2] -= offset;
		break;
	case 13:
		pos[0] -= offset;
		pos[1] -= offset;
		pos[2] -= offset;
	}

	rgb = newRgb;
}