Пример #1
0
void reViewport::SetViewOrientation(reViewOrientation viewOrientation, const rAlignedBox3& bounding) {
	rVector3 center = bounding.Center();
	float distance = bounding.max.Distance(bounding.min) / 2;
	
	
	recondite::Camera* camera = m_glCanvas->GetCamera();
	rVector3 position;
	rVector3 up = rVector3::UpVector;
	rVector3 target = center;

	switch (viewOrientation) {
	case reViewOrientation::Top: 
		position.Set(center.x, bounding.max.y + distance, center.z);
		up = rVector3::RightVector;
		break;

		case reViewOrientation::Bottom:
			position.Set(center.x, bounding.min.y - distance, center.z);
			up = rVector3::RightVector;
			break;

		case reViewOrientation::Right:
			position.Set(bounding.max.x + distance, center.y, center.z);
			break;

		case reViewOrientation::Left:
			position.Set(bounding.min.x - distance, center.y, center.z);
			break;

		case reViewOrientation::Front:
			position.Set(center.x, center.y, bounding.max.z + distance);
			break;

		case reViewOrientation::Back:
			position.Set(center.x, center.y, bounding.min.z - distance);
			break;

		case reViewOrientation::User: {
			position = bounding.max;
			rVector3 forward = target - position;
			forward.Normalize();
			rVector3 right = forward.Cross(up);
			up = right.Cross(forward);
			break;
		}
	};

	camera->SetPosition(position);
	camera->SetTarget(target);
	camera->SetUp(up);

	if (viewOrientation != reViewOrientation::User)
		m_cameraController.reset(new reCameraOrientationController(viewOrientation, m_glCanvas->GetCamera(), m_component));
	else
		m_cameraController.reset(new reCameraUserController(m_glCanvas->GetCamera(), m_component));
}
Пример #2
0
void reViewport::SetViewOrientation(reViewOrientation viewOrientation, const rAlignedBox3& bounding, bool updateMenu) {
	rVector3 center = bounding.Center();
	float extentLength = bounding.Extent().Length();
	float distance = bounding.max.Distance(bounding.min) / 2;
	
	
	recondite::Camera* camera = m_glCanvas->GetCamera();
	rVector3 position;
	rVector3 up = rVector3::UpVector;
	rVector3 target = center;
	reViewportMenuId menuId = reVIEWPORT_MENU_USER;

	switch (viewOrientation) {
		case reViewOrientation::Top: 
			position.Set(center.x, bounding.max.y + distance, center.z);
			up = rVector3::RightVector;
			menuId = reVIEWPORT_MENU_TOP;
			break;

		case reViewOrientation::Bottom:
			position.Set(center.x, bounding.min.y - distance, center.z);
			up = rVector3::RightVector;
			menuId = reVIEWPORT_MENU_BOTTOM;
			break;

		case reViewOrientation::Right:
			position.Set(bounding.max.x + distance, center.y, center.z);
			menuId = reVIEWPORT_MENU_RIGHT;
			break;

		case reViewOrientation::Left:
			position.Set(bounding.min.x - distance, center.y, center.z);
			menuId = reVIEWPORT_MENU_LEFT;
			break;

		case reViewOrientation::Front:
			position.Set(center.x, center.y, bounding.max.z + distance);
			menuId = reVIEWPORT_MENU_FRONT;
			break;

		case reViewOrientation::Back:
			position.Set(center.x, center.y, bounding.min.z - distance);
			menuId = reVIEWPORT_MENU_BACK;
			break;

		case reViewOrientation::User: {
			position = bounding.max;
			rVector3 forward = target - position;
			forward.Normalize();
			rVector3 right = forward.Cross(up);
			up = rVector3::UpVector;

			menuId = reVIEWPORT_MENU_USER;
			break;
		}
	};

	camera->SetPosition(position);
	camera->SetTarget(target);
	camera->SetUp(up);

	camera->SetWidth(extentLength);
	camera->SetHeight(extentLength);

	if (viewOrientation != reViewOrientation::User)
		m_cameraController.reset(new reCameraOrientationController(viewOrientation, m_glCanvas->GetCamera(), m_component));
	else
		m_cameraController.reset(new reCameraUserController(m_glCanvas->GetCamera(), m_component));

	if (updateMenu) {
		m_viewMenu.FindItem(menuId)->Check(true);
	}

	Refresh();
}