TerrainGlobalOptions的源码

	/** Options class which just stores default options for the terrain. 仅仅用来存储地形默认的设置
	@remarks
		None of these options are stored with the terrain when saved. They are
		options that you can use to modify the behaviour of the terrain when it
		is loaded or created. 这些选项都不会被地形存储下来。当我们load或created时候就要修改地形的behaviour
	@note
		You should construct a single instance of this class per application and
		do so before you start working with any other terrain classes.
	*/
	class _OgreTerrainExport TerrainGlobalOptions : public TerrainAlloc, public Singleton<TerrainGlobalOptions>
	{
	protected:

		Real mSkirtSize;//默认的裙子的大小
		Vector3 mLightMapDir;//shadowmap的方向
		bool mCastsShadows;//是否投射阴影
		Real mMaxPixelError;//屏幕像素错误
		uint8 mRenderQueueGroup;//
		uint32 mVisibilityFlags;//
		uint32 mQueryFlags;//
		bool mUseRayBoxDistanceCalculation;
		TerrainMaterialGeneratorPtr mDefaultMaterialGenerator;
		uint16 mLayerBlendMapSize;//BlendMap的大小
		Real mDefaultLayerTextureWorldSize;//纹理大小
		uint16 mDefaultGlobalColourMapSize;//
		uint16 mLightmapSize;//阴影图大小
		uint16 mCompositeMapSize;//混合贴图大小
		ColourValue mCompositeMapAmbient;//混合纹理图环境光
		ColourValue mCompositeMapDiffuse;//混合纹理图diffuse光
		Real mCompositeMapDistance;//距离
		String mResourceGroup;//ResourceGroup

	public:
		TerrainGlobalOptions();
		virtual ~TerrainGlobalOptions() {}


		/** The default size of 'skirts' used to hide terrain cracks 用来去遮挡住由于不同的LOD带来的地形裂缝
		(default 10)
		*/
		Real getSkirtSize() { return mSkirtSize; }//默认的裙子的大小
		/** method - the default size of 'skirts' used to hide terrain cracks
		(default 10)
		@remarks  设置裙子的大小  只能在地形实体load和reload之后设置
			Changing this value only applies to Terrain instances loaded / reloaded afterwards.
		*/
		void setSkirtSize(Real skirtSz) { mSkirtSize = skirtSz; }
		/// Get the shadow map light direction to use (world space)
		const Vector3& getLightMapDirection() { return mLightMapDir; }
		/** Set the shadow map light direction to use (world space). */
		void setLightMapDirection(const Vector3& v) { mLightMapDir = v; }
		/// Get the composite map ambient light to use 
		const ColourValue& getCompositeMapAmbient() { return mCompositeMapAmbient; }
		/// Set the composite map ambient light to use 设置混合纹理环境光
		void setCompositeMapAmbient(const ColourValue& c) { mCompositeMapAmbient = c; }
		/// Get the composite map iffuse light to use 获得混合贴图
		const ColourValue& getCompositeMapDiffuse() { return mCompositeMapDiffuse; }
		/// Set the composite map diffuse light to use 
		void setCompositeMapDiffuse(const ColourValue& c) { mCompositeMapDiffuse = c; }
		/// Get the distance at which to start using a composite map if present
		Real getCompositeMapDistance() { return mCompositeMapDistance; }
		/// Set the distance at which to start using a composite map if present
		void setCompositeMapDistance(Real c) { mCompositeMapDistance = c; }


		/** Whether the terrain will be able to cast shadows (texture shadows
		only are supported, and you must be using depth shadow maps). 是否要进行投射阴影纹理
		*/
		bool getCastsDynamicShadows() { return mCastsShadows; }

		/** Whether the terrain will be able to cast shadows (texture shadows
		only are supported, and you must be using depth shadow maps).
		This value can be set dynamically, and affects all existing terrains.
		It defaults to false. 
		*/
		void setCastsDynamicShadows(bool s) { mCastsShadows = s; }

		/** Get the maximum screen pixel error(最大的屏幕像素) that should be allowed when rendering. */
		Real getMaxPixelError() { return mMaxPixelError; }

		/** Set the maximum screen pixel error that should  be allowed when rendering. 
		设置渲染的时候出现的屏幕的最大容许像素错误 mMaxPixelError 默认是3
		@note
			This value can be varied dynamically and affects all existing terrains.
			It will be weighted by the LOD bias on viewports. 
		*/
		void setMaxPixelError(Real pixerr) { mMaxPixelError = pixerr; }

		/// Get the render queue group that this terrain will be rendered into
		uint8 getRenderQueueGroup(void) { return mRenderQueueGroup; }//获得Terrain的 render queue group
		/** Set the render queue group that terrains will be rendered into.
		@remarks This applies to newly created terrains, after which they will
			maintain their own queue group settings
		*/
		void setRenderQueueGroup(uint8 grp) { mRenderQueueGroup = grp; }

		/// Get the visbility flags that terrains will be rendered with
		uint32 getVisibilityFlags(void) { return mVisibilityFlags; }
		/** Set the visbility flags that terrains will be rendered with
		@remarks This applies to newly created terrains, after which they will
		maintain their own settings
		*/
		void setVisibilityFlags(uint32 flags) { mVisibilityFlags = flags; }

		/** Set the default query flags for terrains.
		@remarks This applies to newly created terrains, after which they will
		maintain their own settings
		*/
		void  setQueryFlags(uint32 flags) { mQueryFlags = flags; }//设置查询Flag
		/** Get the default query flags for terrains.
		*/
		uint32 getQueryFlags(void) { return mQueryFlags; }//得到查询的Flag

		/** As setQueryFlags, except the flags passed as parameters are appended to the existing flags on this object. */
		void addQueryFlags(uint32 flags) { mQueryFlags |= flags; }//为mQueryFlag中添加一个flags

		/* As setQueryFlags, except the flags passed as parameters are removed from the existing flags on this object. */
		void removeQueryFlags(uint32 flags) { mQueryFlags &= ~flags; }//取消mQueryFlag的一个flags

		/** Returns whether or not to use an accurate calculation of camera distance
			from a terrain tile (ray / AABB intersection) or whether to use the
			simpler distance from the tile centre. 
		*/
		bool getUseRayBoxDistanceCalculation() { return mUseRayBoxDistanceCalculation; }

		/** Sets whether to use an accurate ray / box intersection to determine
			distance from a terrain tile, or whether to use the simple distance
			from the tile centre.
			Using ray/box intersection will result in higher detail terrain because 
			the LOD calculation is more conservative, assuming the 'worst case scenario' 
			of a large height difference at the edge of a tile. This is guaranteed to give you at least
			the max pixel error or better, but will often give you more detail than
			you need. Not using the ray/box method is cheaper but will only use
			the max pixel error as a guide, the actual error will vary above and
			below that. The default is not to use the ray/box approach.
		*/
		void setUseRayBoxDistanceCalculation(bool rb) { mUseRayBoxDistanceCalculation = rb; }

		/** Get the default material generator.获得默认的材质generator
		*/
		TerrainMaterialGeneratorPtr getDefaultMaterialGenerator();

		/** Set the default material generator.
		*/
		void setDefaultMaterialGenerator(TerrainMaterialGeneratorPtr gen);

		/** Get the default size of the blend maps for a new terrain.  获得blendmap的大小
		*/
		uint16 getLayerBlendMapSize() { return mLayerBlendMapSize; }

		/** Sets the default size of blend maps for a new terrain.
		This is the resolution of each blending layer for a new terrain. 
		Once created, this information will be stored with the terrain. 
		*/
		void setLayerBlendMapSize(uint16 sz) { mLayerBlendMapSize = sz;}

		/** Get the default world size for a layer 'splat' texture to cover. 
		*/
		Real getDefaultLayerTextureWorldSize() { return mDefaultLayerTextureWorldSize; }

		/** Set the default world size for a layer 'splat' texture to cover. 
		*/
		void setDefaultLayerTextureWorldSize(Real sz) { mDefaultLayerTextureWorldSize = sz; }

		/** Get the default size of the terrain global colour map for a new terrain. 
		*/
		uint16 getDefaultGlobalColourMapSize() { return mDefaultGlobalColourMapSize; }

		/** Set the default size of the terrain global colour map for a new terrain. 
		Once created, this information will be stored with the terrain. 
		*/
		void setDefaultGlobalColourMapSize(uint16 sz) { mDefaultGlobalColourMapSize = sz;}


		/** Get the default size of the lightmaps for a new terrain.获得阴影图的大小 
		*/
		uint16 getLightMapSize() { return mLightmapSize; }

		/** Sets the default size of lightmaps for a new terrain.
		*/
		void setLightMapSize(uint16 sz) { mLightmapSize = sz;}

		/** Get the default size of the composite maps for a new terrain. 
		*/
		uint16 getCompositeMapSize() { return mCompositeMapSize; }

		/** Sets the default size of composite maps for a new terrain.
		*/
		void setCompositeMapSize(uint16 sz) { mCompositeMapSize = sz;}

		/** Set the default resource group to use to load / save terrains.
		*/
		void setDefaultResourceGroup(const String& grp) { mResourceGroup = grp; }

		/** Get the default resource group to use to load / save terrains.
		*/
		const String& getDefaultResourceGroup() { return mResourceGroup; }

		/** Override standard Singleton retrieval.
		@remarks
		Why do we do this? Well, it's because the Singleton
		implementation is in a .h file, which means it gets compiled
		into anybody who includes it. This is needed for the
		Singleton template to work, but we actually only want it
		compiled into the implementation of the class based on the
		Singleton, not all of them. If we don't change this, we get
		link errors when trying to use the Singleton-based class from
		an outside dll.
		@par
		This method just delegates to the template version anyway,
		but the implementation stays in this single compilation unit,
		preventing link errors.
		*/
		static TerrainGlobalOptions& getSingleton(void);
		/** Override standard Singleton retrieval.
		@remarks
		Why do we do this? Well, it's because the Singleton
		implementation is in a .h file, which means it gets compiled
		into anybody who includes it. This is needed for the
		Singleton template to work, but we actually only want it
		compiled into the implementation of the class based on the
		Singleton, not all of them. If we don't change this, we get
		link errors when trying to use the Singleton-based class from
		an outside dll.
		@par
		This method just delegates to the template version anyway,
		but the implementation stays in this single compilation unit,
		preventing link errors.
		*/
		static TerrainGlobalOptions* getSingletonPtr(void);


	};
	//---------------------------------------------------------------------
	TerrainGlobalOptions::TerrainGlobalOptions()
		: mSkirtSize(30)//默认裙子的大小
		, mLightMapDir(Vector3(1, -1, 0).normalisedCopy())//shadowmap的方向
		, mCastsShadows(false)//cast shadows or not
		, mMaxPixelError(3.0)//
		, mRenderQueueGroup(RENDER_QUEUE_MAIN)//渲染队列
		, mVisibilityFlags(0xFFFFFFFF)
		, mQueryFlags(0xFFFFFFFF)
		, mUseRayBoxDistanceCalculation(false)
		, mLayerBlendMapSize(1024)//混合纹理大小
		, mDefaultLayerTextureWorldSize(10)//世界纹理大小
		, mDefaultGlobalColourMapSize(1024)//
		, mLightmapSize(1024)//光照图大小
		, mCompositeMapSize(1024)//混合贴图大小
		, mCompositeMapAmbient(ColourValue::White)//混合贴图环境光
		, mCompositeMapDiffuse(ColourValue::White)//
		, mCompositeMapDistance(4000)//超过4000使用这个混合贴图
		, mResourceGroup(ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)//默认资源组
	{
	}
	void TerrainGlobalOptions::setDefaultMaterialGenerator(TerrainMaterialGeneratorPtr gen)
	{
		mDefaultMaterialGenerator = gen;
	}
	//---------------------------------------------------------------------
	TerrainMaterialGeneratorPtr TerrainGlobalOptions::getDefaultMaterialGenerator()
	{
		if (mDefaultMaterialGenerator.isNull())
		{
			// default
			mDefaultMaterialGenerator.bind(OGRE_NEW TerrainMaterialGeneratorA());
		}

		return mDefaultMaterialGenerator;
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值