00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CAELUM__PRECIPITATION_CONTROLLER_H
00022 #define CAELUM__PRECIPITATION_CONTROLLER_H
00023
00024 #include "CaelumPrerequisites.h"
00025
00026 namespace Caelum
00027 {
00030 struct PrecipitationPresetParams
00031 {
00032 Ogre::ColourValue Colour;
00033 Ogre::Real Speed;
00034 Ogre::String Name;
00035 };
00036
00040 enum PrecipitationType
00041 {
00042 PRECTYPE_DRIZZLE = 0,
00043 PRECTYPE_RAIN = 1,
00044 PRECTYPE_SNOW = 2,
00045 PRECTYPE_SNOWGRAINS = 3,
00046 PRECTYPE_ICECRYSTALS = 4,
00047 PRECTYPE_ICEPELLETS = 5,
00048 PRECTYPE_HAIL = 6,
00049 PRECTYPE_SMALLHAIL = 7,
00050
00051 PRECTYPE_CUSTOM = 8,
00052 };
00053
00060 class CAELUM_EXPORT PrecipitationController
00061 {
00062 private:
00063 friend class PrecipitationInstance;
00064
00065 Ogre::SceneManager *mSceneMgr;
00066 Ogre::Vector3 mWindSpeed;
00067 Ogre::Real mIntensity;
00068 Ogre::Real mSpeed;
00069 Ogre::ColourValue mColour;
00070 PrecipitationType mPresetType;
00071 Ogre::String mTextureName;
00072 Ogre::Vector3 mCameraSpeedScale;
00073 Ogre::Vector3 mFallingDirection;
00074
00075 Ogre::Real mAutoDisableThreshold;
00076 bool mHardDisableCompositor;
00077
00078 Ogre::ColourValue mSceneColour;
00079 Real mInternalTime;
00080
00081
00082 Real mSecondsSinceLastFrame;
00083 inline Real getSecondsSinceLastFrame() { return mSecondsSinceLastFrame; }
00084
00086 void _updateMaterialParams(
00087 const Ogre::MaterialPtr& mat,
00088 const Ogre::Camera* cam,
00089 const Ogre::Vector3& camSpeed);
00090
00091 public:
00093 static const String COMPOSITOR_NAME;
00094
00096 static const String MATERIAL_NAME;
00097
00099 static bool isPresetType (PrecipitationType value);
00100
00102 static const PrecipitationPresetParams& getPresetParams (PrecipitationType value);
00103
00105 void setParams (const PrecipitationPresetParams& params);
00106
00108 void setPresetType (PrecipitationType value);
00109
00114 PrecipitationType getPresetType () const;
00115
00116
00117 void setTextureName(const Ogre::String& textureName);
00118 const Ogre::String getTextureName() const;
00119
00121 void setColour(const Ogre::ColourValue& color);
00122 const Ogre::ColourValue getColour() const;
00123
00125 void setSpeed(Real value);
00126 Real getSpeed() const;
00127
00129 void setIntensity(Real value);
00130 Real getIntensity() const;
00131
00133 void setWindSpeed(const Ogre::Vector3 &value);
00134 const Ogre::Vector3 getWindSpeed() const;
00135
00142 void setFallingDirection(const Ogre::Vector3 &value) { mFallingDirection = value; }
00143 const Ogre::Vector3 getFallingDirection() const { return mFallingDirection; }
00144
00146 void setManualCameraSpeed(const Ogre::Vector3 &value);
00147
00149 void setAutoCameraSpeed();
00150
00156 inline void setAutoDisableThreshold (Real value) { mAutoDisableThreshold = value; }
00157 inline Real getAutoDisableThreshold () const { return mAutoDisableThreshold; }
00158
00169 inline void setCameraSpeedScale (const Ogre::Vector3& value) {
00170 mCameraSpeedScale = value;
00171 }
00172 inline const Ogre::Vector3 getCameraSpeedScale () const {
00173 return mCameraSpeedScale;
00174 }
00175
00178 inline void setCameraSpeedScale (Ogre::Real value) {
00179 setCameraSpeedScale(Ogre::Vector3::UNIT_SCALE * value);
00180 }
00181
00185 void update(Real secondsSinceLastFrame, Ogre::ColourValue colour);
00186
00187 PrecipitationController(
00188 Ogre::SceneManager *sceneMgr);
00189 ~PrecipitationController();
00190
00191 public:
00192 typedef std::map<Ogre::Viewport*, PrecipitationInstance*> ViewportInstanceMap;
00193 ViewportInstanceMap mViewportInstanceMap;
00194
00195 public:
00197 PrecipitationInstance* createViewportInstance(Ogre::Viewport* viewport);
00198
00200 void destroyViewportInstance(Ogre::Viewport* viewport);
00201
00203 PrecipitationInstance* getViewportInstance(Ogre::Viewport* viewport);
00204
00206 void destroyAllViewportInstances();
00207 };
00208
00212 class PrecipitationInstance: private Ogre::CompositorInstance::Listener
00213 {
00214 private:
00215 friend class PrecipitationController;
00216
00217 PrecipitationController* mParent;
00218 Ogre::Viewport* mViewport;
00219 Ogre::CompositorInstance* mCompInst;
00220 Ogre::Camera* mLastCamera;
00221 Ogre::Vector3 mLastCameraPosition;
00222 Ogre::Vector3 mCameraSpeed;
00223 bool mAutoCameraSpeed;
00224
00225 virtual void notifyMaterialSetup(uint pass_id, Ogre::MaterialPtr &mat);
00226 virtual void notifyMaterialRender(uint pass_id, Ogre::MaterialPtr &mat);
00227
00228
00229 void createCompositor ();
00230 void destroyCompositor ();
00231
00232
00233 bool shouldBeEnabled () const;
00234
00236 void _update();
00237
00238 public:
00239 inline Ogre::Viewport* getViewport() const { return mViewport; }
00240 inline PrecipitationController* getParent() const { return mParent; }
00241 inline Ogre::CompositorInstance* getCompositorInstance() const { return mCompInst; }
00242
00244 bool getAutoCameraSpeed();
00245
00251 void setAutoCameraSpeed();
00252
00254 void setManualCameraSpeed(const Ogre::Vector3& value);
00255
00257 const Ogre::Vector3 getCameraSpeed();
00258
00259 PrecipitationInstance(PrecipitationController* parent, Ogre::Viewport* view);
00260 virtual ~PrecipitationInstance();
00261 };
00262 }
00263
00264 #endif //CAELUM__PRECIPITATION_CONTROLLER_H