Beispiel #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();
}
void SetProjection(float width, float depth, gmtl::Matrix44f &p)
{
	p.set(2.0f / width, 0.0f, 0.0f, 0.0f,
		0.0f, 2.0f / width, 0.0f, 0.0f,
		0.0f, 0.0f, 2.0f / depth, 0.0f,
		0.0f, 0.0f, 0.0f, 1.0f);
}
Beispiel #3
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();
}
Beispiel #4
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();
	
}