コード例 #1
0
	void Impl_CameraController_FirstPerson::UpdateRotating(float dx, float dy)
	{
		using namespace math;

		Matrix44 local = m_pObject->GetLocalTransform();
		Matrix44 parent = MatrixIdentity();
		if(m_pObject->GetParent())
		{
			parent = m_pObject->GetParent()->GetWorldTransform();
		}

		Vector3 axis_x = local.GetRow3(0);
		axis_x.Normalize();
		Vector3 axis_y = parent.GetRow3(1);
		axis_y.Normalize();
		
		Vector3 pos = local.GetRow3(3);

		local.SetRow3(3, Vector3(0, 0, 0));

		float step = D2R(0.1);

		local = local * MatrixRotationAxis(axis_x, dy * step) * MatrixRotationAxis(axis_y, dx * step);
		local.SetRow3(3, pos);
		m_pObject->SetLocalTransform(local);

		m_pCameraData->UpdateCamera();
	}
コード例 #2
0
	void Impl_CameraController_FirstPerson::UpdateMoving(float dt)
	{
		using namespace math;

		Matrix44 local = m_pObject->GetLocalTransform();

		Vector3 pos = local.GetRow3(3);

		Vector3 axis_x = local.GetRow3(0);
		axis_x.Normalize();
		Vector3 axis_y = local.GetRow3(1);
		axis_y.Normalize();
		Vector3 axis_z = local.GetRow3(2);
		axis_z.Normalize();

		float speed = 5.0f;

		float step = speed * dt;

		if(m_forward)
		{
			axis_z *= step;
			pos += axis_z;
		}

		if(m_backward)
		{
			axis_z *= -step;
			pos += axis_z;
		}


		if(m_left)
		{
			axis_x *= -step;
			pos += axis_x;
		}

		if(m_right)
		{
			axis_x *= step;
			pos += axis_x;
		}

		local.SetRow3(3, pos);
		m_pObject->SetLocalTransform(local);

		CorrectPosition();

		m_pCameraData->UpdateCamera();
	}