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 #include "FastGpuParamRef.h"
00026
00027 namespace Caelum
00028 {
00031 struct PrecipitationPresetParams
00032 {
00033 Ogre::ColourValue Colour;
00034 Ogre::Real Speed;
00035 Ogre::String Name;
00036 };
00037
00041 enum PrecipitationType
00042 {
00043 PRECTYPE_DRIZZLE = 0,
00044 PRECTYPE_RAIN = 1,
00045 PRECTYPE_SNOW = 2,
00046 PRECTYPE_SNOWGRAINS = 3,
00047 PRECTYPE_ICECRYSTALS = 4,
00048 PRECTYPE_ICEPELLETS = 5,
00049 PRECTYPE_HAIL = 6,
00050 PRECTYPE_SMALLHAIL = 7,
00051
00052 PRECTYPE_CUSTOM = 8,
00053 };
00054
00061 class CAELUM_EXPORT PrecipitationController
00062 {
00063 private:
00064 friend class PrecipitationInstance;
00065
00066 Ogre::SceneManager *mSceneMgr;
00067 Ogre::Vector3 mWindSpeed;
00068 Ogre::Real mIntensity;
00069 Ogre::Real mSpeed;
00070 Ogre::ColourValue mColour;
00071 PrecipitationType mPresetType;
00072 Ogre::String mTextureName;
00073 Ogre::Vector3 mCameraSpeedScale;
00074 Ogre::Vector3 mFallingDirection;
00075
00076 Ogre::Real mAutoDisableThreshold;
00077 bool mHardDisableCompositor;
00078
00079 Ogre::ColourValue mSceneColour;
00080 Real mInternalTime;
00081
00082
00083 Real mSecondsSinceLastFrame;
00084 inline Real getSecondsSinceLastFrame() { return mSecondsSinceLastFrame; }
00085
00086 public:
00088 static const String COMPOSITOR_NAME;
00089
00091 static const String MATERIAL_NAME;
00092
00094 static bool isPresetType (PrecipitationType value);
00095
00097 static const PrecipitationPresetParams& getPresetParams (PrecipitationType value);
00098
00100 void setParams (const PrecipitationPresetParams& params);
00101
00103 void setPresetType (PrecipitationType value);
00104
00109 PrecipitationType getPresetType () const;
00110
00111
00112 void setTextureName(const Ogre::String& textureName);
00113 const Ogre::String getTextureName() const;
00114
00116 void setColour(const Ogre::ColourValue& color);
00117 const Ogre::ColourValue getColour() const;
00118
00120 void setSpeed(Real value);
00121 Real getSpeed() const;
00122
00124 void setIntensity(Real value);
00125 Real getIntensity() const;
00126
00128 void setWindSpeed(const Ogre::Vector3 &value);
00129 const Ogre::Vector3 getWindSpeed() const;
00130
00137 void setFallingDirection(const Ogre::Vector3 &value) { mFallingDirection = value; }
00138 const Ogre::Vector3 getFallingDirection() const { return mFallingDirection; }
00139
00141 void setManualCameraSpeed(const Ogre::Vector3 &value);
00142
00144 void setAutoCameraSpeed();
00145
00151 inline void setAutoDisableThreshold (Real value) { mAutoDisableThreshold = value; }
00152 inline Real getAutoDisableThreshold () const { return mAutoDisableThreshold; }
00153
00164 inline void setCameraSpeedScale (const Ogre::Vector3& value) {
00165 mCameraSpeedScale = value;
00166 }
00167 inline const Ogre::Vector3 getCameraSpeedScale () const {
00168 return mCameraSpeedScale;
00169 }
00170
00173 inline void setCameraSpeedScale (Ogre::Real value) {
00174 setCameraSpeedScale(Ogre::Vector3::UNIT_SCALE * value);
00175 }
00176
00180 void update(Real secondsSinceLastFrame, Ogre::ColourValue colour);
00181
00182 PrecipitationController(
00183 Ogre::SceneManager *sceneMgr);
00184 ~PrecipitationController();
00185
00186 public:
00187 typedef std::map<Ogre::Viewport*, PrecipitationInstance*> ViewportInstanceMap;
00188 ViewportInstanceMap mViewportInstanceMap;
00189
00190 public:
00192 PrecipitationInstance* createViewportInstance(Ogre::Viewport* viewport);
00193
00195 void destroyViewportInstance(Ogre::Viewport* viewport);
00196
00198 PrecipitationInstance* getViewportInstance(Ogre::Viewport* viewport);
00199
00201 void destroyAllViewportInstances();
00202 };
00203
00207 class PrecipitationInstance: private Ogre::CompositorInstance::Listener
00208 {
00209 private:
00210 friend class PrecipitationController;
00211
00212 PrecipitationController* mParent;
00213 Ogre::Viewport* mViewport;
00214 Ogre::CompositorInstance* mCompInst;
00215 Ogre::Camera* mLastCamera;
00216 Ogre::Vector3 mLastCameraPosition;
00217 Ogre::Vector3 mCameraSpeed;
00218 bool mAutoCameraSpeed;
00219
00220 virtual void notifyMaterialSetup(uint pass_id, Ogre::MaterialPtr &mat);
00221 virtual void notifyMaterialRender(uint pass_id, Ogre::MaterialPtr &mat);
00222
00225 void _updateMaterialParams(
00226 const Ogre::MaterialPtr& mat,
00227 const Ogre::Camera* cam,
00228 const Ogre::Vector3& camSpeed);
00229
00230
00231 void createCompositor ();
00232 void destroyCompositor ();
00233
00234
00235 bool shouldBeEnabled () const;
00236
00238 void _update();
00239
00240 public:
00241 inline Ogre::Viewport* getViewport() const { return mViewport; }
00242 inline PrecipitationController* getParent() const { return mParent; }
00243 inline Ogre::CompositorInstance* getCompositorInstance() const { return mCompInst; }
00244
00246 bool getAutoCameraSpeed();
00247
00253 void setAutoCameraSpeed();
00254
00256 void setManualCameraSpeed(const Ogre::Vector3& value);
00257
00259 const Ogre::Vector3 getCameraSpeed();
00260
00261 PrecipitationInstance(PrecipitationController* parent, Ogre::Viewport* view);
00262 virtual ~PrecipitationInstance();
00263
00264 private:
00265 struct Params {
00266 void setup(Ogre::GpuProgramParametersSharedPtr fpParams);
00267
00268 Ogre::GpuProgramParametersSharedPtr fpParams;
00269 FastGpuParamRef precColor;
00270 FastGpuParamRef intensity;
00271 FastGpuParamRef dropSpeed;
00272 FastGpuParamRef corner1;
00273 FastGpuParamRef corner2;
00274 FastGpuParamRef corner3;
00275 FastGpuParamRef corner4;
00276 FastGpuParamRef deltaX;
00277 FastGpuParamRef deltaY;
00278 } mParams;
00279
00280 };
00281 }
00282
00283 #endif //CAELUM__PRECIPITATION_CONTROLLER_H