コード例 #1
0
//Perform per frame updates
void UpdateFrame()
{
	window.Update();
	camera.Update();

	//Change object type
	if(window.isKeyPressed(' '))
	{
		++objectType;
		if(objectType==3)
			objectType=0;

		window.SetKeyReleased(' ');
	}

	//Change render path
	if(window.isKeyPressed('1') && renderPath!=CHROMATIC_SINGLE && pathOneSupported)
	{
		renderPath=CHROMATIC_SINGLE;
		InitChromaticSingleStates();
	}
	
	if(window.isKeyPressed('2') && renderPath!=SIMPLE_SINGLE)
	{
		renderPath=SIMPLE_SINGLE;
		InitSimpleSingleStates();
	}

	if(window.isKeyPressed('3') && renderPath!=CHROMATIC_TWIN)
	{
		renderPath=CHROMATIC_TWIN;
		//Set States every pass, as it is a 2 pass algorithm
	}
}
コード例 #2
0
//Perform per frame updates
void UpdateFrame()
{
    window.Update();
    camera.Update();

    //Update the light's position
    lightPosition+=lightMovement;

    //reflect the velocity if necessary
    if(lightPosition.x>0.9f || lightPosition.x<-0.9f)
        lightMovement.x=-lightMovement.x;

    if(lightPosition.y>0.9f || lightPosition.y<-0.9f)
        lightMovement.y=-lightMovement.y;

    if(lightPosition.z>0.9f || lightPosition.z<-0.9f)
        lightMovement.z=-lightMovement.z;

    if(window.isKeyPressed('1') && codePath!=TEXTURE_ATTEN)
    {
        codePath=TEXTURE_ATTEN;
        SetTextureAttenStates();
    }

    if(	window.isKeyPressed('2') && codePath!=PASS_THROUGH_ATTEN &&
            NV_texture_shader_supported)
    {
        codePath=PASS_THROUGH_ATTEN;
        SetPassThroughAttenStates();
    }

    if(	window.isKeyPressed('3') && codePath!=TEXTURE_3D_ATTEN &&
            EXT_texture3D_supported)
    {
        codePath=TEXTURE_3D_ATTEN;
        SetTexture3DAttenStates();
    }

    if( window.isKeyPressed('4') && codePath!=GAUSSIAN_ATTEN)
    {
        codePath=GAUSSIAN_ATTEN;
        SetGaussianAttenStates();
    }

    if(	window.isKeyPressed(' '))
    {
        currentLightColor++;
        if(currentLightColor==4)
            currentLightColor=0;

        window.SetKeyReleased(' ');
    }
}
コード例 #3
0
//Perform per frame updates
void UpdateFrame()
{
	window.Update();
	camera.Update();

	//Change anisotropy level
	if(	window.isKeyPressed(VK_UP) && EXT_texture_filter_anisotropic_supported &&
		currentAnisotropy<maxAnisotropy)
	{
		window.MakeCurrent();
		currentAnisotropy*=2;
		glBindTexture(GL_TEXTURE_2D, pbufferTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy);
		window.SetKeyReleased(VK_UP);
	}
	
	if(	window.isKeyPressed(VK_DOWN) && EXT_texture_filter_anisotropic_supported &&
		currentAnisotropy>1)
	{
		window.MakeCurrent();
		currentAnisotropy/=2;
		glBindTexture(GL_TEXTURE_2D, pbufferTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy);
		window.SetKeyReleased(VK_DOWN);
	}

	//toggle mipmaps
	if( window.isKeyPressed('M') && useMipmapFilter==false && SGIS_generate_mipmap_supported)
	{
		window.MakeCurrent();
		glBindTexture(GL_TEXTURE_2D, pbufferTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true);
		useMipmapFilter=true;
	}

	if( window.isKeyPressed('L') && useMipmapFilter==true && SGIS_generate_mipmap_supported)
	{
		window.MakeCurrent();
		glBindTexture(GL_TEXTURE_2D, pbufferTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, false);
		useMipmapFilter=false;
	}

	//Pause/unpause
	if(window.isKeyPressed('P'))
		timer.Pause();

	if(window.isKeyPressed('U'))
		timer.Unpause();

	//Swap between scenes in the pbuffer
	if(window.isKeyPressed('1') && drawTextured)
	{
		//Draw wire tori
		drawTextured=false;
	}

	if(window.isKeyPressed('2') && !drawTextured)
	{
		//draw textured sphere
		drawTextured=true;
	}
}
コード例 #4
0
//Perform per frame updates
void UpdateFrame()
{
	window.Update();

	//update balls' position
	float c = 2.0f*(float)cos(timer.GetTime()/600);
  
	metaballs[0].position.x=-4.0f*(float)cos(timer.GetTime()/700) - c;
	metaballs[0].position.y=4.0f*(float)sin(timer.GetTime()/600) - c;

	metaballs[1].position.x=5.0f*(float)sin(timer.GetTime()/400) + c;
	metaballs[1].position.y=5.0f*(float)cos(timer.GetTime()/400) - c;

	metaballs[2].position.x=-5.0f*(float)cos(timer.GetTime()/400) - 0.2f*(float)sin(timer.GetTime()/600);
	metaballs[2].position.y=5.0f*(float)sin(timer.GetTime()/500) - 0.2f*(float)sin(timer.GetTime()/400);
	
	//increase or decrease density
	if(window.isKeyPressed(VK_UP) && gridSize<maxGridSize)
	{
		gridSize++;
		cubeGrid.Init(gridSize);
	}

	if(window.isKeyPressed(VK_DOWN) && gridSize>minGridSize)
	{
		gridSize--;
		cubeGrid.Init(gridSize);
	}

	//pause & unpause
	if(window.isKeyPressed('P'))
	{
		timer.Pause();
	}

	if(window.isKeyPressed('U'))
	{
		timer.Unpause();
	}

	//clear the field
	for(int i=0; i<cubeGrid.numVertices; i++)
	{
		cubeGrid.vertices[i].value=0.0f;
		cubeGrid.vertices[i].normal.LoadZero();
	}
	
	//evaluate the scalar field at each point
	VECTOR3D ballToPoint;
	float squaredRadius;
	VECTOR3D ballPosition;
	float normalScale;
	for(int i=0; i<numMetaballs; i++)
	{
		squaredRadius=metaballs[i].squaredRadius;
		ballPosition=metaballs[i].position;

		//VC++6 standard does not inline functions
		//by inlining these maually, in this performance-critical area,
		//almost a 100% increase in speed is found
		for(int j=0; j<cubeGrid.numVertices; j++)
		{
			//ballToPoint=cubeGrid.vertices[j].position-ballPosition;
			ballToPoint.x=cubeGrid.vertices[j].position.x-ballPosition.x;
			ballToPoint.y=cubeGrid.vertices[j].position.y-ballPosition.y;
			ballToPoint.z=cubeGrid.vertices[j].position.z-ballPosition.z;
			
			//get squared distance from ball to point
			//float squaredDistance=ballToPoint.GetSquaredLength();
			float squaredDistance=	ballToPoint.x*ballToPoint.x +
									ballToPoint.y*ballToPoint.y +
									ballToPoint.z*ballToPoint.z;
			if(squaredDistance==0.0f)
				squaredDistance=0.0001f;

			//value = r^2/d^2
			cubeGrid.vertices[j].value+=squaredRadius/squaredDistance;

			//normal = (r^2 * v)/d^4
			normalScale=squaredRadius/(squaredDistance*squaredDistance);
			//cubeGrid.vertices[j].normal+=ballToPoint*normalScale;
			cubeGrid.vertices[j].normal.x+=ballToPoint.x*normalScale;
			cubeGrid.vertices[j].normal.y+=ballToPoint.y*normalScale;
			cubeGrid.vertices[j].normal.z+=ballToPoint.z*normalScale;
		}
	}

	//toggle wireframe
	if(window.isKeyPressed('W'))
	{
		glPolygonMode(GL_FRONT, GL_LINE);
	}

	if(window.isKeyPressed('F'))
	{
		glPolygonMode(GL_FRONT, GL_FILL);
	}

	//Change color
	if(window.isKeyPressed(VK_SPACE))
	{
		currentDiffuseColor++;
		if(currentDiffuseColor==numDiffuseColors)
			currentDiffuseColor=0;
		glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseColors[currentDiffuseColor]);

		window.SetKeyReleased(VK_SPACE);
	}
}