sceneSimpleZone.h
Engine/source/scene/zones/sceneSimpleZone.h
Classes:
class
Abstract base class for a zone space that contains only a single zone.
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 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 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell 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 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _SCENESIMPLEZONE_H_ 25#define _SCENESIMPLEZONE_H_ 26 27#ifndef _SCENEZONESPACE_H_ 28#include "scene/zones/sceneZoneSpace.h" 29#endif 30 31#ifndef _MORIENTEDBOX_H_ 32#include "math/mOrientedBox.h" 33#endif 34 35 36class SceneRenderState; 37class BaseMatInstance; 38 39 40/// Abstract base class for a zone space that contains only a single zone. 41/// 42/// Simple zones are required to be convex. 43class SceneSimpleZone : public SceneZoneSpace 44{ 45 public: 46 47 typedef SceneZoneSpace Parent; 48 49 protected: 50 51 enum 52 { 53 AmbientMask = Parent::NextFreeMask << 0, ///< Ambient light color setting has changed. 54 NextFreeMask = Parent::NextFreeMask << 1, 55 }; 56 57 /// @name Ambient Lighting 58 /// @{ 59 60 /// If this is true, then the zone defines its own ambient 61 /// light color in #mAmbientColor. 62 bool mUseAmbientLightColor; 63 64 /// Ambient light color in this zone. 65 LinearColorF mAmbientLightColor; 66 67 /// @} 68 69 /// @name Transforms 70 /// @{ 71 72 /// Whether the zone has been rotated. This is used to fasttrack overlap 73 /// tests to avoid doing an OBB/AABB intersection test when we can simply 74 /// use a much quicker AABB/AABB intersection test on the world boxes of 75 /// both objects. 76 bool mIsRotated; 77 78 /// The OBB for the zone. 79 OrientedBox3F mOrientedWorldBox; 80 81 /// @} 82 83 /// Return the oriented bounding box for the zone. 84 const OrientedBox3F& _getOrientedWorldBox() const { return mOrientedWorldBox; } 85 86 /// Update the OBB for the zone. 87 virtual void _updateOrientedWorldBox() { mOrientedWorldBox.set( getTransform(), getScale() ); } 88 89 // SceneObject. 90 virtual bool onSceneAdd(); 91 92 public: 93 94 SceneSimpleZone(); 95 96 /// @name Ambient Lighting 97 /// @{ 98 99 /// Return true if the zone defines its own ambient light color. 100 bool useAmbientLightColor() const { return mUseAmbientLightColor; } 101 102 /// Set whether a custom ambient light color is active in this zone. 103 void setUseAmbientLightColor( bool value ); 104 105 /// Return the ambient light color for this zone. 106 LinearColorF getAmbientLightColor() const { return mAmbientLightColor; } 107 108 /// Set the ambient light color for the zone. 109 /// @note This only takes effect if useAmbientLightColor() return true. 110 /// @see setUseAmbientLightColor 111 void setAmbientLightColor( const LinearColorF& color ); 112 113 /// @} 114 115 /// @name Inherited 116 /// @{ 117 118 // SimObject. 119 virtual String describeSelf() const; 120 121 static void initPersistFields(); 122 123 // NetObject 124 virtual U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream ); 125 virtual void unpackUpdate( NetConnection *conn, BitStream *stream ); 126 127 // SceneObject 128 virtual void prepRenderImage( SceneRenderState* state ); 129 virtual void setTransform( const MatrixF& mat ); 130 131 // SceneZoneSpace. 132 virtual U32 getPointZone( const Point3F &p ); 133 virtual bool getOverlappingZones( const Box3F& aabb, U32* outZones, U32& outNumZones ); 134 virtual void traverseZones( SceneTraversalState* state ); 135 virtual bool getZoneAmbientLightColor( U32 zone, LinearColorF& outColor ) const; 136 virtual void traverseZones( SceneTraversalState* state, U32 startZoneId ); 137 138 /// @} 139 140 private: 141 142 static bool _setUseAmbientLightColor( void* object, const char* index, const char* data ); 143 static bool _setAmbientLightColor( void* object, const char* index, const char* data ); 144}; 145 146#endif // !_SCENESIMPLEZONE_H_ 147