1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of the GameTools Project
|
---|
4 | http://www.gametools.org
|
---|
5 |
|
---|
6 | Author: Martin Szydlowski
|
---|
7 | -----------------------------------------------------------------------------
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "OgreKdTreeSceneNode.h"
|
---|
11 | #include "OgreKdTreeSceneManager.h"
|
---|
12 |
|
---|
13 | #include <OgreStringConverter.h>
|
---|
14 |
|
---|
15 | namespace Ogre
|
---|
16 | {
|
---|
17 | // TRIVIA: this function is _not_ called for nodes which did not change since the last frame
|
---|
18 | // only exception: the root node ... it's aabb should be null however, so we don't care
|
---|
19 | void KdTreeSceneNode::_updateBounds(void)
|
---|
20 | {
|
---|
21 | // Reset bounds first
|
---|
22 | mWorldAABB.setNull();
|
---|
23 |
|
---|
24 | // Update bounds from own attached objects
|
---|
25 | ObjectMap::iterator i;
|
---|
26 | for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i)
|
---|
27 | {
|
---|
28 | // Merge world bounds of each object
|
---|
29 | mWorldAABB.merge(i->second->getWorldBoundingBox(true));
|
---|
30 | }
|
---|
31 |
|
---|
32 | if (!mWorldAABB.isNull())
|
---|
33 | {
|
---|
34 | static_cast<KdTreeSceneManager *>(mCreator)->_updateNode(this);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | void KdTreeSceneNode::forceComputeAABB(AxisAlignedBox& aabb) // OBSOLETE !!
|
---|
39 | {
|
---|
40 |
|
---|
41 | // Update bounds from own attached objects
|
---|
42 | ObjectMap::iterator i;
|
---|
43 | for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i)
|
---|
44 | {
|
---|
45 | // Merge world bounds of each object
|
---|
46 | aabb.merge(i->second->getWorldBoundingBox(true));
|
---|
47 | }
|
---|
48 | // Merge with children
|
---|
49 | ChildNodeMap::iterator child;
|
---|
50 | for (child = mChildren.begin(); child != mChildren.end(); ++child)
|
---|
51 | {
|
---|
52 | KdTreeSceneNode* sceneChild = static_cast<KdTreeSceneNode*>(child->second);
|
---|
53 | sceneChild->forceComputeAABB(aabb);
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | void KdTreeSceneNode::computeScene(PlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren)
|
---|
58 | {
|
---|
59 | // first compute nodes AABB
|
---|
60 | mWorldAABB.setNull();
|
---|
61 | // Update bounds from own attached objects
|
---|
62 | ObjectMap::iterator i;
|
---|
63 | for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i)
|
---|
64 | {
|
---|
65 | // Merge world bounds of each object
|
---|
66 | mWorldAABB.merge(i->second->getWorldBoundingBox(true));
|
---|
67 | }
|
---|
68 |
|
---|
69 | if (!mWorldAABB.isNull())
|
---|
70 | {
|
---|
71 | // merge aabb with global AABB
|
---|
72 | aabb.merge(mWorldAABB);
|
---|
73 | // increase object count
|
---|
74 | nObjects++;
|
---|
75 |
|
---|
76 | // generate events
|
---|
77 | PlaneEvent::Dimension axes[] =
|
---|
78 | {PlaneEvent::PED_X, PlaneEvent::PED_Y, PlaneEvent::PED_Z};
|
---|
79 | Vector3 min = mWorldAABB.getMinimum();
|
---|
80 | Vector3 max = mWorldAABB.getMaximum();
|
---|
81 | //PlaneEvent * e;
|
---|
82 | for (int i = 0; i < 3; i++)
|
---|
83 | {
|
---|
84 | // 1-D and 2-D objects
|
---|
85 | if (min[i] == max[i])
|
---|
86 | {
|
---|
87 | //e = new PlaneEvent(this, min, axes[i], PlaneEvent::PET_ON);
|
---|
88 | //sceneinfo.events.push_back(*e);
|
---|
89 | events.push_back(PlaneEvent(this, min, axes[i], PlaneEvent::PET_ON));
|
---|
90 | }
|
---|
91 | else
|
---|
92 | {
|
---|
93 | //e = new PlaneEvent(this, min, axes[i], PlaneEvent::PET_START);
|
---|
94 | //sceneinfo.events.push_back(*e);
|
---|
95 | //e = new PlaneEvent(this, max, axes[i], PlaneEvent::PET_END);
|
---|
96 | //sceneinfo.events.push_back(*e);
|
---|
97 | events.push_back(PlaneEvent(this, min, axes[i], PlaneEvent::PET_START));
|
---|
98 | events.push_back(PlaneEvent(this, max, axes[i], PlaneEvent::PET_END));
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Merge with children
|
---|
104 | if (includeChildren)
|
---|
105 | {
|
---|
106 | ChildNodeMap::iterator child;
|
---|
107 | for (child = mChildren.begin(); child != mChildren.end(); ++child)
|
---|
108 | {
|
---|
109 | KdTreeSceneNode* sceneChild = static_cast<KdTreeSceneNode*>(child->second);
|
---|
110 | sceneChild->computeScene(events, aabb, nObjects);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | //void KdTreeSceneNode::_findVisibleObjects(Camera* cam, RenderQueue* queue,
|
---|
116 | // bool includeChildren, bool displayNodes, bool onlyShadowCasters)
|
---|
117 | void KdTreeSceneNode::queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters)
|
---|
118 | {
|
---|
119 | //SceneNode::_findVisibleObjects(cam, queue, includeChildren, displayNodes, onlyShadowCasters);
|
---|
120 |
|
---|
121 | // Add all entities
|
---|
122 | ObjectMap::iterator iobj;
|
---|
123 | ObjectMap::iterator iobjend = mObjectsByName.end();
|
---|
124 | for (iobj = mObjectsByName.begin(); iobj != iobjend; ++iobj)
|
---|
125 | {
|
---|
126 | // Tell attached objects about camera position (incase any extra processing they want to do)
|
---|
127 | iobj->second->_notifyCurrentCamera(cam);
|
---|
128 | if (!onlyShadowCasters || iobj->second->getCastShadows())
|
---|
129 | {
|
---|
130 | iobj->second->_updateRenderQueue(queue);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | // Check if the bounding box should be shown.
|
---|
135 | // See if our flag is set or if the scene manager flag is set.
|
---|
136 | if (mShowBoundingBox || (mCreator && mCreator->getShowBoundingBoxes()))
|
---|
137 | {
|
---|
138 | _addBoundingBoxToQueue(queue);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | AxisAlignedBox KdTreeSceneNode::getBoundingBox() const
|
---|
143 | {
|
---|
144 | return mWorldAABB;
|
---|
145 | }
|
---|
146 |
|
---|
147 | // DEBUG
|
---|
148 | String KdTreeSceneNode::dumpToString()
|
---|
149 | {
|
---|
150 | String objects;
|
---|
151 | // Add all entities
|
---|
152 | ObjectMap::iterator iobj = mObjectsByName.begin();
|
---|
153 | ObjectMap::iterator iobjend = mObjectsByName.end();
|
---|
154 | while (iobj != iobjend)
|
---|
155 | {
|
---|
156 | objects += " " + iobj->second->getName();
|
---|
157 | iobj++;
|
---|
158 | }
|
---|
159 | objects += " Attached to " + StringConverter::toString(mLeaves.size()) + " KdLeaves.";
|
---|
160 | return objects;
|
---|
161 | }
|
---|
162 | } |
---|