sun.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SUN_H_
  23. #define _SUN_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _COLOR_H_
  28. #include "core/color.h"
  29. #endif
  30. #ifndef _LIGHTINFO_H_
  31. #include "lighting/lightInfo.h"
  32. #endif
  33. #ifndef _LIGHTFLAREDATA_H_
  34. #include "T3D/lightFlareData.h"
  35. #endif
  36. #include "T3D/assets/MaterialAsset.h"
  37. class TimeOfDay;
  38. class MatrixSet;
  39. ///
  40. class Sun : public SceneObject, public ISceneLight
  41. {
  42. typedef SceneObject Parent;
  43. protected:
  44. F32 mSunAzimuth;
  45. F32 mSunElevation;
  46. LinearColorF mLightColor;
  47. LinearColorF mLightAmbient;
  48. F32 mBrightness;
  49. bool mAnimateSun;
  50. F32 mTotalTime;
  51. F32 mCurrTime;
  52. F32 mStartAzimuth;
  53. F32 mEndAzimuth;
  54. F32 mStartElevation;
  55. F32 mEndElevation;
  56. bool mCastShadows;
  57. S32 mStaticRefreshFreq;
  58. S32 mDynamicRefreshFreq;
  59. LightInfo *mLight;
  60. LightFlareData *mFlareData;
  61. LightFlareState mFlareState;
  62. F32 mFlareScale;
  63. bool mCoronaEnabled;
  64. DECLARE_MATERIALASSET(Sun, CoronaMaterial);
  65. DECLARE_ASSET_NET_SETGET(Sun, CoronaMaterial, UpdateMask);
  66. BaseMatInstance *mCoronaMatInst;
  67. MatrixSet *mMatrixSet;
  68. F32 mCoronaScale;
  69. LinearColorF mCoronaTint;
  70. bool mCoronaUseLightColor;
  71. // These are not user specified.
  72. // These hold data calculated once used across several methods.
  73. F32 mCoronaWorldRadius;
  74. Point3F mLightWorldPos;
  75. void _conformLights();
  76. void _initCorona();
  77. void _renderCorona( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
  78. void _updateTimeOfDay( TimeOfDay *timeOfDay, F32 time );
  79. // SimObject.
  80. virtual void _onSelected();
  81. virtual void _onUnselected();
  82. enum NetMaskBits
  83. {
  84. UpdateMask = BIT(0)
  85. };
  86. public:
  87. Sun();
  88. virtual ~Sun();
  89. // SimObject
  90. virtual bool onAdd();
  91. virtual void onRemove();
  92. // ConsoleObject
  93. DECLARE_CONOBJECT(Sun);
  94. static void initPersistFields();
  95. void inspectPostApply();
  96. // NetObject
  97. U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  98. void unpackUpdate( NetConnection *conn, BitStream *stream );
  99. // ISceneLight
  100. virtual void submitLights( LightManager *lm, bool staticLighting );
  101. virtual LightInfo* getLight() { return mLight; }
  102. // SceneObject
  103. virtual void prepRenderImage( SceneRenderState* state );
  104. // ProcessObject
  105. virtual void advanceTime( F32 dt );
  106. ///
  107. void setAzimuth( F32 azimuth );
  108. ///
  109. void setElevation( F32 elevation );
  110. ///
  111. void setColor( const LinearColorF &color );
  112. ///
  113. void animate( F32 duration, F32 startAzimuth, F32 endAzimuth, F32 startElevation, F32 endElevation );
  114. };
  115. #endif // _SUN_H_