270 likes | 474 Views
OGRE First Steps. Instructor: Dmitri A. Gusev. Spring 2012 CSCI 340: Game Programming Lecture 3, January, 2012. Reading. Felix Kerger , Ogre 3D 1.7 Beginner’s Guide , Packt Publishing, 2010: Chapter 1, “Installing Ogre 3D ” Chapter 2, “The Ogre Scene Graph”
E N D
OGRE First Steps Instructor: Dmitri A. Gusev Spring 2012 CSCI 340: Game Programming Lecture 3, January, 2012
Reading • Felix Kerger, Ogre 3D 1.7 Beginner’s Guide, Packt Publishing, 2010: • Chapter 1, “Installing Ogre 3D” • Chapter 2, “The Ogre Scene Graph” • http://www.ogre3d.org/tikiwiki/Installing+the+Ogre+SDK • How to compile samples for Ogre v. 1.7.3 SDK (Solution) http://www.ogre3d.org/forums/viewtopic.php?f=2&t=68402 • http://www.ogre3d.org/tikiwiki/Building+Ogre (optional) • http://www.ogre3d.org/tikiwiki/SceneManagersFAQ • Basic Tutorial 1, http://www.ogre3d.org/tikiwiki/Basic+Tutorial+1&structure=Tutorials
Compiling QuickStart • Having compiled OGRE from source and/or installed it (as an SDK), add the OGRE_HOME path by setting an environment variable:
Compiling QuickStart (cont’d) • Open QuickStart.sln in Microsoft Visual Studio 2010 and convert the project to a modern format if the need be.
Compiling QuickStart (cont’d) • In main.cpp, make sure that the catch clause is as follows:
Compiling QuickStart (cont’d) • Under Project→Properties→ConfigurationProperties→Debugging, make sure that Working Directory is set properly.
Compiling QuickStart (cont’d) • Under Project→Properties→ConfigurationProperties→C/C++, make sure that Include Directories are set properly, so that Ogre.hand Boost can be found.
Compiling QuickStart (cont’d) • Under Project→Properties→ConfigurationProperties→Linker→Input, make sure that Additional Dependencies are set properly, so that OgreMain_d.lib and Boost can be found. Build Solution (F7).
Running QuickStart Make sure that plugins.cfg is in your working directory! Clone plugins_d.cfg if needed. → The OGRE Render Window will close after 15 sec. Challenge: See if you can modify main.cpp so that the Rendering Setup window appears on every run, and not just the first time around.
Compiling and Running Manual • The process is similar to compiling and running QuickStart • Some peculiarities: • #include "OgreTimer.h" … Ogre::Timer* timer = new Ogre::Timer(); ... delete timer; • add _d to all plugin names for the Debug mode • constRenderSystemList *rList = &(root->getAvailableRenderers()); // for type matching RenderSystemList::const_iterator it; it = rList->begin(); • RenderWindow *window = root->createRenderWindow( // Changed rSys to root! • // accumulate total elapsed time s = (float)timer->getMilliseconds() / 1000.0f; // use = instead of +=
Ogre Log • The log output that Ogre generates contains: • all events • system initialization • state and capabilities information from each run • You are required to have an Ogre log file! • Creating a LogManager: // create an instance of LogManager prior to using LogManager::getSingleton() LogManager* logMgr = newLogManager; Log *log = LogManager::getSingleton().createLog("mylog.log",true,true,false); // third param is not used since we have already created a log in the previous step Root *root = new Root("", "");
Embedding the Ogre Render Window • Ogre’s NameValuePairList class is a typedef of the STL map class // hWnd is a handle to an existing Win32 window // renderSystem points to an existing, initialized instance of D3D9RenderSystem NameValuePairList opts; opts["parentWindowHandle"] = StringConverter::toString(hWnd); // Everything but "opts" is somewhat irrelevant in the context of // an explicitly parented window RenderWindow *window = renderSystem->createRenderWindow( "WindowName", 800, 600, false, &opts); • This code will allow you to embed the Ogre render window in an existing window of your choice
Types of Scene Manager • A scene is an abstract representation of what is shown in a virtual world. Scenes may consist of • static geometry such as terrain or building interiors, • models such as trees, chairs or monsters, • light sources that illuminate the scene, and • cameras that view the scene. • A SceneManager instance is created like this: SceneManager *sceneMgr = root->createSceneManager(ST_GENERIC); • Types of scene manager: • ST_GENERIC — Generic scene manager (Octree if you load Plugin_OctreeSceneManager, DotScene if you load Plugin_DotSceneManager); Most useful for minimally complex scenes • ST_INTERIOR — BSP scene manager; Optimized for rendering interior • ST_EXTERIOR_CLOSE — Terrain Scene Manager; Optimized for rendering outdoor scenes with near-to-medium visibility, such as those based on tiled single-page terrain mesh or heightfield • ST_EXTERIOR_REAL_FAR - Paging Scene Manager; Typically suited for paged landscape, such as a planet
Camera • A camera “takes a picture” of your scene each frame, from a particular vantage point • A camera has a position and an orientation • If you have one camera in the field of view of another, the camera object will not be rendered • A camera can be either attached to a scene node, or moved around manually
Camera Frustum • A camera has a field of view with near and far clip planes. This geometry defines a frustum, which is a pyramid with its tip chopped off
Setting Up a Camera • You supply: • position, • direction, • the near and far clip distances, • the aspect ratio of the camera (defined as X/Y), • the vertical field-of-view angle W (in radians) between the line of sight and the lower frustum-bounding plane • Example: // Create the camera for mSceneMgr, an existing SceneManager instance mCamera = mSceneMgr->createCamera("PlayerCam"); // Position it at 80 in Z direction mCamera->setPosition(Ogre::Vector3(0,0,80)); // Look back along -Z mCamera->lookAt(Ogre::Vector3(0,0,-300)); // Set near and far clip distances to 5 and 1000 mCamera->setNearClipDistance(5.0f); mCamera->setFarClipDistance(1000.0f); // Set field-of-view Y angle to the radian equivalent of 30 degrees mCamera->setFOVy((Ogre::Radian)30.0f*3.14159265358979f/180.0f);
Compiling OgreTemplate • OgreTemplate is our name for the application found in Basic Tutorial 1, http://www.ogre3d.org/tikiwiki/Basic+Tutorial+1&structure=Tutorials • The process of setting up the application using MS Visual Studio 2010 is described at http://www.ogre3d.org/tikiwiki/Setting+Up+An+Application+-+Visual+Studio&structure=Development?tikiversion=Visual+Studio+2010+-+VC10 • Some discrepancies between the online document referenced above and my actual implementation are covered in the subsequent slides
Compiling OgreTemplate (cont’d) • The view of the project in the Solution Explorer:
Compiling OgreTemplate (cont’d) • Project → Properties → Configuration Properties → General:
Compiling OgreTemplate (cont’d) • Project → Properties → Configuration Properties → Debugging:
Compiling OgreTemplate (cont’d) • Project → Properties → Configuration Properties → C/C++ → General → Additional Include Directories: • include; • "$(OGRE_HOME)\include"; • "$(OGRE_HOME)\Dependencies\include\OIS"; • "$(OGRE_HOME)\Samples\Common\include"; • "$(OGRE_HOME)\boost_1_43_0" • Project → Properties → Configuration Properties → Linker → General → Additional Library Directories: • "$(OGRE_HOME)\lib\$(ConfigurationName)"; • "$(OGRE_HOME)\Dependencies\lib\$(ConfigurationName)"; • "$(OGRE_HOME)\boost_1_43_0\lib" • Project → Properties → Configuration Properties → Linker → Input → Additional Dependencies: • For Debug configuration: OgreMain_d.lib OIS_d.lib • For Release configuration: OgreMain.lib OIS.lib
Running OgreTemplate (cont’d) • Controls: • F — toggle visibility of advanced frame stats • G — toggle visibility of debugging details • T — cycle polygon rendering mode: trilinear, anisotropic, none, bilinear (difference is not noticeable) • R — cycle polygon rendering mode: wireframe, points, solid • W, A, S, D, ↑,←,↓,→ — camera movement: position change • mouse movement — camera movement: orientation change • Esc — exit
Rendering Modes • Wireframe: camera->setPolygonMode(PM_WIREFRAME); • “Points” (only the vertices are rendered): camera->setPolygonMode(PM_POINTS); • Solid (the default): camera->setPolygonMode(PM_SOLID); • Retrieving the current rendering mode value: PolygonMode mode = camera->getPolygonMode();
Camera Movement • void move(const Vector3& vec); // move in world space • void moveRelative(const Vector3& vec); //move in local space • void roll(const Radian& angle); // rotate anticlockwise around // the camera’s local Z axis • void yaw(const Radian& angle); // rotate anticlockwise around // the camera’s local Y axis • void pitch(const Radian& angle); // rotate anticlockwise around // the camera’s local Z axis • void setAutoTracking(bool enabled, SceneNode* target = 0, const Vector3& offset = Vector3::ZERO); // follow a node // turn off tracking before deleting the tracked node!
Viewports • A single Camera instance can drive zero or more Viewport objects • Viewports can overlap • A z-order determines what viewports will render “on top” of other viewports in use • The z-order of zero belongs to the viewport underneath all others • Only one viewport can occupy a given z-order for a render window • Each viewport can have an independent background color • Overlays are rendered by default in all viewports; you can turn off overlay rendering on a per-viewport basis: vpTop->setOverlaysEnabled(false);
Main Rendering Loop • A typical Ogre application renders one frame after another until you tell it to stop • So far, we invoked the main rendering loop by calling Root::startRendering() • Root::startRendering()starts a loop that repeatedly calls another method: renderOneFrame(). • You can implement the main rendering loop “manually” using renderOneFrame(). • If you do that, you can still use FrameListener classes: renderOneFrame() is the method that notifies any registered frame listeners in Root