示例#1
0
文件: Flux.cpp 项目: packagesdev/flux
void flux::updateWithScene(scene * inScene)
{
	// randomize constants
	if(inScene->randomizationFrequency)
    {
		randomize --;
        
		if(randomize <= 0)
        {
			for(int i=0; i<NUMCONSTS; i++)
				c[i] = myRandf(2.0f) - 1.0f;
                
			int temp = 101 - inScene->randomizationFrequency;
			temp = temp * temp;
			randomize = temp + myRandi(temp);
		}
	}

	// update constants
	for(int i=0; i<NUMCONSTS; i++)
    {
		c[i] += cv[i];
		if(c[i] >= 1.0f){
			c[i] = 1.0f;
			cv[i] = -cv[i];
		}
		if(c[i] <= -1.0f){
			c[i] = -1.0f;
			cv[i] = -cv[i];
		}
	}

	// update all particles in this flux field
	
	for(int i=0; i<inScene->particlesPerFluxCount; i++)
		particles[i].updateWithScene(c,inScene);
}
示例#2
0
void EuphoriaWidget::updateParameters()
{
	srand((unsigned)time(NULL));
	rand(); rand(); rand(); rand(); rand();

    elapsedTime = 0.0f;

    fr[0] = 0.0f;
    fr[1] = 0.0f;
    fr[2] = 0.0f;
    fr[3] = 0.0f;

    lr[0] = 0.0f;
    lr[1] = 0.0f;
    lr[2] = 0.0f;

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);
	glLineWidth(2.0f);

	// Commented out because smooth lines and textures don't mix on my TNT.
	// It's like it rendering in software mode
	glEnable(GL_LINE_SMOOTH);
	//glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

	if(dTexture)
    {
		int whichtex = dTexture;
		if(whichtex == 4)  // random texture
			whichtex = myRandi(3) + 1;
		glEnable(GL_TEXTURE_2D);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		// Initialize texture
		glGenTextures(1, &texName);
		glBindTexture(GL_TEXTURE_2D, texName);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		switch(whichtex){
		case 1:
			gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TEXSIZE, TEXSIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, plasmamap);
			break;
		case 2:
			gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TEXSIZE, TEXSIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, stringymap);
			break;
		case 3:
			gluBuild2DMipmaps(GL_TEXTURE_2D, 1, TEXSIZE, TEXSIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, linesmap);
		}
	} else if ( texName ) {
		glDeleteTextures( 1, &texName );
		texName = 0;
	}

	if(dFeedback)
    {
		feedbacktexsize = int(pow(2.0, dFeedbacksize));
		while(feedbacktexsize > viewport[2] || feedbacktexsize > viewport[3]){
			dFeedbacksize -= 1;
			feedbacktexsize = int(pow(2.0, dFeedbacksize));
		}

		// feedback texture setup
		glEnable(GL_TEXTURE_2D);
		delete [] feedbackmap;
		feedbackmap = new unsigned char[feedbacktexsize*feedbacktexsize*3];
		glGenTextures(1, &feedbacktex);
		glBindTexture(GL_TEXTURE_2D, feedbacktex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, feedbacktexsize, feedbacktexsize, 0, GL_RGB, GL_UNSIGNED_BYTE, feedbackmap);

		// feedback velocity variable setup
		fv[0] = float(dFeedbackspeed) * (myRandf(0.025f) + 0.025f);
		fv[1] = float(dFeedbackspeed) * (myRandf(0.05f) + 0.05f);
		fv[2] = float(dFeedbackspeed) * (myRandf(0.05f) + 0.05f);
		fv[3] = float(dFeedbackspeed) * (myRandf(0.1f) + 0.1f);
		lv[0] = float(dFeedbackspeed) * (myRandf(0.0025f) + 0.0025f);
		lv[1] = float(dFeedbackspeed) * (myRandf(0.0025f) + 0.0025f);
		lv[2] = float(dFeedbackspeed) * (myRandf(0.0025f) + 0.0025f);
	} else if ( feedbacktex ) {
		glDeleteTextures( 1, &feedbacktex );
		feedbacktex = 0;
	}

	// Initialize wisps
    _ec = this;
    delete[] _wisps;
    delete[] _backwisps;
	_wisps     = new wisp[dWisps];
	_backwisps = new wisp[dBackground];
}