sun.h

Engine/source/environment/sun.h

More...

Classes:

class

Detailed Description

  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 _SUN_H_
 25#define _SUN_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28#include "scene/sceneObject.h"
 29#endif
 30#ifndef _COLOR_H_
 31#include "core/color.h"
 32#endif
 33#ifndef _LIGHTINFO_H_
 34#include "lighting/lightInfo.h"
 35#endif
 36#ifndef _LIGHTFLAREDATA_H_
 37#include "T3D/lightFlareData.h"
 38#endif
 39
 40class TimeOfDay;
 41class MatrixSet;
 42
 43///
 44class Sun : public SceneObject, public ISceneLight
 45{
 46   typedef SceneObject Parent;
 47
 48protected:
 49
 50   F32 mSunAzimuth;
 51   
 52   F32 mSunElevation;
 53
 54   LinearColorF mLightColor;
 55
 56   LinearColorF mLightAmbient;
 57
 58   F32 mBrightness;
 59
 60   bool mAnimateSun;
 61   F32  mTotalTime;
 62   F32  mCurrTime;
 63   F32  mStartAzimuth;
 64   F32  mEndAzimuth;
 65   F32  mStartElevation;
 66   F32  mEndElevation;
 67
 68   bool mCastShadows;
 69   S32 mStaticRefreshFreq;
 70   S32 mDynamicRefreshFreq;
 71
 72   LightInfo *mLight;
 73
 74   LightFlareData *mFlareData;
 75   LightFlareState mFlareState;
 76   F32 mFlareScale;
 77
 78   bool mCoronaEnabled;
 79   String mCoronaMatName;
 80   BaseMatInstance *mCoronaMatInst;
 81   MatrixSet *mMatrixSet;   
 82   F32 mCoronaScale;
 83   LinearColorF mCoronaTint;
 84   bool mCoronaUseLightColor;
 85
 86   // These are not user specified.
 87   // These hold data calculated once used across several methods.
 88   F32 mCoronaWorldRadius;
 89   Point3F mLightWorldPos;
 90
 91   void _conformLights();
 92   void _initCorona();
 93   void _renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
 94   void _updateTimeOfDay( TimeOfDay *timeOfDay, F32 time );
 95
 96   // SimObject.
 97   virtual void _onSelected();
 98   virtual void _onUnselected();
 99
100   enum NetMaskBits 
101   {
102      UpdateMask = BIT(0)
103   };
104
105public:
106
107   Sun();
108   virtual ~Sun();
109
110   // SimObject
111   virtual bool onAdd();
112   virtual void onRemove();
113
114   // ConsoleObject
115   DECLARE_CONOBJECT(Sun);   
116   static void initPersistFields();
117   void inspectPostApply();
118
119   // NetObject
120   U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
121   void unpackUpdate( NetConnection *conn, BitStream *stream ); 
122
123   // ISceneLight
124   virtual void submitLights( LightManager *lm, bool staticLighting );
125   virtual LightInfo* getLight() { return mLight; }   
126
127   // SceneObject   
128   virtual void prepRenderImage( SceneRenderState* state );
129
130   // ProcessObject
131   virtual void advanceTime( F32 dt );
132
133   ///
134   void setAzimuth( F32 azimuth );
135
136   ///
137   void setElevation( F32 elevation );
138
139   ///
140   void setColor( const LinearColorF &color );
141
142   ///
143   void animate( F32 duration, F32 startAzimuth, F32 endAzimuth, F32 startElevation, F32 endElevation );
144};
145
146#endif // _SUN_H_
147