OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgrePortalBase.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-2011 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 PortalBase.h - PortalBase is the base class for Portal and AntiPortal.
28 
29 */
30 
31 #ifndef PORTALBASE_H
32 #define PORTALBASE_H
33 
34 #include "OgrePCZPrerequisites.h"
35 #include "OgrePCZSceneNode.h"
36 #include "OgreMovableObject.h"
37 #include "OgreAxisAlignedBox.h"
38 #include "OgreCapsule.h"
39 #include "OgreSphere.h"
40 
41 namespace Ogre
42 {
43  class PCZSceneNode;
44 
47  {
48  public:
50  {
54  };
55 
57  PortalBase(const String& name, const PORTAL_TYPE type = PORTAL_TYPE_QUAD);
58 
60  virtual ~PortalBase();
61 
63  virtual const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
65  virtual const Sphere& getWorldBoundingSphere(bool derive = false) const;
66 
68  void setNode(SceneNode* sn);
70  void setCurrentHomeZone(PCZone* zone);
72  void setNewHomeZone(PCZone* zone);
73 
75  void setCorner(int index, const Vector3& point);
77  void setCorners(const Vector3* corners);
82  void setDirection(const Vector3 &d)
83  {
84  switch (mType)
85  {
86  default:
87  case PORTAL_TYPE_QUAD:
89  "Cannot setDirection on a Quad type portal",
90  "Portal::setDirection");
91  break;
92  case PORTAL_TYPE_AABB:
93  case PORTAL_TYPE_SPHERE:
94  if (d != Vector3::UNIT_Z &&
96  {
98  "Valid parameters are Vector3::UNIT_Z or Vector3::NEGATIVE_UNIT_Z",
99  "Portal::setDirection");
100  return;
101  }
102  mDirection = d;
103  break;
104  }
105  }
107  void calcDirectionAndRadius() const;
108 
110  const PORTAL_TYPE getType() const {return mType;}
112  Real getRadius() const;
113 
116  { return mCurrentHomeZone; }
119  { return mNewHomeZone; }
120 
122  const Vector3& getCorner(int index) const
123  { return mCorners[index]; }
125  const Vector3& getDirection() const
126  { return mDirection; }
127 
129  const Vector3& getDerivedCorner(int index) const
130  { return mDerivedCorners[index]; }
133  { return mDerivedDirection; }
135  const Vector3& getDerivedCP() const
136  { return mDerivedCP; }
138  const Sphere& getDerivedSphere() const
139  { return mDerivedSphere; }
141  const Plane& getDerivedPlane() const
142  { return mDerivedPlane; }
143 
145  const Vector3& getPrevDerivedCP() const
146  { return mPrevDerivedCP; }
148  const Plane& getPrevDerivedPlane() const
149  { return mPrevDerivedPlane; }
150 
152  void updateDerivedValues() const;
154  void adjustNodeToMatch(SceneNode* node);
156  void setEnabled(bool value)
157  { mEnabled = value; }
159  bool getEnabled() const {return mEnabled;}
160 
161 
163  {
167  INTERSECT_CROSS
168  };
170  bool intersects(const AxisAlignedBox& aab);
171 
173  bool intersects(const Sphere& sphere);
174 
176  bool intersects(const PlaneBoundedVolume& pbv);
177 
179  bool intersects(const Ray& ray);
180 
184  PortalIntersectResult intersects(PCZSceneNode* sn);
185 
187  bool crossedPortal(const PortalBase* otherPortal);
189  bool closeTo(const PortalBase* otherPortal);
190 
192  const AxisAlignedBox& getBoundingBox() const;
193 
196  { return getRadius(); }
197 
200  { /* Draw debug info if needed? */ }
201 
203  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false)
204  { }
205 
208  {
209  updateDerivedValues();
210  mWasMoved = true;
211  }
212 
214  void _notifyAttached(Node* parent, bool isTagPoint = false)
215  {
216  MovableObject::_notifyAttached(parent, isTagPoint);
217  mDerivedUpToDate = false;
218  }
219 
221  bool needUpdate();
222 
224  const Capsule& getCapsule() const;
225 
227  const AxisAlignedBox& getAAB();
228 
229  protected:
230  // Type of portal (quad, aabb, or sphere)
237  // NOTE: there are 4 corners if the portal is a quad type
238  // there are 2 corners if the portal is an AABB type
239  // there are 2 corners if the portal is a sphere type (center and point on sphere)
242  // NOTE: For a Quad portal, determined by the 1st 3 corners.
243  // NOTE: For AABB & SPHERE portals, we only have "inward" or "outward" cases.
244  // To indicate "outward", the Direction is UNIT_Z
245  // to indicate "inward", the Direction is NEGATIVE_UNIT_Z
248  // NOTE: For aabb portals, this value is the distance from the center of the aab to a corner
249  mutable Real mRadius;
250  // Local Centerpoint of the portal
251  mutable Vector3 mLocalCP;
253  // NOTE: there are 4 corners if the portal is a quad type
254  // there are 2 corners if the portal is an AABB type (min corner & max corner)
255  // there are 2 corners if the portal is a sphere type (center and point on sphere)
258  // NOTE: Only applicable for a Quad portal
265  // NOTE: Only applicable for a Quad portal
270  // NOTE: Only applicable for a Quad portal
273  mutable bool mLocalsUpToDate;
275  mutable bool mDerivedUpToDate;
276  // previous world transform
278  // flag defining if portal is enabled or disabled.
279  bool mEnabled;
280  // cache of portal's capsule.
282  // cache of portal's AAB that contains the bound of portal movement.
284  // cache of portal's previous AAB.
286  // cache of portal's local AAB.
288  // defined if portal was moved previously.
289  mutable bool mWasMoved;
290  };
291 
294  {
295  protected:
297  PortalBase::PORTAL_TYPE getPortalType(const NameValuePairList* params);
298 
299  };
300 
301 }
302 
303 #endif
Representation of a ray in space, i.e.
Definition: OgreRay.h:46
const Vector3 & getDerivedCP() const
Get the position (centerpoint) of the portal in world coordinates.
Real mRadius
Radius of the sphere enclosing the portal.
static const Vector3 UNIT_Z
Definition: OgreVector3.h:777
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
const Vector3 & getPrevDerivedCP() const
Get the previous position (centerpoint) of the portal in world coordinates.
PCZone * mCurrentHomeZone
Zone this portal is currently owned by (in)
float Real
Software floating point type.
Vector3 * mDerivedCorners
Derived (world coordinates) Corners of the portal.
map< String, String >::type NameValuePairList
Name / value parameter pair (first = name, second = value)
Definition: OgreCommon.h:524
Defines a plane in 3D space.
Definition: OgrePlane.h:61
const Vector3 & getCorner(int index) const
Get the coordinates of one of the portal corners in local space.
Vector3 mDerivedCP
Derived (world coordinates) of portal (center point)
PCZone * getCurrentHomeZone()
Get the Zone the Portal is currently "in".
Vector3 * mCorners
Corners of the portal - coordinates are relative to the sceneNode.
Plane mDerivedPlane
Derived (world coordinates) Plane of the portal.
const Vector3 & getDerivedCorner(int index) const
Get the derived (world) coordinates of one of the portal corners.
Plane mPrevDerivedPlane
Previous frame derived plane.
PORTAL_TYPE mType
A 3D box aligned with the x/y/z axes.
void _updateRenderQueue(RenderQueue *queue)
const PORTAL_TYPE getType() const
get the type of portal
void _notifyMoved()
Called when scene node moved.
Interface definition for a factory class which produces a certain kind of MovableObject, and can be registered with Root in order to allow all clients to produce new instances of this object, integrated with the standard Ogre processing.
PCZone * mNewHomeZone
zone to transfer this portal to
PortalBase - Base class to Portal and AntiPortal classes.
const Plane & getDerivedPlane() const
Get the portal plane in world coordinates.
Abstract class defining a movable object in a scene.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:57
bool mDerivedUpToDate
flag indicating whether or not derived values are up-to-date
PCZone * getNewHomeZone()
Get the Zone the Portal should be moved to.
Vector3 mDerivedDirection
Derived (world coordinates) direction of the portal.
Matrix4 mPrevWorldTransform
bool getEnabled() const
check if portal is enabled
void setEnabled(bool value)
enable the portal
AxisAlignedBox mLocalPortalAAB
static const Vector3 NEGATIVE_UNIT_Z
Definition: OgreVector3.h:780
void setDirection(const Vector3 &d)
Set the "inward/outward norm" direction of AAB or SPHERE portals NOTE: UNIT_Z = "outward" norm...
void _notifyAttached(Node *parent, bool isTagPoint=false)
Called when attached to a scene node.
A sphere primitive, mostly used for bounds checking.
Definition: OgreSphere.h:51
#define OGRE_EXCEPT(num, desc, src)
#define _OgrePCZPluginExport
Vector3 mPrevDerivedCP
Previous frame portal cp (in world coordinates)
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
Real getBoundingRadius() const
virtual void _notifyAttached(Node *parent, bool isTagPoint=false)
Internal method called to notify the object that it has been attached to a node.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
AxisAlignedBox mPortalAAB
Represents a convex volume bounded by planes.
const Vector3 & getDirection() const
Get the direction vector of the portal in local space.
const Vector3 & getDerivedDirection() const
Get the direction of the portal in world coordinates.
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Class to manage the scene object rendering queue.
Portal-Connected Zone datastructure for managing scene nodes.
Definition: OgrePCZone.h:82
_StringBase String
Vector3 mDirection
Direction ("Norm") of the portal -.
AxisAlignedBox mPrevPortalAAB
Factory object for creating Portal instances.
const Plane & getPrevDerivedPlane() const
Get the previous portal plane in world coordinates.
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:62
Sphere mDerivedSphere
Sphere of the portal centered on the derived CP.
const Sphere & getDerivedSphere() const
Get the sphere centered on the derived CP of the portal in world coordinates.
bool mLocalsUpToDate
flag indicating whether or not local values are up-to-date