glm::vec3 Camera::ResolveCamPosition()
{
	float phi = DegToRad(sphereCamRelPos.x);
	float theta = DegToRad(sphereCamRelPos.y + 90.0f);

	float fSinTheta = sinf(theta);
	float fCosTheta = cosf(theta);
	float fCosPhi = cosf(phi);
	float fSinPhi = sinf(phi);

	glm::vec3 dirToCamera(fSinTheta * fCosPhi, fCosTheta, fSinTheta * fSinPhi);
	return (dirToCamera * sphereCamRelPos.z) + camTarget;
}
glm::vec3 GraphicsSubsystem::resolveCamPosition()
{
	float phi = sphereCamRelPos.x / 180.0f * M_PI;
	float theta = (sphereCamRelPos.y) / 180.0f * M_PI;

	float fSinTheta = sinf(theta);
	float fCosTheta = cosf(theta);
	float fCosPhi = cosf(phi);
	float fSinPhi = sinf(phi);

	glm::vec3 dirToCamera(fSinTheta * fCosPhi, fCosTheta, fSinTheta * fSinPhi);
	viewVector = glm::normalize(-dirToCamera);
	return (dirToCamera * sphereCamRelPos.z) + camTarget;
}
glm::vec3 ResolveCamPosition()
{
	glutil::MatrixStack tempMat;

	float phi = Framework::DegToRad(g_sphereCamRelPos.x);
	float theta = Framework::DegToRad(g_sphereCamRelPos.y + 90.0f);

	float fSinTheta = sinf(theta);
	float fCosTheta = cosf(theta);
	float fCosPhi = cosf(phi);
	float fSinPhi = sinf(phi);

	glm::vec3 dirToCamera(fSinTheta * fCosPhi, fCosTheta, fSinTheta * fSinPhi);
	return (dirToCamera * g_sphereCamRelPos.z) + g_camTarget;
}
glm::vec3 ResolveCamPosition()
{
    glutil::MatrixStack tempMat;

    float phi = DegToRad(sphereCamRelPos.x);
    float theta = DegToRad(sphereCamRelPos.y + 90.0f);

    float sinTheta = sinf(theta);
    float cosTheta = cosf(theta);
    float cosPhi = cosf(phi);
    float sinPhi = sinf(phi);

    glm::vec3 dirToCamera(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi);
    return (dirToCamera * sphereCamRelPos.z) + camTarget;
}
示例#5
0
void TPCamera::Move(float msec) {
		sphereRelativePosition.x	  -=(Window::GetMouse()->GetRelativePosition().x);
		sphereRelativePosition.y	  -=(Window::GetMouse()->GetRelativePosition().y);

		//pitch = min(pitch,90.f);
		//pitch = max(pitch,-90.0f);

		//pitch = -sphereRelativePosition.y;
		//yaw = -sphereRelativePosition.x;
		
		sphereRelativePosition.y = min(sphereRelativePosition.y,90.f);
		sphereRelativePosition.y = max(sphereRelativePosition.y,-90.0f);

		/*
		if(yaw<0)	{
			yaw+=360.0f;
		}
		if(yaw>360.0)	{
			yaw-=360.0f;
		}
		*/

		if(sphereRelativePosition.x>360.0f)	{
			sphereRelativePosition.x-=360.0f;
		}

		if(sphereRelativePosition.x<0)	{
			sphereRelativePosition.x+=360.0f;
		}


		if(Window::GetKeyboard()->KeyDown(KEYBOARD_W))	{
			lookAt += Matrix4::Rotation(yaw,Vector3(0.0f,1.0f,0.0f)) *
					Vector3(0.0f,0.0f,-1.0f) * msec;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_S))	{
			lookAt -= Matrix4::Rotation(yaw,Vector3(0.0f,1.0f,0.0)) *
					Vector3(0.0f,0.0f,-1.0f) * msec;
		}


		if(Window::GetKeyboard()->KeyDown(KEYBOARD_A))	{
			lookAt += Matrix4::Rotation(yaw,Vector3(0.0f,1.0f,0.0f)) *
					Vector3(-1.0f,0.0f,0.0f) * msec;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_D))	{
			lookAt -= Matrix4::Rotation(yaw,Vector3(0.0f,1.0f,0.0)) *
						Vector3(-1.0f,0.0f,0.0f) * msec;
		}



		if(Window::GetKeyboard()->KeyDown(KEYBOARD_Z))	{
			roll+=1.0f;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_X))	{
			roll-=1.0f;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_SHIFT))	{
			lookAt.y +=msec;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_SPACE))	{
			lookAt.y -=msec;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_Q))	{
			sphereRelativePosition.z += 1.0f;
		}

		if(Window::GetKeyboard()->KeyDown(KEYBOARD_E))	{
			sphereRelativePosition.z -= 1.0f;
		}

		float phi = DegToRad(sphereRelativePosition.x);
		float theta= DegToRad(sphereRelativePosition.y + 90.0f);

		float SinTheta = sin(theta);
		float CosTheta = cos(theta);

		float CosPhi = cos(phi);
		float SinPhi = sin(phi);

		pitch = 0;
		yaw = 0;

		double dx = lookAt.x - position.x;
		double dy = lookAt.y - position.y;
		double dz = lookAt.z - position.z;


		float test;

		if(dx!=0) {
			if(dx < 0) {
				yaw = 1.5f * PI;
			} else
			{
				yaw = 0.5f * PI;
			}
			
			yaw+= atan(dz /dx);
		} else if(dz < 0) {
			yaw = PI;
		}
		double dxz;
		if (dx==0 || dz == 0 ) {
			dxz = 0;
			pitch = PI * 0.5f;
		}
		else {
			dxz = sqrt(( dx * dx) + (dz * dz));
			pitch = (float)-atan(dy / dxz);
			test = (float)-atan(dy / dxz);

		}

		pitch *= -180.0f / PI;
		yaw   *= -180.0f / PI;
	

		Vector3 dirToCamera(SinTheta * CosPhi, CosTheta, SinTheta * SinPhi);
		position = (dirToCamera * sphereRelativePosition.z) + lookAt;


}