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 | #include "OgreStableHeaders.h"
|
---|
26 |
|
---|
27 | #include "OgreMovableObject.h"
|
---|
28 | #include "OgreSceneNode.h"
|
---|
29 | #include "OgreTagPoint.h"
|
---|
30 | #include "OgreLight.h"
|
---|
31 | #include "OgreEntity.h"
|
---|
32 |
|
---|
33 | namespace Ogre {
|
---|
34 |
|
---|
35 | //-----------------------------------------------------------------------
|
---|
36 | MovableObject::MovableObject()
|
---|
37 | {
|
---|
38 | mParentNode = 0;
|
---|
39 | mVisible = true;
|
---|
40 | mUserObject = 0;
|
---|
41 | mRenderQueueID = RENDER_QUEUE_MAIN;
|
---|
42 | mRenderQueueIDSet = false;
|
---|
43 | mQueryFlags = 0xFFFFFFFF;
|
---|
44 | mWorldAABB.setNull();
|
---|
45 | mParentIsTagPoint = false;
|
---|
46 | mCastShadows = true;
|
---|
47 | }
|
---|
48 | //-----------------------------------------------------------------------
|
---|
49 | MovableObject::~MovableObject()
|
---|
50 | {
|
---|
51 | if (mParentNode)
|
---|
52 | {
|
---|
53 | // detach from parent
|
---|
54 | if (mParentIsTagPoint)
|
---|
55 | {
|
---|
56 | // May be we are a lod entity which not in the parent entity child object list,
|
---|
57 | // call this method could safely ignore this case.
|
---|
58 | static_cast<TagPoint*>(mParentNode)->getParentEntity()->detachObjectFromBone(this);
|
---|
59 | }
|
---|
60 | else
|
---|
61 | {
|
---|
62 | // May be we are a lod entity which not in the parent node child object list,
|
---|
63 | // call this method could safely ignore this case.
|
---|
64 | static_cast<SceneNode*>(mParentNode)->detachObject(this);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | //-----------------------------------------------------------------------
|
---|
69 | void MovableObject::_notifyAttached(Node* parent, bool isTagPoint)
|
---|
70 | {
|
---|
71 | mParentNode = parent;
|
---|
72 | mParentIsTagPoint = isTagPoint;
|
---|
73 | }
|
---|
74 | //-----------------------------------------------------------------------
|
---|
75 | Node* MovableObject::getParentNode(void) const
|
---|
76 | {
|
---|
77 | return mParentNode;
|
---|
78 | }
|
---|
79 | //-----------------------------------------------------------------------
|
---|
80 | SceneNode* MovableObject::getParentSceneNode(void) const
|
---|
81 | {
|
---|
82 | if (mParentIsTagPoint)
|
---|
83 | {
|
---|
84 | TagPoint* tp = static_cast<TagPoint*>(mParentNode);
|
---|
85 | return tp->getParentEntity()->getParentSceneNode();
|
---|
86 | }
|
---|
87 | else
|
---|
88 | {
|
---|
89 | return static_cast<SceneNode*>(mParentNode);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | //-----------------------------------------------------------------------
|
---|
93 | bool MovableObject::isAttached(void) const
|
---|
94 | {
|
---|
95 | return (mParentNode != 0);
|
---|
96 |
|
---|
97 | }
|
---|
98 | //-----------------------------------------------------------------------
|
---|
99 | bool MovableObject::isInScene(void) const
|
---|
100 | {
|
---|
101 | if (mParentNode != 0)
|
---|
102 | {
|
---|
103 | if (mParentIsTagPoint)
|
---|
104 | {
|
---|
105 | TagPoint* tp = static_cast<TagPoint*>(mParentNode);
|
---|
106 | return tp->getParentEntity()->isInScene();
|
---|
107 | }
|
---|
108 | else
|
---|
109 | {
|
---|
110 | SceneNode* sn = static_cast<SceneNode*>(mParentNode);
|
---|
111 | return sn->isInSceneGraph();
|
---|
112 | }
|
---|
113 | }
|
---|
114 | else
|
---|
115 | {
|
---|
116 | return false;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | //-----------------------------------------------------------------------
|
---|
120 | void MovableObject::setVisible(bool visible)
|
---|
121 | {
|
---|
122 | mVisible = visible;
|
---|
123 | }
|
---|
124 | //-----------------------------------------------------------------------
|
---|
125 | bool MovableObject::isVisible(void) const
|
---|
126 | {
|
---|
127 | return mVisible;
|
---|
128 |
|
---|
129 | }
|
---|
130 | //-----------------------------------------------------------------------
|
---|
131 | void MovableObject::setRenderQueueGroup(RenderQueueGroupID queueID)
|
---|
132 | {
|
---|
133 | mRenderQueueID = queueID;
|
---|
134 | mRenderQueueIDSet = true;
|
---|
135 | }
|
---|
136 | //-----------------------------------------------------------------------
|
---|
137 | RenderQueueGroupID MovableObject::getRenderQueueGroup(void) const
|
---|
138 | {
|
---|
139 | return mRenderQueueID;
|
---|
140 | }
|
---|
141 | //-----------------------------------------------------------------------
|
---|
142 | Matrix4 MovableObject::_getParentNodeFullTransform(void) const
|
---|
143 | {
|
---|
144 |
|
---|
145 | if(mParentNode)
|
---|
146 | {
|
---|
147 | // object attached to a sceneNode
|
---|
148 | return mParentNode->_getFullTransform();
|
---|
149 | }
|
---|
150 | // fallback
|
---|
151 | return Matrix4::IDENTITY;
|
---|
152 | }
|
---|
153 | //-----------------------------------------------------------------------
|
---|
154 | const AxisAlignedBox& MovableObject::getWorldBoundingBox(bool derive) const
|
---|
155 | {
|
---|
156 | if (derive)
|
---|
157 | {
|
---|
158 | mWorldAABB = this->getBoundingBox();
|
---|
159 | mWorldAABB.transform(_getParentNodeFullTransform());
|
---|
160 | }
|
---|
161 |
|
---|
162 | return mWorldAABB;
|
---|
163 |
|
---|
164 | }
|
---|
165 | //-----------------------------------------------------------------------
|
---|
166 | const Sphere& MovableObject::getWorldBoundingSphere(bool derive) const
|
---|
167 | {
|
---|
168 | if (derive)
|
---|
169 | {
|
---|
170 | mWorldBoundingSphere.setRadius(getBoundingRadius());
|
---|
171 | mWorldBoundingSphere.setCenter(mParentNode->_getDerivedPosition());
|
---|
172 | }
|
---|
173 | return mWorldBoundingSphere;
|
---|
174 | }
|
---|
175 |
|
---|
176 | //-----------------------------------------------------------------------
|
---|
177 | ShadowCaster::ShadowRenderableListIterator MovableObject::getShadowVolumeRenderableIterator(
|
---|
178 | ShadowTechnique shadowTechnique, const Light* light,
|
---|
179 | HardwareIndexBufferSharedPtr* indexBuffer,
|
---|
180 | bool extrudeVertices, Real extrusionDist, unsigned long flags )
|
---|
181 | {
|
---|
182 | static ShadowRenderableList dummyList;
|
---|
183 | return ShadowRenderableListIterator(dummyList.begin(), dummyList.end());
|
---|
184 | }
|
---|
185 | //-----------------------------------------------------------------------
|
---|
186 | const AxisAlignedBox& MovableObject::getLightCapBounds(void) const
|
---|
187 | {
|
---|
188 | // Same as original bounds
|
---|
189 | return getWorldBoundingBox();
|
---|
190 | }
|
---|
191 | //-----------------------------------------------------------------------
|
---|
192 | const AxisAlignedBox& MovableObject::getDarkCapBounds(const Light& light, Real extrusionDist) const
|
---|
193 | {
|
---|
194 | // Extrude own light cap bounds
|
---|
195 | mWorldDarkCapBounds = getLightCapBounds();
|
---|
196 | this->extrudeBounds(mWorldDarkCapBounds, light.getAs4DVector(),
|
---|
197 | extrusionDist);
|
---|
198 | return mWorldDarkCapBounds;
|
---|
199 |
|
---|
200 | }
|
---|
201 | //-----------------------------------------------------------------------
|
---|
202 | Real MovableObject::getPointExtrusionDistance(const Light* l) const
|
---|
203 | {
|
---|
204 | if (mParentNode)
|
---|
205 | {
|
---|
206 | return getExtrusionDistance(mParentNode->_getDerivedPosition(), l);
|
---|
207 | }
|
---|
208 | else
|
---|
209 | {
|
---|
210 | return 0;
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | }
|
---|
216 |
|
---|