コード例 #1
0
ファイル: wxOgre.cpp プロジェクト: johnfredcee/meshmixer
void wxOgre::cameraTrackNode(Ogre::SceneNode* target)
{
	static const wxString camCalcPosCaption(wxT("CalcCamPos:X:%08.4f, Y:%08.4f, Z:%08.4f"));
	static const wxString camRealPosCaption(wxT("CalcCamPos:X:%08.4f, Y:%08.4f, Z:%08.4f"));

	// TODO: Position camera somwehere sensible relative to object
	if (target)
	{
		Ogre::LogManager* logMgr = Ogre::LogManager::getSingletonPtr();
		Ogre::Log* log(logMgr->getDefaultLog());
		mTarget = target;
		Ogre::Vector3 size( target->getAttachedObject(0)->getBoundingBox().getSize() );
		Ogre::Vector3 camPos(target->getPosition() + size * 1.2f); 
		setZoomScale(size.length() / 30.0f);
		mCameraNode->setPosition(camPos);
		mCamera->lookAt(target->getPosition());
		mDebugPanelOverlay->show();
		wxString msg(wxString::Format(camCalcPosCaption, camPos.x, camPos.y, camPos.x));
		log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8)));
		Ogre::Vector3 camRealPos(mCamera->getRealPosition());
		msg = wxString(wxString::Format(camCalcPosCaption, camRealPos.x, camRealPos.y, camRealPos.x));
		log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8)));
	} else {
		mTarget = NULL;
	}

}
コード例 #2
0
ファイル: wxOgre.cpp プロジェクト: johnfredcee/meshmixer
void wxOgre::OnMouseMotion(wxMouseEvent& event)
{
	static float speed = 0.0f;
	static bool dragStart = true;
	static const wxString posInfo(wxT("Pos:X:%03d, Y:%03d Change X:%03d Y:%03d"));
	static Ogre::Quaternion startRot(Ogre::Quaternion::IDENTITY);

	Ogre::LogManager* logMgr = Ogre::LogManager::getSingletonPtr();
	Ogre::Log* log(logMgr->getDefaultLog());
	int left, top, width, height;	
	mCamera->getViewport()->getActualDimensions(left, top, width, height);

	wxPoint pos = event.GetPosition();
	wxPoint change = pos - mPrevPos;

	Ogre::Vector2 changeNorm((Ogre::Real) change.x / (Ogre::Real) width,
							 (Ogre::Real) -change.y / (Ogre::Real) height);
	
	if ((!dragStart) && ((!event.Dragging()) || (!event.LeftIsDown()))) {
 			wxString msg(wxT("Drag End"));
			log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8)));
			dragStart = true;
	}

	if(event.Dragging())
	{
		if (event.LeftIsDown())
		{
			if (mTarget) {
				Ogre::Vector3 objectCentre(mTarget == NULL ? Ogre::Vector3::ZERO : mTarget->getPosition());
				if (dragStart) {
					Ogre::Vector3 cam2Object(mCameraNode->getPosition() - objectCentre);
					mDirection =  cam2Object.normalisedCopy();
					mRadius = cam2Object.length();
					mChangePos = Ogre::Vector2::ZERO;
					dragStart = false;					
					wxString msg(wxT("Drag Start"));
					log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8)));
				}  else {
					Ogre::Vector3 across;
					Ogre::Vector3 up;
					Ogre::Vector3 forward;
					mCamera->getRealOrientation().ToAxes(across, up, forward);
					mChangePos += changeNorm;
					Ogre::Quaternion roty(Ogre::Radian(mChangePos.y * Ogre::Math::PI / 12.0f), across);
					Ogre::Quaternion rotx(Ogre::Radian(mChangePos.x * Ogre::Math::PI / 12.0f), up);					
					Ogre::Quaternion rot(roty * rotx);
					rot.normalise();
					mCameraNode->setPosition(objectCentre + ((rot * mDirection) * mRadius));
 					mCamera->lookAt(objectCentre);
				}
			} 
		}
		else if(event.MiddleIsDown())
		{
			int left, top, width, height;
			mCamera->getViewport()->getActualDimensions(left, top, width, height);

			float speed = 1.0f;
			if (event.ShiftDown())
				speed = 0.1f;
			if (event.ControlDown())
				speed = 10.0f;
			float moveX = ((float)-change.x / (float)width) * mZoomScale * speed;
			float moveY = ((float)change.y / (float)height) * mZoomScale * speed;

			Ogre::Vector3 delta(mCamera->getRealOrientation().xAxis() * moveX);
			delta += mCamera->getRealOrientation().yAxis() * moveY;
			mCamera->setPosition(mCamera->getRealPosition() + delta);
		}
	}
	mPrevPos = pos;
}