Exemplo n.º 1
0
// TODO still broken - needs fixing!
void
Camera::rollRotation(float angleX)
{
	// Get our view vector (The direction we are facing)
	V3f vView(mView - mEye);
	float x = vView.getX();
	float y = vView.getY();
	float z = vView.getZ();

	V3f vNewUp;

	// Calculate the sine and cosine of the angle once
	float cosTheta = cos(angleX);
	float sinTheta = sin(angleX);

	// Find the new x position for the new rotated point
	*vNewUp.x = ((cosTheta + (1.0f - cosTheta) * x * x) * vView.getX());
	*vNewUp.x += ((1.0f - cosTheta) * x * y - z * sinTheta)	* mUp.getY();
	*vNewUp.x += ((1.0f - cosTheta) * x * z + y * sinTheta)	* mUp.getZ();

	// Find the new y position for the new rotated point
	*vNewUp.y  = ((1.0f - cosTheta) * x * y + z * sinTheta)	* mUp.getX();
	*vNewUp.y += (cosTheta + (1.0f - cosTheta) * y * y)		* mUp.getY();
	*vNewUp.y += ((1.0f - cosTheta) * y * z - x * sinTheta)	* mUp.getZ();

	// Find the new z position for the new rotated point
	*vNewUp.z  = ((1.0f - cosTheta) * x * z - y * sinTheta)	* mUp.getX();
	*vNewUp.z += ((1.0f - cosTheta) * y * z + x * sinTheta)	* mUp.getY();
	*vNewUp.z += (cosTheta + (1.0f - cosTheta) * z * z)		* mUp.getZ();

	// Now we just add the newly rotated vector to our position to set
	// our new rotated view of our camera.
	mUp = vNewUp;
//	mView = mEye + vNewView;
}
Exemplo n.º 2
0
void Game::Init() 
{
	m_pShaderProgram = new CShaderProgram;
	m_pSphere = new CSphere;
	m_pTimer = new CHighResolutionTimer;

	// This sets the position, viewpoint, and up vector of the synthetic camera
	glm::vec3 vEye(0, 0, 20);
	glm::vec3 vView(0, 0, 0);
	glm::vec3 vUp(0, 1, 0);
	glm::mat4 mViewMatrix = glm::lookAt(vEye, vView, vUp);

	// This creates a view frustum
	glm::mat4 mProjectionMatrix = glm::perspective(45.0f, 1.333f, 1.0f, 150.0f);

	// This sets the background colour
	glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
	glClearDepth(1.0);


	// Load and compile shaders 
	CShader shVertex, shFragment;	
	shVertex.LoadShader("data\\shaders\\shader.vert", GL_VERTEX_SHADER);
	shFragment.LoadShader("data\\shaders\\shader.frag", GL_FRAGMENT_SHADER);

	// Create shader program and add shaders
	m_pShaderProgram->CreateProgram();
	m_pShaderProgram->AddShaderToProgram(&shVertex);
	m_pShaderProgram->AddShaderToProgram(&shFragment);

	// Link and use the program
	m_pShaderProgram->LinkProgram();
	m_pShaderProgram->UseProgram();

	// Set the modeling, viewing, and projection matrices in the shader
	m_pShaderProgram->SetUniform("viewMatrix", mViewMatrix);
	m_pShaderProgram->SetUniform("projectionMatrix", mProjectionMatrix);
	m_pShaderProgram->SetUniform("vlightDirection", glm::normalize(glm::vec3(0.5f, 0.5f, 0.5f)));
	m_pShaderProgram->SetUniform("sampler0", 0);

	m_pSphere->Create("data\\textures\\", "dirtpile01.jpg", 25, 25);  // Texture downloaded from http://www.psionicgames.com/?page_id=26 on 24 Jan 2013

	
	m_pTimer->Start();
}
Exemplo n.º 3
0
void Camera::Update()
{
	glm::vec3 vAxis(0.0f, 1.0f, 0.0f);

	//Rotate the view vector by the horizontal angle around the vertical axis
	glm::vec3 vView(1.0f, 0.0f, 0.0f);
	vView = glm::rotate(vView, Theta, vAxis);
	vView = glm::normalize(vView);

	//Rotate the view vector by the vertical angle around the horizontal axis
	glm::vec3 hAxis = glm::cross(vAxis, vView);
	hAxis = glm::normalize(hAxis);
	vView = glm::rotate(vView, Phi, hAxis);

	target = vView;
	target = glm::normalize(target);

	up = glm::cross(target, hAxis);
	up = glm::normalize(up);

}