Zone.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Copyright (c) 2008-2013 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. /// Handle enabled/disabled state change.
  41. virtual void OnSetEnabled();
  42. /// Visualize the component as debug geometry.
  43. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  44. /// Set local-space bounding box. Will be used as an oriented bounding box to test whether objects or the camera are inside.
  45. void SetBoundingBox(const BoundingBox& box);
  46. /// Set ambient color
  47. void SetAmbientColor(const Color& color);
  48. /// Set fog color.
  49. void SetFogColor(const Color& color);
  50. /// Set fog start distance.
  51. void SetFogStart(float start);
  52. /// Set fog end distance.
  53. void SetFogEnd(float end);
  54. /// Set zone priority. If an object or camera is inside several zones, the one with highest priority is used.
  55. void SetPriority(int priority);
  56. /// Set override mode. If camera is inside an override zone, it will also be used for all drawables.
  57. void SetOverride(bool enable);
  58. /// Set ambient gradient mode. In gradient mode ambient color is interpolated from neighbor zones.
  59. void SetAmbientGradient(bool enable);
  60. /// Return inverse world transform.
  61. const Matrix3x4& GetInverseWorldTransform() const;
  62. /// Return zone's own ambient color, disregarding gradient mode.
  63. const Color& GetAmbientColor() const { return ambientColor_; }
  64. /// Return ambient start color. Not safe to call from worker threads due to possible octree query.
  65. const Color& GetAmbientStartColor();
  66. /// Return ambient end color. Not safe to call from worker threads due to possible octree query.
  67. const Color& GetAmbientEndColor();
  68. /// Return fog color.
  69. const Color& GetFogColor() const { return fogColor_; }
  70. /// Return fog start distance.
  71. float GetFogStart() const { return fogStart_; }
  72. /// Return fog end distance.
  73. float GetFogEnd() const { return fogEnd_; }
  74. /// Return zone priority.
  75. int GetPriority() const { return priority_; }
  76. /// Return override mode.
  77. bool GetOverride() const { return override_; }
  78. /// Return whether ambient gradient mode is enabled.
  79. bool GetAmbientGradient() const { return ambientGradient_; }
  80. /// Check whether a point is inside.
  81. bool IsInside(const Vector3& point) const;
  82. protected:
  83. /// Transform has changed. Clear cached zone of any contained drawables.
  84. virtual void OnMarkedDirty(Node* node);
  85. /// Recalculate the world-space bounding box.
  86. virtual void OnWorldBoundingBoxUpdate();
  87. /// Recalculate the ambient gradient colors from neighbor zones. Not safe to call from worker threads due to octree query.
  88. void UpdateAmbientGradient();
  89. /// Cached inverse world transform matrix.
  90. mutable Matrix3x4 inverseWorld_;
  91. /// Inverse transform dirty flag.
  92. mutable bool inverseWorldDirty_;
  93. /// Override mode flag.
  94. bool override_;
  95. /// Ambient gradient mode flag.
  96. bool ambientGradient_;
  97. /// Last world-space bounding box.
  98. BoundingBox lastWorldBoundingBox_;
  99. /// Ambient color.
  100. Color ambientColor_;
  101. /// Cached ambient start color.
  102. Color ambientStartColor_;
  103. /// Cached ambient end color.
  104. Color ambientEndColor_;
  105. /// Fog color.
  106. Color fogColor_;
  107. /// Fog start distance.
  108. float fogStart_;
  109. /// Fog end distance.
  110. float fogEnd_;
  111. /// Zone priority.
  112. int priority_;
  113. /// Last zone used for ambient gradient start color.
  114. WeakPtr<Zone> lastAmbientStartZone_;
  115. /// Last zone used for ambient gradient end color.
  116. WeakPtr<Zone> lastAmbientEndZone_;
  117. };
  118. }