Пример #1
0
 void Object3D::set_look_at(const Object3DPtr &theLookAt)
 {
     set_look_at(-theLookAt->position() + position(), theLookAt->up());
 }
Пример #2
0
		void bc_free_camera::update(core_platform::bc_clock::update_param p_clock_update_param,
			const platform::bc_pointing_device& p_pointing_device,
			const platform::bc_key_device& p_key_device)
		{
			core::bc_vector3f l_position = get_position();
			bcFLOAT l_move_speed = m_shift_pressed ? m_move_speed * 6 : m_ctrl_pressed ? m_move_speed * 0.25 : m_move_speed;
			bcFLOAT l_rotate_speed = m_rotate_speed;

			l_move_speed *= p_clock_update_param.m_elapsed_second;
			l_rotate_speed *= p_clock_update_param.m_elapsed_second;

			if (m_w_pressed)
			{
				l_position += get_forward() * l_move_speed;
			}
			if (m_s_pressed)
			{
				l_position += get_back() * l_move_speed;
			}
			if (m_a_pressed)
			{
				l_position += get_left() * l_move_speed;
			}
			if (m_d_pressed)
			{
				l_position += get_right() * l_move_speed;
			}
			if (m_e_pressed)
			{
				l_position += get_down() * l_move_speed;
			}
			if (m_q_pressed)
			{
				l_position += get_up() * l_move_speed;
			}

			core::bc_vector3f l_direction = get_direction();

			if (m_rmb_pressed)
			{
				bcFLOAT l_pi = 3.14159265358979323846 / 2;
				auto l_dx = -m_dx * l_rotate_speed;
				auto l_dy = m_dy * l_rotate_speed;

				if (m_dy > l_pi)
				{
					m_dy = l_pi;
				}
				if (m_dy < -l_pi)
				{
					m_dy = -l_pi;
				}

				core::bc_matrix3f l_rotation_y;
				core::bc_matrix3f l_rotation_x;
				core::bc_matrix3f l_rotation;

				core::bc_vector3f l_right = get_right();
				core::bc_vector3f l_up = get_up();

				if(graphic::bc_render_api_info::is_left_handed())
				{
					l_rotation_y.rotation_euler_lh(l_up, -l_dx);
					l_rotation_x.rotation_euler_lh(l_right, l_dy);
				}
				else
				{
					l_rotation_y.rotation_euler_rh(l_up, -l_dx);
					l_rotation_x.rotation_euler_rh(l_right, l_dy);
				}
				l_rotation = l_rotation_y * l_rotation_x;

				l_direction = l_rotation * l_direction;
				l_direction.normalize();
			}

			auto l_lookat = l_position + l_direction;

			set_look_at(l_position, l_lookat, core::bc_vector3f(0, 1, 0));

			m_dx = 0;
			m_dy = 0;
		}