Zone.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Color.h"
  24. #include "Drawable.h"
  25. namespace Urho3D
  26. {
  27. /// %Component that describes global rendering properties
  28. class URHO3D_API Zone : public Drawable
  29. {
  30. OBJECT(Zone);
  31. public:
  32. /// Construct.
  33. Zone(Context* context);
  34. /// Destruct.
  35. virtual ~Zone();
  36. /// Register object factory. Drawable must be registered first.
  37. static void RegisterObject(Context* context);
  38. /// Handle attribute write access.
  39. virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& src);
  40. /// Visualize the component as debug geometry.
  41. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  42. /// Set local-space bounding box. Will be used as an oriented bounding box to test whether objects or the camera are inside.
  43. void SetBoundingBox(const BoundingBox& box);
  44. /// Set ambient color
  45. void SetAmbientColor(const Color& color);
  46. /// Set fog color.
  47. void SetFogColor(const Color& color);
  48. /// Set fog start distance.
  49. void SetFogStart(float start);
  50. /// Set fog end distance.
  51. void SetFogEnd(float end);
  52. /// Set fog height distance relative to the scene node's world position. Effective only in height fog mode.
  53. void SetFogHeight(float height);
  54. /// Set fog height scale. Effective only in height fog mode.
  55. void SetFogHeightScale(float scale);
  56. /// Set zone priority. If an object or camera is inside several zones, the one with highest priority is used.
  57. void SetPriority(int priority);
  58. /// Set height fog mode.
  59. void SetHeightFog(bool enable);
  60. /// Set override mode. If camera is inside an override zone, it will also be used for all drawables.
  61. void SetOverride(bool enable);
  62. /// Set ambient gradient mode. In gradient mode ambient color is interpolated from neighbor zones.
  63. void SetAmbientGradient(bool enable);
  64. /// Return inverse world transform.
  65. const Matrix3x4& GetInverseWorldTransform() const;
  66. /// Return zone's own ambient color, disregarding gradient mode.
  67. const Color& GetAmbientColor() const { return ambientColor_; }
  68. /// Return ambient start color. Not safe to call from worker threads due to possible octree query.
  69. const Color& GetAmbientStartColor();
  70. /// Return ambient end color. Not safe to call from worker threads due to possible octree query.
  71. const Color& GetAmbientEndColor();
  72. /// Return fog color.
  73. const Color& GetFogColor() const { return fogColor_; }
  74. /// Return fog start distance.
  75. float GetFogStart() const { return fogStart_; }
  76. /// Return fog end distance.
  77. float GetFogEnd() const { return fogEnd_; }
  78. /// Return fog height distance relative to the scene node's world position.
  79. float GetFogHeight() const { return fogHeight_; }
  80. /// Return fog height scale.
  81. float GetFogHeightScale() const { return fogHeightScale_; }
  82. /// Return zone priority.
  83. int GetPriority() const { return priority_; }
  84. /// Return whether height fog mode is enabled.
  85. bool GetHeightFog() const { return heightFog_; }
  86. /// Return whether override mode is enabled.
  87. bool GetOverride() const { return override_; }
  88. /// Return whether ambient gradient mode is enabled.
  89. bool GetAmbientGradient() const { return ambientGradient_; }
  90. /// Check whether a point is inside.
  91. bool IsInside(const Vector3& point) const;
  92. protected:
  93. /// Handle node transform being dirtied.
  94. virtual void OnMarkedDirty(Node* node);
  95. /// Recalculate the world-space bounding box.
  96. virtual void OnWorldBoundingBoxUpdate();
  97. /// Handle removal from octree.
  98. virtual void OnRemoveFromOctree();
  99. /// Recalculate the ambient gradient colors from neighbor zones. Not safe to call from worker threads due to octree query.
  100. void UpdateAmbientGradient();
  101. /// Clear zone reference from drawables inside the bounding box.
  102. void ClearDrawablesZone();
  103. /// Cached inverse world transform matrix.
  104. mutable Matrix3x4 inverseWorld_;
  105. /// Inverse transform dirty flag.
  106. mutable bool inverseWorldDirty_;
  107. /// Height fog mode flag.
  108. bool heightFog_;
  109. /// Override mode flag.
  110. bool override_;
  111. /// Ambient gradient mode flag.
  112. bool ambientGradient_;
  113. /// Last world-space bounding box.
  114. BoundingBox lastWorldBoundingBox_;
  115. /// Ambient color.
  116. Color ambientColor_;
  117. /// Cached ambient start color.
  118. Color ambientStartColor_;
  119. /// Cached ambient end color.
  120. Color ambientEndColor_;
  121. /// Fog color.
  122. Color fogColor_;
  123. /// Fog start distance.
  124. float fogStart_;
  125. /// Fog end distance.
  126. float fogEnd_;
  127. /// Fog height distance.
  128. float fogHeight_;
  129. /// Fog height cale.
  130. float fogHeightScale_;
  131. /// Zone priority.
  132. int priority_;
  133. /// Last zone used for ambient gradient start color.
  134. WeakPtr<Zone> lastAmbientStartZone_;
  135. /// Last zone used for ambient gradient end color.
  136. WeakPtr<Zone> lastAmbientEndZone_;
  137. };
  138. }