source: OGRE/trunk/ogrenew/OgreMain/src/OgreMovableObject.cpp @ 692

Revision 692, 9.6 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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#include "OgreRoot.h"
33#include "OgreSceneManager.h"
34#include "OgreCamera.h"
35
36namespace Ogre {
37        //-----------------------------------------------------------------------
38        //-----------------------------------------------------------------------
39        uint32 MovableObject::msDefaultQueryFlags = 0xFFFFFFFF;
40        uint32 MovableObject::msDefaultVisibilityFlags = 0xFFFFFFFF;
41    //-----------------------------------------------------------------------
42    MovableObject::MovableObject()
43                : mCreator(0), mManager(0), mParentNode(0), mParentIsTagPoint(false),
44                mVisible(true), mUpperDistance(0), mSquaredUpperDistance(0),
45                mBeyondFarDistance(false), mRenderQueueID(RENDER_QUEUE_MAIN),
46                mRenderQueueIDSet(false), mQueryFlags(msDefaultQueryFlags),
47                mVisibilityFlags(msDefaultVisibilityFlags), mCastShadows (true)
48    {
49                mWorldAABB.setNull();
50       
51    }
52        //-----------------------------------------------------------------------
53        MovableObject::MovableObject(const String& name)
54                : mName(name), mCreator(0), mManager(0), mParentNode(0),
55                mParentIsTagPoint(false), mVisible(true), mUpperDistance(0),
56                mSquaredUpperDistance(0),
57                mBeyondFarDistance(false), mRenderQueueID(RENDER_QUEUE_MAIN),
58                mRenderQueueIDSet(false), mQueryFlags(msDefaultQueryFlags),
59                mVisibilityFlags(msDefaultVisibilityFlags),
60                mCastShadows (true)
61        {
62                mWorldAABB.setNull();
63        }
64        //-----------------------------------------------------------------------
65    MovableObject::~MovableObject()
66    {
67        if (mParentNode)
68        {
69            // detach from parent
70            if (mParentIsTagPoint)
71            {
72                // May be we are a lod entity which not in the parent entity child object list,
73                // call this method could safely ignore this case.
74                static_cast<TagPoint*>(mParentNode)->getParentEntity()->detachObjectFromBone(this);
75            }
76            else
77            {
78                // May be we are a lod entity which not in the parent node child object list,
79                // call this method could safely ignore this case.
80                static_cast<SceneNode*>(mParentNode)->detachObject(this);
81            }
82        }
83    }
84    //-----------------------------------------------------------------------
85    void MovableObject::_notifyAttached(Node* parent, bool isTagPoint)
86    {
87        mParentNode = parent;
88        mParentIsTagPoint = isTagPoint;
89    }
90    //-----------------------------------------------------------------------
91    Node* MovableObject::getParentNode(void) const
92    {
93        return mParentNode;
94    }
95    //-----------------------------------------------------------------------
96    SceneNode* MovableObject::getParentSceneNode(void) const
97    {
98        if (mParentIsTagPoint)
99        {
100            TagPoint* tp = static_cast<TagPoint*>(mParentNode);
101            return tp->getParentEntity()->getParentSceneNode();
102        }
103        else
104        {
105            return static_cast<SceneNode*>(mParentNode);
106        }
107    }
108    //-----------------------------------------------------------------------
109    bool MovableObject::isAttached(void) const
110    {
111        return (mParentNode != 0);
112
113    }
114    //-----------------------------------------------------------------------
115        bool MovableObject::isInScene(void) const
116        {
117                if (mParentNode != 0)
118                {
119                        if (mParentIsTagPoint)
120                        {
121                                TagPoint* tp = static_cast<TagPoint*>(mParentNode);
122                                return tp->getParentEntity()->isInScene();
123                        }
124                        else
125                        {
126                                SceneNode* sn = static_cast<SceneNode*>(mParentNode);
127                                return sn->isInSceneGraph();
128                        }
129                }
130                else
131                {
132                        return false;
133                }
134        }
135    //-----------------------------------------------------------------------
136    void MovableObject::setVisible(bool visible)
137    {
138        mVisible = visible;
139    }
140    //-----------------------------------------------------------------------
141    bool MovableObject::isVisible(void) const
142    {
143                bool flagVis = true;
144                if (Root::getSingleton()._getCurrentSceneManager())
145                {
146                        flagVis = (mVisibilityFlags &
147                                Root::getSingleton()._getCurrentSceneManager()->getVisibilityMask()) != 0;
148                }
149
150                return mVisible && !mBeyondFarDistance && flagVis;
151    }
152        //-----------------------------------------------------------------------
153        void MovableObject::_notifyCurrentCamera(Camera* cam)
154        {
155                if (mParentNode)
156                {
157                        if (cam->getUseRenderingDistance() && mUpperDistance > 0)
158                        {
159                                Real rad = getBoundingRadius();
160                                Real squaredDepth = mParentNode->getSquaredViewDepth(cam);
161                                // Max distance to still render
162                                Real maxDist = mUpperDistance + rad;
163                                if (squaredDepth > Math::Sqr(maxDist))
164                                {
165                                        mBeyondFarDistance = true;
166                                }
167                                else
168                                {
169                                        mBeyondFarDistance = false;
170                                }
171                        }
172                        else
173                        {
174                                mBeyondFarDistance = false;
175                        }
176                }
177
178        }
179    //-----------------------------------------------------------------------
180    void MovableObject::setRenderQueueGroup(uint8 queueID)
181    {
182        mRenderQueueID = queueID;
183        mRenderQueueIDSet = true;
184    }
185    //-----------------------------------------------------------------------
186    uint8 MovableObject::getRenderQueueGroup(void) const
187    {
188        return mRenderQueueID;
189    }
190    //-----------------------------------------------------------------------
191        Matrix4 MovableObject::_getParentNodeFullTransform(void) const
192        {
193               
194                if(mParentNode)
195                {
196                        // object attached to a sceneNode
197                        return mParentNode->_getFullTransform();
198                }
199        // fallback
200        return Matrix4::IDENTITY;
201        }
202    //-----------------------------------------------------------------------
203    const AxisAlignedBox& MovableObject::getWorldBoundingBox(bool derive) const
204    {
205        if (derive)
206        {
207            mWorldAABB = this->getBoundingBox();
208            mWorldAABB.transform(_getParentNodeFullTransform());
209        }
210
211        return mWorldAABB;
212
213    }
214    //-----------------------------------------------------------------------
215        const Sphere& MovableObject::getWorldBoundingSphere(bool derive) const
216        {
217                if (derive)
218                {
219                        mWorldBoundingSphere.setRadius(getBoundingRadius());
220                        mWorldBoundingSphere.setCenter(mParentNode->_getDerivedPosition());
221                }
222                return mWorldBoundingSphere;
223        }
224
225    //-----------------------------------------------------------------------
226    ShadowCaster::ShadowRenderableListIterator MovableObject::getShadowVolumeRenderableIterator(
227        ShadowTechnique shadowTechnique, const Light* light,
228        HardwareIndexBufferSharedPtr* indexBuffer,
229        bool extrudeVertices, Real extrusionDist, unsigned long flags )
230    {
231        static ShadowRenderableList dummyList;
232        return ShadowRenderableListIterator(dummyList.begin(), dummyList.end());
233    }
234    //-----------------------------------------------------------------------
235    const AxisAlignedBox& MovableObject::getLightCapBounds(void) const
236    {
237        // Same as original bounds
238        return getWorldBoundingBox();
239    }
240    //-----------------------------------------------------------------------
241    const AxisAlignedBox& MovableObject::getDarkCapBounds(const Light& light, Real extrusionDist) const
242    {
243        // Extrude own light cap bounds
244        mWorldDarkCapBounds = getLightCapBounds();
245        this->extrudeBounds(mWorldDarkCapBounds, light.getAs4DVector(),
246            extrusionDist);
247        return mWorldDarkCapBounds;
248
249    }
250    //-----------------------------------------------------------------------
251    Real MovableObject::getPointExtrusionDistance(const Light* l) const
252    {
253        if (mParentNode)
254        {
255            return getExtrusionDistance(mParentNode->_getDerivedPosition(), l);
256        }
257        else
258        {
259            return 0;
260        }
261    }
262        //-----------------------------------------------------------------------
263        uint32 MovableObject::getTypeFlags(void) const
264        {
265                if (mCreator)
266                {
267                        return mCreator->getTypeFlags();
268                }
269                else
270                {
271                        return 0xFFFFFFFF;
272                }
273        }
274        //-----------------------------------------------------------------------
275        //-----------------------------------------------------------------------
276        MovableObject* MovableObjectFactory::createInstance(
277                const String& name, SceneManager* manager,
278                const NameValuePairList* params)
279        {
280                MovableObject* m = createInstanceImpl(name, params);
281                m->_notifyCreator(this);
282                m->_notifyManager(manager);
283                return m;
284        }
285
286
287}
288
Note: See TracBrowser for help on using the repository browser.