sceneSimpleZone.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 _SCENESIMPLEZONE_H_
  23. #define _SCENESIMPLEZONE_H_
  24. #ifndef _SCENEZONESPACE_H_
  25. #include "scene/zones/sceneZoneSpace.h"
  26. #endif
  27. #ifndef _MORIENTEDBOX_H_
  28. #include "math/mOrientedBox.h"
  29. #endif
  30. class SceneRenderState;
  31. class BaseMatInstance;
  32. /// Abstract base class for a zone space that contains only a single zone.
  33. ///
  34. /// Simple zones are required to be convex.
  35. class SceneSimpleZone : public SceneZoneSpace
  36. {
  37. public:
  38. typedef SceneZoneSpace Parent;
  39. protected:
  40. enum
  41. {
  42. AmbientMask = Parent::NextFreeMask << 0, ///< Ambient light color setting has changed.
  43. NextFreeMask = Parent::NextFreeMask << 1,
  44. };
  45. /// @name Ambient Lighting
  46. /// @{
  47. /// If this is true, then the zone defines its own ambient
  48. /// light color in #mAmbientColor.
  49. bool mUseAmbientLightColor;
  50. /// Ambient light color in this zone.
  51. LinearColorF mAmbientLightColor;
  52. /// @}
  53. /// @name Transforms
  54. /// @{
  55. /// Whether the zone has been rotated. This is used to fasttrack overlap
  56. /// tests to avoid doing an OBB/AABB intersection test when we can simply
  57. /// use a much quicker AABB/AABB intersection test on the world boxes of
  58. /// both objects.
  59. bool mIsRotated;
  60. /// The OBB for the zone.
  61. OrientedBox3F mOrientedWorldBox;
  62. /// @}
  63. /// Return the oriented bounding box for the zone.
  64. const OrientedBox3F& _getOrientedWorldBox() const { return mOrientedWorldBox; }
  65. /// Update the OBB for the zone.
  66. virtual void _updateOrientedWorldBox() { mOrientedWorldBox.set( getTransform(), getScale() ); }
  67. // SceneObject.
  68. virtual bool onSceneAdd();
  69. public:
  70. SceneSimpleZone();
  71. /// @name Ambient Lighting
  72. /// @{
  73. /// Return true if the zone defines its own ambient light color.
  74. bool useAmbientLightColor() const { return mUseAmbientLightColor; }
  75. /// Set whether a custom ambient light color is active in this zone.
  76. void setUseAmbientLightColor( bool value );
  77. /// Return the ambient light color for this zone.
  78. LinearColorF getAmbientLightColor() const { return mAmbientLightColor; }
  79. /// Set the ambient light color for the zone.
  80. /// @note This only takes effect if useAmbientLightColor() return true.
  81. /// @see setUseAmbientLightColor
  82. void setAmbientLightColor( const LinearColorF& color );
  83. /// @}
  84. /// @name Inherited
  85. /// @{
  86. // SimObject.
  87. virtual String describeSelf() const;
  88. static void initPersistFields();
  89. // NetObject
  90. virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
  91. virtual void unpackUpdate( NetConnection *conn, BitStream *stream );
  92. // SceneObject
  93. virtual void prepRenderImage( SceneRenderState* state );
  94. virtual void setTransform( const MatrixF& mat );
  95. // SceneZoneSpace.
  96. virtual U32 getPointZone( const Point3F &p );
  97. virtual bool getOverlappingZones( const Box3F& aabb, U32* outZones, U32& outNumZones );
  98. virtual void traverseZones( SceneTraversalState* state );
  99. virtual bool getZoneAmbientLightColor( U32 zone, LinearColorF& outColor ) const;
  100. virtual void traverseZones( SceneTraversalState* state, U32 startZoneId );
  101. /// @}
  102. private:
  103. static bool _setUseAmbientLightColor( void* object, const char* index, const char* data );
  104. static bool _setAmbientLightColor( void* object, const char* index, const char* data );
  105. };
  106. #endif // !_SCENESIMPLEZONE_H_