1 #ifndef __BSP_H__ 2 #define __BSP_H__ 3 4 #include "SdkSample.h" 5 #include "OgreFileSystemLayer.h" 6 7 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS 8 #include "macUtils.h" 9 #endif 10 11 using namespace Ogre; 12 using namespace OgreBites; 13 14 class _OgreSampleClassExport Sample_BSP : public SdkSample 15 { 16 public: 17 Sample_BSP()18 Sample_BSP() 19 { 20 mInfo["Title"] = "BSP"; 21 mInfo["Description"] = "A demo of the indoor, or BSP (Binary Space Partition) scene manager. " 22 "Also demonstrates how to load BSP maps from Quake 3."; 23 mInfo["Thumbnail"] = "thumb_bsp.png"; 24 mInfo["Category"] = "Geometry"; 25 } 26 testCapabilities(const RenderSystemCapabilities * caps)27 void testCapabilities(const RenderSystemCapabilities* caps) 28 { 29 if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !caps->hasCapability(RSC_FRAGMENT_PROGRAM)) 30 { 31 OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your graphics card does not support vertex or fragment shaders, " 32 "so you cannot run this sample. Sorry!", "Sample_BSP::testCapabilities"); 33 } 34 } 35 getRequiredPlugins()36 StringVector getRequiredPlugins() 37 { 38 StringVector names; 39 names.push_back("Cg Program Manager"); 40 names.push_back("BSP Scene Manager"); 41 return names; 42 } 43 44 protected: 45 locateResources()46 void locateResources() 47 { 48 // load the Quake archive location and map name from a config file 49 ConfigFile cf; 50 cf.load(mFSLayer->getConfigFilePath("quakemap.cfg")); 51 mArchive = cf.getSetting("Archive"); 52 mMap = cf.getSetting("Map"); 53 54 #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS 55 // OS X does not set the working directory relative to the app, 56 // In order to make things portable on OS X we need to provide 57 // the loading with it's own bundle path location 58 if (!Ogre::StringUtil::startsWith(mArchive, "/", false)) // only adjust relative dirs 59 mArchive = Ogre::String(Ogre::macBundlePath() + "/" + mArchive); 60 #endif 61 62 // add the Quake archive to the world resource group 63 ResourceGroupManager::getSingleton().addResourceLocation(mArchive, "Zip", 64 ResourceGroupManager::getSingleton().getWorldResourceGroupName(), true); 65 } 66 createSceneManager()67 void createSceneManager() 68 { 69 mSceneMgr = mRoot->createSceneManager("BspSceneManager"); // the BSP scene manager is required for this sample 70 #ifdef INCLUDE_RTSHADER_SYSTEM 71 mShaderGenerator->addSceneManager(mSceneMgr); 72 #endif 73 if(mOverlaySystem) 74 mSceneMgr->addRenderQueueListener(mOverlaySystem); 75 } 76 loadResources()77 void loadResources() 78 { 79 /* NOTE: The browser initialises everything at the beginning already, so we use a 0 init proportion. 80 If you're not compiling this sample for use with the browser, then leave the init proportion at 0.7. */ 81 mTrayMgr->showLoadingBar(1, 1, 0); 82 83 // associate the world geometry with the world resource group, and then load the group 84 ResourceGroupManager& rgm = ResourceGroupManager::getSingleton(); 85 rgm.linkWorldGeometryToResourceGroup(rgm.getWorldResourceGroupName(), mMap, mSceneMgr); 86 rgm.initialiseResourceGroup(rgm.getWorldResourceGroupName()); 87 rgm.loadResourceGroup(rgm.getWorldResourceGroupName(), false); 88 89 mTrayMgr->hideLoadingBar(); 90 } 91 unloadResources()92 void unloadResources() 93 { 94 // unload the map so we don't interfere with subsequent samples 95 ResourceGroupManager& rgm = ResourceGroupManager::getSingleton(); 96 rgm.unloadResourceGroup(rgm.getWorldResourceGroupName()); 97 rgm.removeResourceLocation(mArchive, ResourceGroupManager::getSingleton().getWorldResourceGroupName()); 98 } 99 setupView()100 void setupView() 101 { 102 SdkSample::setupView(); 103 104 // modify camera for close work 105 mCamera->setNearClipDistance(4); 106 mCamera->setFarClipDistance(4000); 107 108 // set a random player starting point 109 ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true); 110 111 // Quake uses the Z axis as the up axis, so make necessary adjustments 112 mCamera->setFixedYawAxis(true, Vector3::UNIT_Z); 113 mCamera->pitch(Degree(90)); 114 115 mCamera->setPosition(vp.position); 116 mCamera->rotate(vp.orientation); 117 118 mCameraMan->setTopSpeed(350); // make the camera move a bit faster 119 } 120 121 String mArchive; 122 String mMap; 123 }; 124 125 #endif 126