Ejemplo n.º 1
0
void Camera::updateTransform()
{
	// Store the rotation matrix here.
	float matRot[4][4];

	// Determine rotation matrix from quaternion.
	build_rotmatrix(matRot, m_fQuat);

	// Normal camera direction
	Vec3f vDirection(0,0,m_fDolly);
	Vec3f vUpVector(0,1,0);

	// Apply the rotation matrix to determine the camera's new direction.
	Vec3f vNewDirection(
		matRot[0][0] * vDirection[0] + matRot[0][1] * vDirection[1] + matRot[0][2] * vDirection[2],
		matRot[1][0] * vDirection[0] + matRot[1][1] * vDirection[1] + matRot[1][2] * vDirection[2],
		matRot[2][0] * vDirection[0] + matRot[2][1] * vDirection[1] + matRot[2][2] * vDirection[2]
	);

	// Apply the rotation matrix to determine the camera's new up-vector.
	Vec3f vNewUpVector(
		matRot[0][0] * vUpVector[0] + matRot[0][1] * vUpVector[1] + matRot[0][2] * vUpVector[2],
		matRot[1][0] * vUpVector[0] + matRot[1][1] * vUpVector[1] + matRot[1][2] * vUpVector[2],
		matRot[2][0] * vUpVector[0] + matRot[2][1] * vUpVector[1] + matRot[2][2] * vUpVector[2]
	);

	// Update camera.
	m_vPosition = m_vLookAt + vNewDirection;
	m_vUpVector = vNewUpVector;

	// Not dirty anymore
	m_bDirtyTransform = false;
}
Ejemplo n.º 2
0
void Application::HandleRender()
{
	XMFLOAT3 vUpVector(0.0f, 1.0f, 0.0f);
	XMFLOAT3 vCamera, vLookat;

	switch (m_cameraState)
	{
	case CAMERA_MAP:
		vCamera = XMFLOAT3(sin(m_rotationAngle)*m_cameraZ, 2000.0f, cos(m_rotationAngle)*m_cameraZ);
		vLookat = XMFLOAT3(0.0f, 0.0f, 0.0f);
		break;
	case CAMERA_BOID:
		//vCamera = XMFLOAT3(m_birds.at(0)->GetCameraPosition().x, m_birds.at(0)->GetCameraPosition().y, m_birds.at(0)->GetCameraPosition().z);
		//vLookat = XMFLOAT3(m_birds.at(0)->GetFocusPosition().x, m_birds.at(0)->GetFocusPosition().y, m_birds.at(0)->GetFocusPosition().z);
		break;
	}

	XMMATRIX  matView;
	matView = XMMatrixLookAtLH(XMLoadFloat3(&vCamera), XMLoadFloat3(&vLookat), XMLoadFloat3(&vUpVector));

	XMMATRIX matProj;
	matProj = XMMatrixPerspectiveFovLH(float(XM_PI / 4), 2, 1.5f, 5000.0f);

	this->SetViewMatrix(matView);
	this->SetProjectionMatrix(matProj);

	this->EnablePointLight(0, XMFLOAT3(100.0f, 100.f, -100.f), XMFLOAT3(1.f, 1.f, 1.f));
	this->SetLightAttenuation(0, 200.f, 2.f, 2.f, 2.f);
	this->EnableDirectionalLight(1, D3DXVECTOR3(-1.f, -1.f, -1.f), D3DXVECTOR3(0.65f, 0.55f, 0.65f));


	//changes the background colour
	this->Clear(XMFLOAT4(.6f, .6f, .6f, 1.f));

	XMMATRIX  matWorld;
	matWorld = XMMatrixIdentity();
	this->SetWorldMatrix(matWorld);

	m_pHeightMap->Draw();
	
	m_bManager->drawBirds();


}