00001 /*------------------------------------------------------------------------- 00002 This source file is a part of OGRE 00003 (Object-oriented Graphics Rendering Engine) 00004 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This library is free software; you can redistribute it and/or modify it 00011 under the terms of the GNU Lesser General Public License (LGPL) as 00012 published by the Free Software Foundation; either version 2.1 of the 00013 License, or (at your option) any later version. 00014 00015 This library is distributed in the hope that it will be useful, but 00016 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00017 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00018 License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with this library; if not, write to the Free Software Foundation, 00022 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or go to 00023 http://www.gnu.org/copyleft/lesser.txt 00024 -------------------------------------------------------------------------*/ 00025 #ifndef __SceneManager_H__ 00026 #define __SceneManager_H__ 00027 00028 // Precompiler options 00029 #include "OgrePrerequisites.h" 00030 00031 #include "OgreString.h" 00032 #include "OgreSceneNode.h" 00033 #include "OgrePlane.h" 00034 #include "OgreQuaternion.h" 00035 #include "OgreColourValue.h" 00036 #include "OgreCommon.h" 00037 #include "OgreRenderQueue.h" 00038 #include "OgreDataChunk.h" 00039 #include "OgreAnimationState.h" 00040 #include "OgreSceneQuery.h" 00041 #include "OgreAutoParamDataSource.h" 00042 #include "OgreAnimationState.h" 00043 #include "OgreRenderQueue.h" 00044 #include "OgreRenderQueueSortingGrouping.h" 00045 #include "OgreRectangle2D.h" 00046 00047 namespace Ogre { 00048 00050 struct ViewPoint 00051 { 00052 Vector3 position; 00053 Quaternion orientation; 00054 }; 00055 00056 // Forward declarations 00057 class DefaultIntersectionSceneQuery; 00058 class DefaultRaySceneQuery; 00059 class DefaultSphereSceneQuery; 00060 class DefaultAxisAlignedBoxSceneQuery; 00061 00077 class _OgreExport SceneManager 00078 { 00079 friend class DefaultIntersectionSceneQuery; 00080 friend class DefaultRaySceneQuery; 00081 friend class DefaultSphereSceneQuery; 00082 friend class DefaultAxisAlignedBoxSceneQuery; 00083 friend class DefaultPlaneBoundedVolumeListSceneQuery; 00084 public: 00087 struct materialLess 00088 { 00089 _OgreExport bool operator()(const Material* x, const Material* y) const; 00090 }; 00092 struct lightLess 00093 { 00094 _OgreExport bool operator()(const Light* a, const Light* b) const; 00095 }; 00096 00098 enum IlluminationRenderStage 00099 { 00101 IRS_NONE, 00103 IRS_AMBIENT, 00105 IRS_PER_LIGHT, 00107 IRS_DECAL, 00109 IRS_RENDER_TO_TEXTURE, 00111 IRS_RENDER_MODULATIVE_PASS 00112 }; 00113 00114 protected: 00115 00117 RenderQueue* mRenderQueue; 00118 00120 ColourValue mAmbientLight; 00121 00123 RenderSystem *mDestRenderSystem; 00124 00125 typedef std::map<std::string, Camera*, std::less<std::string> > CameraList; 00126 00129 CameraList mCameras; 00130 00131 typedef std::map<std::string, Light*, std::less<std::string> > SceneLightList; 00132 00135 SceneLightList mLights; 00136 00137 00138 typedef std::map<std::string, Entity*, std::less<std::string> > EntityList; 00139 00142 EntityList mEntities; 00143 00144 typedef std::map<std::string, BillboardSet*, std::less<std::string> > BillboardSetList; 00145 00148 BillboardSetList mBillboardSets; 00149 00150 typedef std::map<String, SceneNode*> SceneNodeList; 00151 00158 SceneNodeList mSceneNodes; 00159 00161 Camera* mCameraInProgress; 00163 Viewport* mCurrentViewport; 00164 00166 SceneNode* mSceneRoot; 00167 00169 typedef std::set<SceneNode*> AutoTrackingSceneNodes; 00170 AutoTrackingSceneNodes mAutoTrackingSceneNodes; 00171 00172 // Sky params 00173 // Sky plane 00174 Entity* mSkyPlaneEntity; 00175 Entity* mSkyDomeEntity[5]; 00176 Entity* mSkyBoxEntity[6]; 00177 00178 SceneNode* mSkyPlaneNode; 00179 SceneNode* mSkyDomeNode; 00180 SceneNode* mSkyBoxNode; 00181 00182 bool mSkyPlaneEnabled; 00183 bool mSkyPlaneDrawFirst; 00184 Plane mSkyPlane; 00185 // Sky box 00186 bool mSkyBoxEnabled; 00187 bool mSkyBoxDrawFirst; 00188 Quaternion mSkyBoxOrientation; 00189 // Sky dome 00190 bool mSkyDomeEnabled; 00191 bool mSkyDomeDrawFirst; 00192 Quaternion mSkyDomeOrientation; 00193 // Fog 00194 FogMode mFogMode; 00195 ColourValue mFogColour; 00196 Real mFogStart; 00197 Real mFogEnd; 00198 Real mFogDensity; 00199 00204 virtual void initRenderQueue(void); 00206 virtual RenderQueue* getRenderQueue(void); 00214 virtual Pass* setPass(Pass* pass); 00216 Pass* mShadowCasterPlainBlackPass; 00218 Pass* mShadowReceiverPass; 00228 Pass* deriveShadowCasterPass(Pass* pass); 00237 Pass* deriveShadowReceiverPass(Pass* pass); 00238 00245 bool validatePassForRendering(Pass* pass); 00246 00253 bool validateRenderableForRendering(Pass* pass, Renderable* rend); 00254 00255 enum BoxPlane 00256 { 00257 BP_FRONT = 0, 00258 BP_BACK = 1, 00259 BP_LEFT = 2, 00260 BP_RIGHT = 3, 00261 BP_UP = 4, 00262 BP_DOWN = 5 00263 }; 00264 00265 /* Internal utility method for creating the planes of a skybox. 00266 */ 00267 Mesh* createSkyboxPlane( 00268 BoxPlane bp, 00269 Real distance, 00270 const Quaternion& orientation); 00271 00272 /* Internal utility method for creating the planes of a skydome. 00273 */ 00274 Mesh* createSkydomePlane( 00275 BoxPlane bp, 00276 Real curvature, Real tiling, Real distance, 00277 const Quaternion& orientation); 00278 00279 // Flag indicating whether SceneNodes will be rendered as a set of 3 axes 00280 bool mDisplayNodes; 00281 00283 typedef std::map<String, Animation*> AnimationList; 00284 AnimationList mAnimationsList; 00285 AnimationStateSet mAnimationStates; 00286 00289 void useRenderableViewProjMode(Renderable* pRend); 00290 00292 bool mCamChanged; 00293 00294 typedef std::vector<RenderQueueListener*> RenderQueueListenerList; 00295 RenderQueueListenerList mRenderQueueListeners; 00296 00298 bool fireRenderQueueStarted(RenderQueueGroupID id); 00300 bool fireRenderQueueEnded(RenderQueueGroupID id); 00301 00303 virtual void setViewport(Viewport *vp); 00304 00306 bool mShowBoundingBoxes; 00307 00320 virtual void renderSingleObject(Renderable* rend, Pass* pass, bool doLightIteration, 00321 const LightList* manualLightList = 0); 00322 00324 AutoParamDataSource mAutoParamDataSource; 00325 00326 ShadowTechnique mShadowTechnique; 00327 bool mDebugShadows; 00328 ColourValue mShadowColour; 00329 Pass* mShadowDebugPass; 00330 Pass* mShadowStencilPass; 00331 Pass* mShadowModulativePass; 00332 LightList mLightsAffectingFrustum; 00333 HardwareIndexBufferSharedPtr mShadowIndexBuffer; 00334 size_t mShadowIndexBufferSize; 00335 Rectangle2D* mFullScreenQuad; 00336 Real mShadowDirLightExtrudeDist; 00337 IlluminationRenderStage mIlluminationStage; 00338 unsigned short mShadowTextureSize; 00339 unsigned short mShadowTextureCount; 00340 typedef std::vector<RenderTexture*> ShadowTextureList; 00341 ShadowTextureList mShadowTextures; 00342 RenderTexture* mCurrentShadowTexture; 00343 bool mShadowUseInfiniteFarPlane; 00350 virtual void findLightsAffectingFrustum(const Camera* camera); 00352 virtual void initShadowVolumeMaterials(void); 00354 virtual void createShadowTextures(unsigned short size, unsigned short count); 00356 virtual void prepareShadowTextures(Camera* cam, Viewport* vp); 00357 00363 virtual void renderShadowVolumesToStencil(const Light* light, const Camera* cam); 00369 virtual void setShadowVolumeStencilState(bool secondpass, bool zfail, bool twosided); 00371 void renderSingleShadowVolumeToStencil(ShadowRenderable* sr, bool zfail, bool stencil2sided, 00372 const LightList* manualLightList); 00373 typedef std::vector<ShadowCaster*> ShadowCasterList; 00374 ShadowCasterList mShadowCasterList; 00375 SphereSceneQuery* mShadowCasterSphereQuery; 00376 AxisAlignedBoxSceneQuery* mShadowCasterAABBQuery; 00377 Real mShadowFarDist; 00378 Real mShadowFarDistSquared; 00379 Real mShadowTextureOffset; // proportion of texture offset in view direction e.g. 0.4 00380 Real mShadowTextureFadeStart; // as a proportion e.g. 0.6 00381 Real mShadowTextureFadeEnd; // as a proportion e.g. 0.9 00382 GpuProgramParametersSharedPtr mInfiniteExtrusionParams; 00383 GpuProgramParametersSharedPtr mFiniteExtrusionParams; 00384 00386 class _OgreExport ShadowCasterSceneQueryListener : public SceneQueryListener 00387 { 00388 protected: 00389 ShadowCasterList* mCasterList; 00390 bool mIsLightInFrustum; 00391 const PlaneBoundedVolumeList* mLightClipVolumeList; 00392 const Camera* mCamera; 00393 const Light* mLight; 00394 Real mFarDistSquared; 00395 public: 00396 ShadowCasterSceneQueryListener() : mCasterList(0), 00397 mIsLightInFrustum(false), mLightClipVolumeList(0), 00398 mCamera(0) {} 00399 // Prepare the listener for use with a set of parameters 00400 void prepare(bool lightInFrustum, 00401 const PlaneBoundedVolumeList* lightClipVolumes, 00402 const Light* light, const Camera* cam, ShadowCasterList* casterList, 00403 Real farDistSquared) 00404 { 00405 mCasterList = casterList; 00406 mIsLightInFrustum = lightInFrustum; 00407 mLightClipVolumeList = lightClipVolumes; 00408 mCamera = cam; 00409 mLight = light; 00410 mFarDistSquared = farDistSquared; 00411 } 00412 bool queryResult(MovableObject* object); 00413 bool queryResult(SceneQuery::WorldFragment* fragment); 00414 }; 00415 00416 ShadowCasterSceneQueryListener mShadowCasterQueryListener; 00417 00424 virtual const ShadowCasterList& findShadowCastersForLight(const Light* light, 00425 const Camera* camera); 00428 virtual void renderQueueGroupObjects(RenderQueueGroup* group); 00430 virtual void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup); 00432 virtual void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* group); 00434 virtual void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* group); 00436 virtual void renderTextureShadowCasterQueueGroupObjects(RenderQueueGroup* group); 00438 virtual void renderTextureShadowReceiverQueueGroupObjects(RenderQueueGroup* group); 00440 virtual void renderModulativeTextureShadowedQueueGroupObjects(RenderQueueGroup* group); 00442 virtual void renderObjects(const RenderPriorityGroup::SolidRenderablePassMap& objs, 00443 bool doLightIteration, const LightList* manualLightList = 0); 00445 virtual void renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs, 00446 bool doLightIteration, const LightList* manualLightList = 0); 00447 00448 public: 00451 SceneManager(); 00452 00455 virtual ~SceneManager(); 00456 00464 virtual Camera* createCamera(const String& name); 00465 00468 virtual Camera* getCamera(const String& name); 00469 00478 virtual void removeCamera(Camera *cam); 00479 00485 virtual void removeCamera(const String& name); 00486 00489 virtual void removeAllCameras(void); 00490 00501 virtual Light* createLight(const String& name); 00502 00505 virtual Light* getLight(const String& name); 00506 00511 virtual void removeLight(const String& name); 00512 00517 virtual void removeLight(Light* light); 00520 virtual void removeAllLights(void); 00521 00540 virtual void _populateLightList(const Vector3& position, LightList& destList); 00541 00545 virtual Material* createMaterial(const String& name); 00546 00577 virtual Material* getDefaultMaterialSettings(void); 00578 00581 virtual Material* getMaterial(const String& name); 00582 00589 virtual Material* getMaterial(int handle); 00590 00607 virtual SceneNode* createSceneNode(void); 00608 00623 virtual SceneNode* createSceneNode(const String& name); 00624 00631 virtual void destroySceneNode(const String& name); 00632 00648 virtual SceneNode* getRootSceneNode(void) const; 00649 00656 virtual SceneNode* getSceneNode(const String& name) const; 00657 00665 virtual Entity* createEntity(const String& entityName, const String& meshName); 00666 00673 enum PrefabType { 00674 PT_PLANE 00675 }; 00676 00683 virtual Entity* createEntity(const String& entityName, PrefabType ptype); 00685 virtual Entity* getEntity(const String& name); 00686 00695 virtual void removeEntity(Entity* ent); 00696 00705 virtual void removeEntity(const String& name); 00706 00716 virtual void removeAllEntities(void); 00717 00723 virtual void clearScene(void); 00724 00737 void setAmbientLight(const ColourValue& colour); 00738 00741 const ColourValue& getAmbientLight(void) const; 00742 00758 virtual void setWorldGeometry(const String& filename); 00759 00774 virtual ViewPoint getSuggestedViewpoint(bool random = false); 00775 00789 virtual bool setOption( const String& strKey, const void* pValue ) { return false; } 00790 00804 virtual bool getOption( const String& strKey, void* pDestValue ) { return false; } 00805 00815 virtual bool hasOption( const String& strKey ) const { return false; } 00830 virtual bool getOptionValues( const String& strKey, std::list<SDDataChunk>& refValueList ) { return false; } 00831 00838 virtual bool getOptionKeys( std::list<String>& refKeys ) { return false; } 00839 00848 virtual void _updateSceneGraph(Camera* cam); 00849 00861 virtual void _findVisibleObjects(Camera* cam, bool onlyShadowCasters); 00862 00867 virtual void _applySceneAnimations(void); 00868 00871 virtual void _renderVisibleObjects(void); 00872 00886 virtual void _renderScene(Camera* camera, Viewport* vp, bool includeOverlays); 00887 00891 virtual void _queueSkiesForRendering(Camera* cam); 00892 00893 00894 00903 virtual void _setDestinationRenderSystem(RenderSystem* sys); 00904 00951 virtual void setSkyPlane( 00952 bool enable, 00953 const Plane& plane, const String& materialName, Real scale = 1000, 00954 Real tiling = 10, bool drawFirst = true, Real bow = 0 ); 00955 00995 virtual void setSkyBox( 00996 bool enable, const String& materialName, Real distance = 5000, 00997 bool drawFirst = true, const Quaternion& orientation = Quaternion::IDENTITY ); 00998 01052 virtual void setSkyDome( 01053 bool enable, const String& materialName, Real curvature = 10, 01054 Real tiling = 8, Real distance = 4000, bool drawFirst = true, 01055 const Quaternion& orientation = Quaternion::IDENTITY); 01056 01081 void setFog( 01082 FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, 01083 Real expDensity = 0.001, Real linearStart = 0.0, Real linearEnd = 1.0); 01084 01087 virtual FogMode getFogMode(void) const; 01088 01091 virtual const ColourValue& getFogColour(void) const; 01092 01095 virtual Real getFogStart(void) const; 01096 01099 virtual Real getFogEnd(void) const; 01100 01103 virtual Real getFogDensity(void) const; 01104 01105 01123 virtual BillboardSet* createBillboardSet(const String& name, unsigned int poolSize = 20); 01124 01127 virtual BillboardSet* getBillboardSet(const String& name); 01128 01135 virtual void removeBillboardSet(BillboardSet* set); 01136 01143 virtual void removeBillboardSet(const String& name); 01144 01154 virtual void removeAllBillboardSets(void); 01155 01163 virtual void setDisplaySceneNodes(bool display); 01164 01185 virtual Animation* createAnimation(const String& name, Real length); 01186 01188 virtual Animation* getAnimation(const String& name) const; 01189 01195 virtual void destroyAnimation(const String& name); 01196 01198 virtual void destroyAllAnimations(void); 01199 01223 virtual AnimationState* createAnimationState(const String& animName); 01224 01226 virtual AnimationState* getAnimationState(const String& animName); 01227 01233 virtual void destroyAnimationState(const String& name); 01234 01236 virtual void destroyAllAnimationStates(void); 01237 01261 virtual void manualRender(RenderOperation* rend, Pass* pass, Viewport* vp, 01262 const Matrix4& worldMatrix, const Matrix4& viewMatrix, const Matrix4& projMatrix, 01263 bool doBeginEndFrame = false) ; 01264 01278 virtual Overlay* createOverlay(const String& name, ushort zorder = 100); 01279 01281 virtual Overlay* getOverlay(const String& name); 01282 01284 virtual void destroyOverlay(const String& name); 01285 01287 virtual void destroyAllOverlays(void); 01288 01292 virtual void addRenderQueueListener(RenderQueueListener* newListener); 01293 01295 virtual void removeRenderQueueListener(RenderQueueListener* delListener); 01296 01298 void showBoundingBoxes(bool bShow); 01299 01301 bool getShowBoundingBoxes() const; 01302 01304 void _notifyAutotrackingSceneNode(SceneNode* node, bool autoTrack); 01305 01306 01319 virtual AxisAlignedBoxSceneQuery* 01320 createAABBQuery(const AxisAlignedBox& box, unsigned long mask = 0xFFFFFFFF); 01333 virtual SphereSceneQuery* 01334 createSphereQuery(const Sphere& sphere, unsigned long mask = 0xFFFFFFFF); 01347 virtual PlaneBoundedVolumeListSceneQuery* 01348 createPlaneBoundedVolumeQuery(const PlaneBoundedVolumeList& volumes, unsigned long mask = 0xFFFFFFFF); 01349 01350 01363 virtual RaySceneQuery* 01364 createRayQuery(const Ray& ray, unsigned long mask = 0xFFFFFFFF); 01365 //PyramidSceneQuery* createPyramidQuery(const Pyramid& p, unsigned long mask = 0xFFFFFFFF); 01377 virtual IntersectionSceneQuery* 01378 createIntersectionQuery(unsigned long mask = 0xFFFFFFFF); 01379 01381 virtual void destroyQuery(SceneQuery* query); 01382 01383 typedef MapIterator<SceneLightList> LightIterator; 01384 typedef MapIterator<EntityList> EntityIterator; 01385 typedef MapIterator<CameraList> CameraIterator; 01386 typedef MapIterator<BillboardSetList> BillboardSetIterator; 01387 typedef MapIterator<AnimationList> AnimationIterator; 01388 01390 LightIterator getLightIterator(void) { 01391 return LightIterator(mLights.begin(), mLights.end()); 01392 } 01394 EntityIterator getEntityIterator(void) { 01395 return EntityIterator(mEntities.begin(), mEntities.end()); 01396 } 01398 CameraIterator getCameraIterator(void) { 01399 return CameraIterator(mCameras.begin(), mCameras.end()); 01400 } 01402 BillboardSetIterator getBillboardSetIterator(void) { 01403 return BillboardSetIterator(mBillboardSets.begin(), mBillboardSets.end()); 01404 } 01406 AnimationIterator getAnimationIterator(void) { 01407 return AnimationIterator(mAnimationsList.begin(), mAnimationsList.end()); 01408 } 01410 AnimationStateIterator getAnimationStateIterator(void) { 01411 return AnimationStateIterator(mAnimationStates.begin(), mAnimationStates.end()); 01412 } 01413 01446 virtual void setShadowTechnique(ShadowTechnique technique); 01447 01449 virtual ShadowTechnique getShadowTechnique(void) const { return mShadowTechnique; } 01450 01452 virtual void setShowDebugShadows(bool debug) { mDebugShadows = debug; } 01454 virtual bool getShowDebugShadows(void ) const { return mDebugShadows; } 01455 01462 virtual void setShadowColour(const ColourValue& colour); 01469 virtual const ColourValue& getShadowColour(void) const; 01481 virtual void setShadowDirectionalLightExtrusionDistance(Real dist); 01484 virtual Real getShadowDirectionalLightExtrusionDistance(void) const; 01500 virtual void setShadowFarDistance(Real distance); 01504 virtual Real getShadowFarDistance(void) const 01505 { return mShadowFarDist; } 01506 01532 virtual void setShadowIndexBufferSize(size_t size); 01534 virtual size_t getShadowIndexBufferSize(void) const 01535 { return mShadowIndexBufferSize; } 01542 virtual void setShadowTextureSize(unsigned short size); 01544 unsigned short getShadowTextureSize(void) const {return mShadowTextureSize; } 01552 virtual void setShadowTextureCount(unsigned short count); 01554 unsigned short getShadowTextureCount(void) const {return mShadowTextureCount; } 01561 virtual void setShadowTextureSettings(unsigned short size, unsigned short count); 01576 virtual void setShadowDirLightTextureOffset(Real offset) { mShadowTextureOffset = offset;} 01584 virtual void setShadowTextureFadeStart(Real fadeStart) 01585 { mShadowTextureFadeStart = fadeStart; } 01593 virtual void setShadowTextureFadeEnd(Real fadeEnd) 01594 { mShadowTextureFadeEnd = fadeEnd; } 01595 01632 virtual void setShadowUseInfiniteFarPlane(bool enable) { 01633 mShadowUseInfiniteFarPlane = enable; } 01634 01635 }; 01636 01638 class _OgreExport DefaultIntersectionSceneQuery : 01639 public IntersectionSceneQuery 01640 { 01641 public: 01642 DefaultIntersectionSceneQuery(SceneManager* creator); 01643 ~DefaultIntersectionSceneQuery(); 01644 01646 void execute(IntersectionSceneQueryListener* listener); 01647 }; 01648 01650 class _OgreExport DefaultRaySceneQuery : public RaySceneQuery 01651 { 01652 public: 01653 DefaultRaySceneQuery(SceneManager* creator); 01654 ~DefaultRaySceneQuery(); 01655 01657 void execute(RaySceneQueryListener* listener); 01658 }; 01660 class _OgreExport DefaultSphereSceneQuery : public SphereSceneQuery 01661 { 01662 public: 01663 DefaultSphereSceneQuery(SceneManager* creator); 01664 ~DefaultSphereSceneQuery(); 01665 01667 void execute(SceneQueryListener* listener); 01668 }; 01670 class _OgreExport DefaultPlaneBoundedVolumeListSceneQuery : public PlaneBoundedVolumeListSceneQuery 01671 { 01672 public: 01673 DefaultPlaneBoundedVolumeListSceneQuery(SceneManager* creator); 01674 ~DefaultPlaneBoundedVolumeListSceneQuery(); 01675 01677 void execute(SceneQueryListener* listener); 01678 }; 01680 class _OgreExport DefaultAxisAlignedBoxSceneQuery : public AxisAlignedBoxSceneQuery 01681 { 01682 public: 01683 DefaultAxisAlignedBoxSceneQuery(SceneManager* creator); 01684 ~DefaultAxisAlignedBoxSceneQuery(); 01685 01687 void execute(SceneQueryListener* listener); 01688 }; 01689 01690 01691 01692 } // Namespace 01693 01694 01695 01696 #endif 01697
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:44 2004