Torque3D Documentation / _generateds / forestWindEmitter.h

forestWindEmitter.h

Engine/source/forest/forestWindEmitter.h

More...

Classes:

Public Typedefs

ForestWindEmitterList 

A vector of WindEmitter pointers.

Detailed Description

Public Typedefs

typedef Vector< ForestWindEmitter * > ForestWindEmitterList 

A vector of WindEmitter pointers.

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _FORESTWINDEMITTER_H_
 25#define _FORESTWINDEMITTER_H_
 26
 27
 28#ifndef _SCENEOBJECT_H_
 29#include "scene/sceneObject.h"
 30#endif
 31#ifndef _MMATRIX_H_
 32#include "math/mMatrix.h"
 33#endif
 34#ifndef _MPOINT3_H_
 35#include "math/mPoint3.h"
 36#endif
 37#ifndef _MSPHERE_H_
 38#include "math/mSphere.h"
 39#endif
 40#ifndef _TVECTOR_H_
 41#include "core/util/tVector.h"
 42#endif
 43
 44
 45class ForestWindEmitter;
 46class ForestWindAccumulator;
 47class BaseMatInstance;
 48
 49
 50class ForestWind
 51{
 52
 53protected:
 54
 55   F32 mStrength;
 56
 57   VectorF mDirection;
 58
 59   F32 mLastGustTime;
 60   F32 mLastYawTime;
 61
 62   F32 mTargetYawAngle;
 63
 64   F32 mCurrentInterp;
 65   Point2F mCurrentTarget;
 66
 67   ForestWindEmitter *mParent;
 68
 69   MRandom mRandom;
 70
 71   bool mIsDirty;
 72
 73public:
 74
 75   ForestWind( ForestWindEmitter *emitter );
 76   virtual ~ForestWind();
 77
 78   void processTick();
 79
 80   void setStrengthAndDirection( F32 strength, const VectorF &direction );
 81
 82   void setStrength( F32 strength );
 83
 84   void setDirection( const VectorF &direction );
 85
 86   void setIsDirty( bool isDirty ) { mIsDirty = isDirty; }
 87
 88   F32 getStrength() const { return mStrength; }
 89
 90   const VectorF& getDirection() const { return mDirection; }
 91   VectorF getTarget() const { return VectorF( mCurrentTarget.x, mCurrentTarget.y, 0 ); }
 92};
 93
 94
 95/// A vector of WindEmitter pointers.
 96typedef Vector<ForestWindEmitter*> ForestWindEmitterList;
 97
 98class ForestWindEmitter : public SceneObject
 99{
100   typedef SceneObject Parent;
101   friend class ForestWind;
102   friend class ForestWindAccumulator;
103
104protected:
105
106   enum
107   {
108        EnabledMask    = Parent::NextFreeMask << 0,
109        WindMask       = Parent::NextFreeMask << 1,
110          NextFreeMask   = Parent::NextFreeMask << 2
111   };
112
113   bool mAddedToScene;
114
115   bool mEnabled;
116
117   ForestWind *mWind;
118
119   F32 mWindStrength;
120
121   VectorF mWindDirection;
122
123   /// Controls how often the wind gust peaks per second.
124   F32 mWindGustFrequency;
125
126   /// The maximum distance in meters that the peak wind 
127   /// gust will displace an element.
128   F32 mWindGustStrength;
129
130   /// The range that the wind direction
131   /// will yaw between (-val to +val).
132   F32 mWindGustYawAngle;
133
134   /// The frequency, in seconds, between
135   /// animations in the gust yaw angle.
136   F32 mWindGustYawFrequency;
137
138   /// The maximum amount of random wobble
139   /// that will be applied to the gusting
140   /// as well as the yaw rotation.
141   F32 mWindGustWobbleStrength;
142
143   /// Controls the overally rapidity of the wind turbulence.
144   F32 mWindTurbulenceFrequency;
145
146   /// The maximum distance in meters that the turbulence can
147   /// displace a ground cover element.
148   F32 mWindTurbulenceStrength;
149
150   /// If the radius is greater than zero then this is
151   /// a localized radial wind emitter.
152   F32 mWindRadius;
153
154   /// Explicitly denotes whether this is a
155   /// global directional wind emitter or a
156   /// localized radial wind emitter.
157   bool mRadialEmitter;
158
159   bool mHasMount;
160   bool mIsMounted;
161
162   /// An object that the emitter can
163   /// get position updates from.
164   SimObjectPtr<SceneObject> mMountObject;
165
166   static ForestWindEmitterList smEmitters;
167
168   void _initWind( U32 mask = 0xFFFFFFFF );
169
170   void _onMountObjectGhostReceived( SceneObject *object );
171
172public:
173
174   ForestWindEmitter( bool makeClientObject = false );
175
176   virtual ~ForestWindEmitter();
177
178   bool isEnabled() const { return mEnabled; }
179
180   ForestWind* getWind() { return mWind; }
181
182   bool isLocalWind() const { return mWindRadius > 0.0f; }
183   bool isRadialEmitter() const { return mRadialEmitter; }
184
185   F32 getWindRadius() const { return mWindRadius; }
186
187   F32 getWindRadiusSquared() const { return mWindRadius * mWindRadius; }
188
189   void setWindRadius( F32 radius ) { mWindRadius = radius; } 
190
191   F32 getStrength() const;
192   void setStrength( F32 strength );
193
194   void _renderEmitterInfo( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
195
196   void attachToObject( SceneObject *obj );
197   void updateMountPosition();
198
199   // SceneObject
200   virtual void setTransform( const MatrixF &mat );
201   void prepRenderImage( SceneRenderState *state );
202
203   // SimObject
204   bool onAdd();
205   void onRemove();
206   void inspectPostApply();
207   void onEditorEnable();
208   void onEditorDisable();
209   void onDeleteNotify(SimObject *object);
210
211   // NetObject
212   U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
213   void unpackUpdate( NetConnection *conn, BitStream *stream );
214
215   // ConObject.
216   static void initPersistFields();
217   DECLARE_CONOBJECT(ForestWindEmitter);
218};
219
220#endif // _FORESTWINDEMITTER_H_
221