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-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef __MovableObject_H__
|
---|
27 | #define __MovableObject_H__
|
---|
28 |
|
---|
29 | // Precompiler options
|
---|
30 | #include "OgrePrerequisites.h"
|
---|
31 | #include "OgreRenderQueue.h"
|
---|
32 | #include "OgreAxisAlignedBox.h"
|
---|
33 | #include "OgreSphere.h"
|
---|
34 | #include "OgreShadowCaster.h"
|
---|
35 |
|
---|
36 | namespace Ogre {
|
---|
37 |
|
---|
38 |
|
---|
39 | /** Abstract class definining a movable object in a scene.
|
---|
40 | @remarks
|
---|
41 | Instances of this class are discrete, relatively small, movable objects
|
---|
42 | which are attached to SceneNode objects to define their position.
|
---|
43 | */
|
---|
44 | class _OgreExport MovableObject : public ShadowCaster
|
---|
45 | {
|
---|
46 | protected:
|
---|
47 | /// node to which this object is attached
|
---|
48 | Node* mParentNode;
|
---|
49 | bool mParentIsTagPoint;
|
---|
50 | /// Is this object visible?
|
---|
51 | bool mVisible;
|
---|
52 | /// User defined object which is linked to this object
|
---|
53 | UserDefinedObject *mUserObject;
|
---|
54 | /// The render queue to use when rendering this object
|
---|
55 | RenderQueueGroupID mRenderQueueID;
|
---|
56 | /// Flags whether the RenderQueue's default should be used.
|
---|
57 | bool mRenderQueueIDSet;
|
---|
58 | /// Flags determining whether this object is included / excluded from scene queries
|
---|
59 | unsigned long mQueryFlags;
|
---|
60 | /// Cached world AABB of this object
|
---|
61 | mutable AxisAlignedBox mWorldAABB;
|
---|
62 | // Cached world bounding sphere
|
---|
63 | mutable Sphere mWorldBoundingSphere;
|
---|
64 | /// World space AABB of this object's dark cap
|
---|
65 | mutable AxisAlignedBox mWorldDarkCapBounds;
|
---|
66 | /// Does this object cast shadows?
|
---|
67 | bool mCastShadows;
|
---|
68 |
|
---|
69 |
|
---|
70 | public:
|
---|
71 | /// Constructor
|
---|
72 | MovableObject();
|
---|
73 |
|
---|
74 | /** Virtual destructor - read Scott Meyers if you don't know why this is needed.
|
---|
75 | */
|
---|
76 | virtual ~MovableObject();
|
---|
77 |
|
---|
78 | /** Returns the name of this object. */
|
---|
79 | virtual const String& getName(void) const = 0;
|
---|
80 |
|
---|
81 | /** Returns the type name of this object. */
|
---|
82 | virtual const String& getMovableType(void) const = 0;
|
---|
83 |
|
---|
84 | /** Returns the node to which this object is attached.
|
---|
85 | @remarks
|
---|
86 | A MovableObject may be attached to either a SceneNode or to a TagPoint,
|
---|
87 | the latter case if it's attached to a bone on an animated entity.
|
---|
88 | Both are Node subclasses so this method will return either.
|
---|
89 | */
|
---|
90 | virtual Node* getParentNode(void) const;
|
---|
91 |
|
---|
92 | /** Returns the scene node to which this object is attached.
|
---|
93 | @remarks
|
---|
94 | A MovableObject may be attached to either a SceneNode or to a TagPoint,
|
---|
95 | the latter case if it's attached to a bone on an animated entity.
|
---|
96 | This method will return the scene node of the parent entity
|
---|
97 | if the latter is true.
|
---|
98 | */
|
---|
99 | virtual SceneNode* getParentSceneNode(void) const;
|
---|
100 |
|
---|
101 | /** Internal method called to notify the object that it has been attached to a node.
|
---|
102 | */
|
---|
103 | virtual void _notifyAttached(Node* parent, bool isTagPoint = false);
|
---|
104 |
|
---|
105 | /** Returns true if this object is attached to a SceneNode or TagPoint. */
|
---|
106 | virtual bool isAttached(void) const;
|
---|
107 |
|
---|
108 | /** Returns true if this object is attached to a SceneNode or TagPoint,
|
---|
109 | and this SceneNode / TagPoint is currently in an active part of the
|
---|
110 | scene graph. */
|
---|
111 | virtual bool isInScene(void) const;
|
---|
112 |
|
---|
113 | /** Internal method to notify the object of the camera to be used for the next rendering operation.
|
---|
114 | @remarks
|
---|
115 | Certain objects may want to do specific processing based on the camera position. This method notifies
|
---|
116 | them incase they wish to do this.
|
---|
117 | */
|
---|
118 | virtual void _notifyCurrentCamera(Camera* cam) = 0;
|
---|
119 |
|
---|
120 | /** Retrieves the local axis-aligned bounding box for this object.
|
---|
121 | @remarks
|
---|
122 | This bounding box is in local coordinates.
|
---|
123 | */
|
---|
124 | virtual const AxisAlignedBox& getBoundingBox(void) const = 0;
|
---|
125 |
|
---|
126 | /** Retrieves the radius of the origin-centered bounding sphere
|
---|
127 | for this object.
|
---|
128 | */
|
---|
129 | virtual Real getBoundingRadius(void) const = 0;
|
---|
130 |
|
---|
131 | /** Retrieves the axis-aligned bounding box for this object in world coordinates. */
|
---|
132 | virtual const AxisAlignedBox& getWorldBoundingBox(bool derive = false) const;
|
---|
133 | /** Retrieves the worldspace bounding sphere for this object. */
|
---|
134 | virtual const Sphere& getWorldBoundingSphere(bool derive = false) const;
|
---|
135 | /** Internal method by which the movable object must add Renderable subclass instances to the rendering queue.
|
---|
136 | @remarks
|
---|
137 | The engine will call this method when this object is to be rendered. The object must then create one or more
|
---|
138 | Renderable subclass instances which it places on the passed in Queue for rendering.
|
---|
139 | */
|
---|
140 | virtual void _updateRenderQueue(RenderQueue* queue) = 0;
|
---|
141 |
|
---|
142 | /** Tells this object whether to be visible or not, if it has a renderable component.
|
---|
143 | @note An alternative approach of making an object invisible is to detach it
|
---|
144 | from it's SceneNode, or to remove the SceneNode entirely.
|
---|
145 | Detaching a node means that structurally the scene graph changes.
|
---|
146 | Once this change has taken place, the objects / nodes that have been
|
---|
147 | removed have less overhead to the visbility detection pass than simply
|
---|
148 | making the object invisible, so if you do this and leave the objects
|
---|
149 | out of the tree for a long time, it's faster. However, the act of
|
---|
150 | detaching / reattaching nodes is in itself more expensive than
|
---|
151 | setting an object visibility flag, since in the latter case
|
---|
152 | structural changes are not made. Therefore, small or frequent visbility
|
---|
153 | changes are best done using this method; large or more longer term
|
---|
154 | changes are best done by detaching.
|
---|
155 | */
|
---|
156 | virtual void setVisible(bool visible);
|
---|
157 |
|
---|
158 | /** Returns whether or not this object is supposed to be visible or not. */
|
---|
159 | virtual bool isVisible(void) const;
|
---|
160 |
|
---|
161 | /** Call this to associate your own custom user object instance with this MovableObject.
|
---|
162 | @remarks
|
---|
163 | By simply making your game / application object a subclass of UserDefinedObject, you
|
---|
164 | can establish a link between an OGRE instance of MovableObject and your own application
|
---|
165 | classes. Call this method to establish the link.
|
---|
166 | */
|
---|
167 | virtual void setUserObject(UserDefinedObject* obj) { mUserObject = obj; }
|
---|
168 | /** Retrieves a pointer to a custom application object associated with this movable by an earlier
|
---|
169 | call to setUserObject.
|
---|
170 | */
|
---|
171 | virtual UserDefinedObject* getUserObject(void) { return mUserObject; }
|
---|
172 |
|
---|
173 | /** Sets the render queue group this entity will be rendered through.
|
---|
174 | @remarks
|
---|
175 | Render queues are grouped to allow you to more tightly control the ordering
|
---|
176 | of rendered objects. If you do not call this method, all Entity objects default
|
---|
177 | to the default queue (RenderQueue::getDefaultQueueGroup), which is fine for most objects. You may want to alter this
|
---|
178 | if you want this entity to always appear in front of other objects, e.g. for
|
---|
179 | a 3D menu system or such.
|
---|
180 | @par
|
---|
181 | See RenderQueue for more details.
|
---|
182 | @param queueID Enumerated value of the queue group to use.
|
---|
183 | */
|
---|
184 | virtual void setRenderQueueGroup(RenderQueueGroupID queueID);
|
---|
185 |
|
---|
186 | /** Gets the queue group for this entity, see setRenderQueueGroup for full details. */
|
---|
187 | virtual RenderQueueGroupID getRenderQueueGroup(void) const;
|
---|
188 |
|
---|
189 | /// return the full transformation of the parent sceneNode or the attachingPoint node
|
---|
190 | virtual Matrix4 _getParentNodeFullTransform(void) const;
|
---|
191 |
|
---|
192 | /** Sets the query flags for this object.
|
---|
193 | @remarks
|
---|
194 | When performing a scene query, this object will be included or excluded according
|
---|
195 | to flags on the object and flags on the query. This is a bitwise value, so only when
|
---|
196 | a bit on these flags is set, will it be included in a query asking for that flag. The
|
---|
197 | meaning of the bits is application-specific.
|
---|
198 | */
|
---|
199 | virtual void setQueryFlags(unsigned long flags) { mQueryFlags = flags; }
|
---|
200 |
|
---|
201 | /** As setQueryFlags, except the flags passed as parameters are appended to the
|
---|
202 | existing flags on this object. */
|
---|
203 | virtual void addQueryFlags(unsigned long flags) { mQueryFlags |= flags; }
|
---|
204 |
|
---|
205 | /** As setQueryFlags, except the flags passed as parameters are removed from the
|
---|
206 | existing flags on this object. */
|
---|
207 | virtual void removeQueryFlags(unsigned long flags) { mQueryFlags &= ~flags; }
|
---|
208 |
|
---|
209 | /// Returns the query flags relevant for this object
|
---|
210 | virtual unsigned long getQueryFlags(void) const { return mQueryFlags; }
|
---|
211 |
|
---|
212 | /// Define a default implementation of method from ShadowCaster which implements no shadows
|
---|
213 | EdgeData* getEdgeList(void) { return NULL; }
|
---|
214 | /// Define a default implementation of method from ShadowCaster which implements no shadows
|
---|
215 | ShadowRenderableListIterator getShadowVolumeRenderableIterator(
|
---|
216 | ShadowTechnique shadowTechnique, const Light* light,
|
---|
217 | HardwareIndexBufferSharedPtr* indexBuffer,
|
---|
218 | bool extrudeVertices, Real extrusionDist, unsigned long flags = 0);
|
---|
219 |
|
---|
220 | /** Overridden member from ShadowCaster. */
|
---|
221 | const AxisAlignedBox& getLightCapBounds(void) const;
|
---|
222 | /** Overridden member from ShadowCaster. */
|
---|
223 | const AxisAlignedBox& getDarkCapBounds(const Light& light, Real dirLightExtrusionDist) const;
|
---|
224 | /** Sets whether or not this object will cast shadows.
|
---|
225 | @remarks
|
---|
226 | This setting simply allows you to turn on/off shadows for a given object.
|
---|
227 | An object will not cast shadows unless the scene supports it in any case
|
---|
228 | (see SceneManager::setShadowTechnique), and also the material which is
|
---|
229 | in use must also have shadow casting enabled. By default all entities cast
|
---|
230 | shadows. If, however, for some reason you wish to disable this for a single
|
---|
231 | object then you can do so using this method.
|
---|
232 | @note This method normally refers to objects which block the light, but
|
---|
233 | since Light is also a subclass of MovableObject, in that context it means
|
---|
234 | whether the light causes shadows itself.
|
---|
235 | */
|
---|
236 | void setCastShadows(bool enabled) { mCastShadows = enabled; }
|
---|
237 | /** Returns whether shadow casting is enabled for this object. */
|
---|
238 | bool getCastShadows(void) const { return mCastShadows; }
|
---|
239 | /** Get the distance to extrude for a point/spot light */
|
---|
240 | Real getPointExtrusionDistance(const Light* l) const;
|
---|
241 |
|
---|
242 |
|
---|
243 |
|
---|
244 |
|
---|
245 |
|
---|
246 | };
|
---|
247 |
|
---|
248 | }
|
---|
249 | #endif
|
---|