Tutorial Basic Setup
- New Project -> OGRE SDK Application -> Minimal application
- "프로젝트 속성 -> 구성속성 -> C/C++ -> 일반 -> 추가 포함 디렉터리" 항목에 "$(OGRE_HOME)\samples\include" 을 추가한다.
Ogre Cameras
A Camera is what we use to view the scene that we have created. A Camera is a special object which works somewhat like a SceneNode does.
The Camera object has setPosition, yaw, roll, and pitch functions, and you can attach it to any SceneNode. Just like SceneNodes, a
Camera's position is relative to its parents (it's nice to respect one's elders). For all movement and rotation, you can basically consider a Camera a SceneNode.
One thing about Ogre Cameras that is different from what you may expect is that you should only be using one Camera at a time (for now). That is, we do not create a Camera for viewing one portion of a scene, a second camera for viewing another portion of the scene and then enabling or disabling cameras based on what portion of the scene we want to display. Instead the way to accomplish this is to create SceneNodes which act as "camera holders". These SceneNodes simply sit in the scene and point at what the Camera might want to look at. When it is time to display a portion of the Scene, the Camera simply attaches itself to the appropriate SceneNode. We will revisit this technique in the FrameListener tutorial.
Creating a Camera
{PROJECT_NAME}App::createCamera 멤버 함수에 다음과 같은 코드를 추가한다.
-
카메라를 생성
This creates a Camera with the name "PlayerCam". Note that you can use the
getCamera function of SceneManager to get Cameras based on their name if you decide not to hold a pointer to it.
- mCamera = mSceneMgr->createCamera("PlayerCam");
-
카메라의 위치 및 방향을 설정
The
lookAt function is pretty nifty. You can have the Camera face any position you want to instead of having to yaw, rotate, and pitch your way there. SceneNodes have this function as well, which can make setting Entities facing the right direction much easier in many cases.
- mCamera->setPosition(Vector3(0,10,500));
mCamera->lookAt(Vector3(0,0,0)); // lookAt = yaw + roll + pitch
-
카메라의 클리핑 거리 설정
The clipping distance of a Camera specifies how close or far something can be before you no longer see it.
- mCamera->setNearClipDistance(5);
Ogre Viewports
three of Ogre's constructs: the Camera, the SceneManager, and the RenderWindow.
The SceneManager object creates Cameras to view the scene. You must tell the RenderWindow which Cameras to display on the screen, and what portion of the window to render it in. The area in which you tell the RenderWindow to display the Camera is your Viewport.
Creating the Viewport
{PROJECT_NAME}App::createViewports 멤버 함수에 다음과 같은 코드를 추가한다.
-
뷰포트를 생성
- Viewport* vp = mWindow->addViewport(mCamera);
-
뷰포트의 배경색을 설정
- vp->setBackgroundColour(ColourValue(0, 0, 0));
-
카메라의 종횡비를 설정
- mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));