OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgrePCZone.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 PCZone.h - Portal Connected Zone (PCZone) header file.
28 -----------------------------------------------------------------------------
29 Portal Connected Zones are spatial constructs for partitioning space into cross
30 connected zones. Each zone is connected to other zones using Portal nodes.
31 
32 Zones contain references to nodes which touch them. However, zones do not
33 care how nodes are arranged hierarchically. Whether or not a node is
34 referenced as being part of a zone is entirely determined by the user or
35 by the node crossing a portal into or out-of the zone.
36 
37 Nodes can be referenced by several zones at once, but only one zone is
38 considered the "home" zone of the node. Home zone is determined by location
39 of the centerpoint of the node. Nodes can "touch" other zones if the node
40 BV intersects a portal (this is also called "visiting" a zone). Nodes keep
41 a pointer to their home zone and a list of references to zones they are
42 "visiting".
43 -----------------------------------------------------------------------------
44 begin : Tue Feb 20 2007
45 author : Eric Cha
46 email : ericc@xenopi.com
47 Code Style Update :
48 -----------------------------------------------------------------------------
49 */
50 
51 #ifndef PCZONE_H
52 #define PCZONE_H
53 
54 #include "OgrePCZPrerequisites.h"
55 #include "OgrePCZSceneNode.h"
56 #include "OgrePCZCamera.h"
57 #include "OgrePCZFrustum.h"
58 
59 namespace Ogre
60 {
61 
62  class PCZone;
63  class Portal;
64  class AntiPortal;
65  class PCZSceneNode;
66  class PCZSceneManager;
67  class PCZLight;
68 
77 
83  {
84  public:
85 
87  {
88  HOME_NODE_LIST = 1,
89  VISITOR_NODE_LIST = 2
90  };
91 
92  PCZone( PCZSceneManager *, const String& );
93  virtual ~PCZone();
94 
95  // get the zone type name (ex: "ZoneType_Terrain")
96  const String& getZoneTypeName() const { return mZoneTypeName; }
97 
98  // Returns the name of the zone
99  const String& getName(void) const { return mName; }
100 
101  /* get a pointer to the enclosure node for this PCZone
102  */
103  SceneNode * getEnclosureNode(void) {return mEnclosureNode;}
104 
107  void setHasSky(bool yesno) {mHasSky = yesno;}
108 
109  /* return whether or not this zone has sky
110  */
111  bool hasSky(void) {return mHasSky;}
112 
113  /* set the lastVisibleFrame counter */
114  void setLastVisibleFrame(unsigned long frameCount) {mLastVisibleFrame = frameCount;}
115 
116  /* get the lastVisibleFrame counter value */
117  unsigned long getLastVisibleFrame(void) {return mLastVisibleFrame;}
118 
119  /* set the lastVisibleFromCamera pointer */
120  void setLastVisibleFromCamera(PCZCamera * camera) {mLastVisibleFromCamera = camera;}
121 
122  /* get the lastVisibleFromCamera pointer */
123  PCZCamera* getLastVisibleFromCamera() {return mLastVisibleFromCamera;}
124 
125  public:
128  virtual void setEnclosureNode(PCZSceneNode *) = 0;
129 
135  virtual void _addNode( PCZSceneNode * ) = 0;
136 
139  virtual void removeNode( PCZSceneNode * ) = 0;
140 
143  virtual void _clearNodeLists(short nodeListTypes);
144 
148  virtual bool requiresZoneSpecificNodeData(void) = 0;
149 
152  virtual void createNodeZoneData(PCZSceneNode *);
153 
156  virtual Portal * findMatchingPortal(Portal *);
157 
158  /* Add a portal to the zone */
159  virtual void _addPortal(Portal* newPortal);
160 
161  /* Remove a portal from the zone */
162  virtual void _removePortal(Portal* removePortal);
163 
164  /* Add an anti portal to the zone */
165  virtual void _addAntiPortal(AntiPortal* newAntiPortal);
166 
167  /* Remove an anti portal from the zone */
168  virtual void _removeAntiPortal(AntiPortal* removeAntiPortal);
169 
172  virtual void _checkNodeAgainstPortals(PCZSceneNode *, Portal * ) = 0;
173 
176  virtual void _checkLightAgainstPortals(PCZLight *,
177  unsigned long,
178  PCZFrustum *,
179  Portal *) = 0;
180 
181  /* Update the zone data for each portal
182  */
183  virtual void updatePortalsZoneData(void) = 0;
184 
186  virtual void dirtyNodeByMovingPortals(void) = 0;
187 
188  /* Update a node's home zone */
189  virtual PCZone * updateNodeHomeZone(PCZSceneNode * pczsn, bool allowBackTouces) = 0;
190 
196  virtual void findVisibleNodes(PCZCamera *,
197  NodeList & visibleNodeList,
198  RenderQueue * queue,
199  VisibleObjectsBoundsInfo* visibleBounds,
200  bool onlyShadowCasters,
201  bool displayNodes,
202  bool showBoundingBoxes) = 0;
203 
204  /* Functions for finding Nodes that intersect various shapes */
205  virtual void _findNodes( const AxisAlignedBox &t,
207  PortalList &visitedPortals,
208  bool includeVisitors,
209  bool recurseThruPortals,
210  PCZSceneNode *exclude) = 0;
211  virtual void _findNodes( const Sphere &t,
213  PortalList &visitedPortals,
214  bool includeVisitors,
215  bool recurseThruPortals,
216  PCZSceneNode *exclude ) = 0;
217  virtual void _findNodes( const PlaneBoundedVolume &t,
219  PortalList &visitedPortals,
220  bool includeVisitors,
221  bool recurseThruPortals,
222  PCZSceneNode *exclude ) = 0;
223  virtual void _findNodes( const Ray &t,
225  PortalList &visitedPortals,
226  bool includeVisitors,
227  bool recurseThruPortals,
228  PCZSceneNode *exclude ) = 0;
229 
231  virtual bool setOption( const String &, const void * ) = 0;
235  virtual void notifyCameraCreated( Camera* c ) = 0;
236  /* called by PCZSM during setWorldGeometryRenderQueue() */
237  virtual void notifyWorldGeometryRenderQueue(uint8 qid) = 0;
238  /* Called when a _renderScene is called in the SceneManager */
239  virtual void notifyBeginRenderScene(void) = 0;
240  /* called by PCZSM during setZoneGeometry() */
241  virtual void setZoneGeometry(const String &filename, PCZSceneNode * parentNode) = 0;
242  /* get the world coordinate aabb of the zone */
243  virtual void getAABB(AxisAlignedBox &);
244  void setPortalsUpdated(bool updated) { mPortalsUpdated = updated; }
245  bool getPortalsUpdated(void) { return mPortalsUpdated; }
246  /* get & set the user data */
247  void * getUserData(void) {return mUserData;}
248  void setUserData(void * userData) {mUserData = userData;}
253  // pointer to the pcz scene manager that created this zone
255 
256  protected:
259  {
261  PortalSortDistance(const Vector3& inCameraPosition) : cameraPosition(inCameraPosition)
262  { }
263 
264  bool _OgrePCZPluginExport operator()(const PortalBase* p1, const PortalBase* p2) const
265  {
266  Real depth1 = p1->getDerivedCP().squaredDistance(cameraPosition);
267  Real depth2 = p2->getDerivedCP().squaredDistance(cameraPosition);
268  return (depth1 < depth2);
269  }
270  };
271 
272  // name of the zone (must be unique)
276  // frame counter for visibility
277  unsigned long mLastVisibleFrame;
278  // last camera which this zone was visible to
280  // flag determining whether or not this zone has sky in it.
281  bool mHasSky;
282  //SceneNode which corresponds to the enclosure for this zone
284  // list of SceneNodes contained in this particular PCZone
286  // list of SceneNodes visiting this particular PCZone
288  // flag recording whether any portals in this zone have moved
290  // user defined data pointer - NOT allocated or deallocated by the zone!
291  // you must clean it up yourself!
292  void * mUserData;
293 
294  };
295 
297  {
298  public:
302  virtual ~ZoneData();
304  virtual void update(void);
305  public:
308 
309  };
310 
311 }
312 
313 #endif
314 
315 
316 
vector< SceneNode * >::type NodeList
Definition: OgrePCZone.h:74
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
unsigned char uint8
Definition: OgrePlatform.h:272
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
const Vector3 & getDerivedCP() const
Get the position (centerpoint) of the portal in world coordinates.
AntiPortal datastructure for occlusion culling.
set< PCZSceneNode * >::type PCZSceneNodeList
float Real
Software floating point type.
std::vector< T, A > type
map< String, SceneNode * >::type SceneNodeList
Definition: OgrePCZone.h:76
Specialized frustum shaped culling volume that has culling planes created from portals.
const String & getZoneTypeName() const
Definition: OgrePCZone.h:96
void * getUserData(void)
Definition: OgrePCZone.h:247
void setLastVisibleFrame(unsigned long frameCount)
Definition: OgrePCZone.h:114
Real squaredDistance(const Vector3 &rhs) const
Returns the square of the distance to another vector.
Definition: OgreVector3.h:394
bool getPortalsUpdated(void)
Definition: OgrePCZone.h:245
PCZCamera * getLastVisibleFromCamera()
Definition: OgrePCZone.h:123
AntiPortalList mAntiPortals
Definition: OgrePCZone.h:252
PortalSortDistance(const Vector3 &inCameraPosition)
Definition: OgrePCZone.h:261
A 3D box aligned with the x/y/z axes.
PortalBase - Base class to Portal and AntiPortal classes.
PCZSceneNodeList mHomeNodeList
Definition: OgrePCZone.h:285
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
bool _OgrePCZPluginExport operator()(const PortalBase *p1, const PortalBase *p2) const
Definition: OgrePCZone.h:264
Portal datastructure for connecting zones.
Definition: OgrePortal.h:51
PCZSceneManager * mPCZSM
Definition: OgrePCZone.h:254
String mName
Definition: OgrePCZone.h:273
PCZSceneNodeList mVisitorNodeList
Definition: OgrePCZone.h:287
vector< PortalBase * >::type PortalBaseList
Definition: OgrePCZone.h:73
PCZSceneNode * mAssociatedNode
Definition: OgrePCZone.h:307
unsigned long mLastVisibleFrame
Definition: OgrePCZone.h:277
void setHasSky(bool yesno)
if sky should be drawn with this zone
Definition: OgrePCZone.h:107
SceneNode * mEnclosureNode
Definition: OgrePCZone.h:283
Specialized version of Ogre::Light which caches which zones the light affects.
Definition: OgrePCZLight.h:52
bool hasSky(void)
Definition: OgrePCZone.h:111
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
PCZCamera * mLastVisibleFromCamera
Definition: OgrePCZone.h:279
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
#define _OgrePCZPluginExport
SceneNode * getEnclosureNode(void)
Definition: OgrePCZone.h:103
const String & getName(void) const
Definition: OgrePCZone.h:99
void setLastVisibleFromCamera(PCZCamera *camera)
Definition: OgrePCZone.h:120
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
list< PCZone * >::type PCZoneList
Definition: OgrePCZone.h:70
void setPortalsUpdated(bool updated)
Definition: OgrePCZone.h:244
unsigned long getLastVisibleFrame(void)
Definition: OgrePCZone.h:117
Represents a convex volume bounded by planes.
list< Portal * >::type PortalList
Definition: OgrePCZone.h:71
list< AntiPortal * >::type AntiPortalList
Definition: OgrePCZone.h:72
String mZoneTypeName
Zone type name.
Definition: OgrePCZone.h:275
PortalList mPortals
list of Portals which this zone contains (each portal leads to another zone)
Definition: OgrePCZone.h:251
void setUserData(void *userData)
Definition: OgrePCZone.h:248
Class to manage the scene object rendering queue.
Portal-Connected Zone datastructure for managing scene nodes.
Definition: OgrePCZone.h:82
_StringBase String
Binary pradicate for portal <-> camera distance sorting.
Definition: OgrePCZone.h:258
PCZone * mAssociatedZone
Definition: OgrePCZone.h:306
Structure collecting together information about the visible objects that have been discovered in a sc...
map< String, PCZone * >::type ZoneMap
Definition: OgrePCZone.h:67
Specialized SceneManager that uses Portal-Connected-Zones to divide the scene spatially.
bool mPortalsUpdated
Definition: OgrePCZone.h:289
Specialized viewpoint from which an PCZone Scene can be rendered.
Definition: OgrePCZCamera.h:56
void * mUserData
Definition: OgrePCZone.h:292