예제 #1
0
void cameraRotate()
{
	
	elevationRotation.set(
		1, 0, 0, 0,
		0, cos(elevation * -1), (sin(elevation * -1) * -1), 0,
		0, sin(elevation * -1), cos(elevation * -1), 0,
		0, 0, 0, 1);

	azimuthRotation.set(
		cos(azimuth * -1), 0, sin(azimuth * -1), 0,
		0, 1, 0, 0,
		(sin(azimuth * -1) * -1), 0, cos(azimuth * -1), 0,
		0, 0, 0, 1);

	elevationRotation.setState(gmtl::Matrix44f::ORTHOGONAL);

	azimuthRotation.setState(gmtl::Matrix44f::ORTHOGONAL);

	gmtl::transpose(elevationRotation);
	gmtl::transpose(azimuthRotation);
	
	view = viewScale * elevationRotation * azimuthRotation;

	view.setState(gmtl::Matrix44f::FULL);

	glutPostRedisplay();
}
예제 #2
0
void cameraRotate()
{
	elevationRotation.set(
		1, 0, 0, 0,
		0, cos(elevation * -1), (sin(elevation * -1) * -1), 0,
		0, sin(elevation * -1), cos(elevation * -1), 0,
		0, 0, 0, 1);

	azimuthRotation.set(
		cos(azimuth * -1), 0, sin(azimuth * -1), 0,
		0, 1, 0, 0,
		(sin(azimuth * -1) * -1), 0, cos(azimuth * -1), 0,
		0, 0, 0, 1);

	elevationRotation.setState(gmtl::Matrix44f::ORTHOGONAL);

	azimuthRotation.setState(gmtl::Matrix44f::ORTHOGONAL);
	
	if (c_tableCenter)
	{
		cameraTrans = gmtl::makeTrans<gmtl::Matrix44f>(gmtl::Vec3f(0, 0, 0));
	}
	else if (c_cueFollow)
	{
		cameraTrans = gmtl::makeTrans<gmtl::Matrix44f>(sceneGraph[0]->GetPosition());
	}
	
	viewRotation = azimuthRotation * elevationRotation;
	gmtl::invert(viewRotation);

	originalView = cameraTrans * azimuthRotation * elevationRotation * cameraZ;

	view = gmtl::invert(originalView);

	glutPostRedisplay();
}
예제 #3
0
void init()
{

	elevation = azimuth = 0;
	ballRadius = 4.0f;
	ballDiameter = ballRadius * 2.0f;
	hit = c_tableCenter = c_cueFollow = c_cue = bounce = attract = false;
	hitScale = 3.0f;
	drag = 0.1f;
	restitutionBall =  0.0f;
	restitutionWall = 1.0f;
	simStep = 1;

	delta = 1.0f;
	// Enable depth test (visible surface determination)
	glEnable(GL_DEPTH_TEST);

	// OpenGL background color
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	// Load/compile/link shaders and set to use for rendering
	ShaderInfo shaders[] = { { GL_VERTEX_SHADER, "Cube_Vertex_Shader.vert" },
	{ GL_FRAGMENT_SHADER, "Cube_Fragment_Shader.frag" },
	{ GL_NONE, NULL } };

	program = LoadShaders(shaders);
	glUseProgram(program);

	//Get the shader parameter locations for passing data to shaders
	NormalMatrix = glGetUniformLocation(program, "NormalMatrix");
	lightPosition_loc = glGetUniformLocation(program, "lightPosition");
	
	ambientLight_loc = glGetUniformLocation(program, "ambientLight");
	diffuseLight_loc = glGetUniformLocation(program, "diffuseLight");
	specularLight_loc = glGetUniformLocation(program, "specularLight");

	glActiveTexture(GL_TEXTURE0);

	texture_location = glGetUniformLocation(program, "texture_Colors");
	glBindTexture(GL_TEXTURE_2D, texture_location);

	

	gmtl::identity(view);
	gmtl::identity(viewRotation);
	gmtl::identity(cameraTrans);

	lightPosition.set(0.0f, 20.0f, 0.0f);

	nearValue = 1.0f;
	farValue = 1000.0f;
	topValue = screenHeight / screenWidth;
	bottomValue = topValue * -1.0f;
	rightValue = 1.0f;
	leftValue = -1.0f;

	projection.set(
		((2.0f * nearValue) / (rightValue - leftValue)), 0.0f, ((rightValue + leftValue) / (rightValue - leftValue)), 0.0f,
		0.0f, ((2.0f * nearValue) / (topValue - bottomValue)), ((topValue + bottomValue) / (topValue - bottomValue)), 0.0f,
		0.0f, 0.0f, ((-1.0f * (farValue + nearValue)) / (farValue - nearValue)), ((-2.0f*farValue*nearValue)/(farValue-nearValue)),
		0.0f,0.0f,-1.0f,0.0f		
		);

	cameraZFactor = 350.0f;

	cameraZ = gmtl::makeTrans<gmtl::Matrix44f>(gmtl::Vec3f(0.0f,0.0f,cameraZFactor));
	cameraZ.setState(gmtl::Matrix44f::TRANS);
	
	elevation = degreesToRadians(30.0f);
	azimuth = 0.0f;
	
	cameraRotate();

	buildGraph();
	
}
예제 #4
0
void keyboard(unsigned char key, int x, int y)
{
	switch (key) 
	{

		case '1':
			hitScale = 1.0f;
			break;

		case '2':
			hitScale = 2.0f;
			break;

		case '3':
			hitScale = 3.0f;
			break;

		case '4':
			hitScale = 4.0f;
			break;

		case '5':
			hitScale = 5.0f;
			break;

		case '6':
			hitScale = 6.0f;
			break;

		case '7':
			hitScale = 7.0f;
			break;

		case '8':
			hitScale = 8.0f;
			break;

		case '9':
			hitScale = 9.0f;
			break;
			
		case 'f':
			c_cueFollow = true;
			c_cue = c_tableCenter = false;
			break;

		case 'k':
			drag += 0.01f;
			break;

		case 'K':
			drag = max(0.0f,drag - 0.01f);
			break;

		case 'm':
			sceneGraph[0]->mass += 1.0f;
			break;

		case 'M':
			sceneGraph[0]->mass = max(0.0f, sceneGraph[0]->mass - 1.0f);
			break;

		case 'j':
			restitutionBall = min(restitutionBall + 0.01f,1.0f);
			break;

		case 'J':
			restitutionBall = max(0.0f, restitutionBall - 0.01f);
			break;

		case 'n':
			restitutionWall = min(restitutionWall + 0.01f, 1.0f);
			break;

		case 'N':
			restitutionWall = max(0.0f, restitutionWall - 0.01f);
			break;

		

		case 'h':
			delta += max(1.0f, delta + 0.01f);
			break;

		case 'H':
			delta = max(delta - 0.01f, 0.0f);
			break;


		case 'b':
			bounce = (bounce ? false:true);
			break;

		case 'a':
			attract = (attract ? false : true);
			break;

		case 'Z':
			cameraZFactor += 10.f;
			cameraZ = gmtl::makeTrans<gmtl::Matrix44f>(gmtl::Vec3f(0.0f, 0.0f, cameraZFactor));
			cameraZ.setState(gmtl::Matrix44f::TRANS);
			view = cameraTrans * azimuthRotation * elevationRotation * cameraZ;
			gmtl::invert(view);			
			break;

		case 'z':
			cameraZFactor -= 10.f;
			cameraZ = gmtl::makeTrans<gmtl::Matrix44f>(gmtl::Vec3f(0.0f, 0.0f, cameraZFactor));
			cameraZ.setState(gmtl::Matrix44f::TRANS);
			view = cameraTrans * azimuthRotation * elevationRotation * cameraZ;
			gmtl::invert(view);
			break;

		case 033 /* Escape key */:
			exit(EXIT_SUCCESS);
			break;
	}
	
	glutPostRedisplay();
}