Zone.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  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 deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // 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 FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Color.h"
  25. #include "Drawable.h"
  26. /// %Component that describes global rendering properties
  27. class Zone : public Drawable
  28. {
  29. OBJECT(Zone);
  30. public:
  31. /// Construct.
  32. Zone(Context* context);
  33. /// Destruct.
  34. virtual ~Zone();
  35. /// Register object factory. Drawable must be registered first.
  36. static void RegisterObject(Context* context);
  37. /// Handle attribute write access.
  38. virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& src);
  39. /// Add debug geometry to the debug renderer.
  40. virtual void DrawDebugGeometry(DebugRenderer* debug, bool depthTest);
  41. /// %Set bounding box. Will be used as an oriented bounding box to test whether objects or the camera are inside.
  42. void SetBoundingBox(const BoundingBox& box);
  43. /// %Set ambient color
  44. void SetAmbientColor(const Color& color);
  45. /// %Set fog color.
  46. void SetFogColor(const Color& color);
  47. /// %Set fog start distance.
  48. void SetFogStart(float start);
  49. /// %Set fog end distance.
  50. void SetFogEnd(float end);
  51. /// %Set zone priority. If an object or camera is inside several zones, the one with highest priority is used.
  52. void SetPriority(int priority);
  53. /// %Set override mode. If camera is inside an override zone, it will also be used for all drawables.
  54. void SetOverride(bool enable);
  55. /// %Set ambient gradient mode. In gradient mode ambient color is interpolated from neighbor zones.
  56. void SetAmbientGradient(bool enable);
  57. /// Return bounding box.
  58. const BoundingBox& GetBoundingBox() const { return boundingBox_; }
  59. /// Return zone's own ambient color, disregarding gradient mode.
  60. const Color& GetAmbientColor() const { return ambientColor_; }
  61. /// Return ambient start color.
  62. const Color& GetAmbientStartColor();
  63. /// Return ambient end color.
  64. const Color& GetAmbientEndColor();
  65. /// Return fog color.
  66. const Color& GetFogColor() const { return fogColor_; }
  67. /// Return fog start distance.
  68. float GetFogStart() const { return fogStart_; }
  69. /// Return fog end distance.
  70. float GetFogEnd() const { return fogEnd_; }
  71. /// Return zone priority.
  72. int GetPriority() const { return priority_; }
  73. /// Return override mode.
  74. bool GetOverride() const { return override_; }
  75. /// Return whether ambient gradient mode is enabled.
  76. bool GetAmbientGradient() const { return ambientGradient_; }
  77. /// Check whether a point is inside.
  78. virtual bool IsInside(const Vector3& point);
  79. protected:
  80. /// Transform has changed. Clear cached zone of any contained drawables.
  81. virtual void OnMarkedDirty(Node* node);
  82. /// Recalculate the world-space bounding box.
  83. virtual void OnWorldBoundingBoxUpdate();
  84. /// Recalculate the ambient gradient colors from neighbor zones.
  85. void UpdateAmbientGradient();
  86. /// Last zone used for ambient gradient start color.
  87. WeakPtr<Zone> lastAmbientStartZone_;
  88. /// Last zone used for ambient gradient end color.
  89. WeakPtr<Zone> lastAmbientEndZone_;
  90. /// Bounding box.
  91. BoundingBox boundingBox_;
  92. /// Last world-space bounding box.
  93. BoundingBox lastWorldBoundingBox_;
  94. /// Ambient color.
  95. Color ambientColor_;
  96. /// Cached ambient start color.
  97. Color ambientStartColor_;
  98. /// Cached ambient end color.
  99. Color ambientEndColor_;
  100. /// Fog color.
  101. Color fogColor_;
  102. /// Fog start distance.
  103. float fogStart_;
  104. /// Fog end distance.
  105. float fogEnd_;
  106. /// Zone priority.
  107. int priority_;
  108. /// Override mode flag.
  109. bool override_;
  110. /// Ambient gradient mode flag.
  111. bool ambientGradient_;
  112. };