1 | #include "..\include\ogrerenderable.h"
|
---|
2 |
|
---|
3 | OgreRenderable::OgreRenderable(SubEntity* sube, Entity* parentEntity)
|
---|
4 | {
|
---|
5 | renderableType = OGRE_RENDERABLETYPE_SUBENTITY;
|
---|
6 | subEntityRenderable = sube;
|
---|
7 | this->parentEntity = parentEntity;
|
---|
8 | int subEntityNum = 0;
|
---|
9 | updateBounds();
|
---|
10 | for(unsigned int i = 0; i < parentEntity->getNumSubEntities(); i++)
|
---|
11 | {
|
---|
12 | if(parentEntity->getSubEntity(i) == sube)
|
---|
13 | {
|
---|
14 | subEntityNum = i;
|
---|
15 | break;
|
---|
16 | }
|
---|
17 | }
|
---|
18 | name = parentEntity->getName() + "_SE_" + StringConverter::toString(subEntityNum);
|
---|
19 | }
|
---|
20 |
|
---|
21 | OgreRenderable::OgreRenderable(Entity* parentEntity, int subEntityNum)
|
---|
22 | {
|
---|
23 | SubEntity* sube = parentEntity->getSubEntity(subEntityNum);
|
---|
24 | renderableType = OGRE_RENDERABLETYPE_SUBENTITY;
|
---|
25 | subEntityRenderable = sube;
|
---|
26 | this->parentEntity = parentEntity;
|
---|
27 | updateBounds();
|
---|
28 | name = parentEntity->getName() + "_SE_" + StringConverter::toString(subEntityNum);
|
---|
29 | }
|
---|
30 |
|
---|
31 | OgreRenderable::OgreRenderable(BillboardSet* billboardset, ParticleSystem* sys)
|
---|
32 | {
|
---|
33 | renderableType = OGRE_RENDERABLETYPE_BILLBOARDSET;
|
---|
34 | billboardSetRenderable = billboardset;
|
---|
35 | parentParticleSystem = sys;
|
---|
36 | updateBounds();
|
---|
37 | name = sys->getName();
|
---|
38 | }
|
---|
39 |
|
---|
40 | OgreRenderable::~OgreRenderable(void)
|
---|
41 | {
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | void OgreRenderable::setVisible(bool visible)
|
---|
46 | {
|
---|
47 | switch(renderableType)
|
---|
48 | {
|
---|
49 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
50 | // subEntityRenderable->setVisible(visible);
|
---|
51 | parentEntity->setVisible(visible);
|
---|
52 | break;
|
---|
53 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
54 | if(parentParticleSystem != 0)
|
---|
55 | parentParticleSystem->setVisible(visible);
|
---|
56 | else
|
---|
57 | billboardSetRenderable->setVisible(visible);
|
---|
58 | break;
|
---|
59 | default:
|
---|
60 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
61 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
62 | "OgreRenderable::setVisible");
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | void OgreRenderable::setMaterialName(String& name)
|
---|
67 | {
|
---|
68 | switch(renderableType)
|
---|
69 | {
|
---|
70 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
71 | subEntityRenderable->setMaterialName(name);
|
---|
72 | break;
|
---|
73 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
74 | billboardSetRenderable->setMaterialName(name);
|
---|
75 | break;
|
---|
76 | default:
|
---|
77 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
78 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
79 | "OgreRenderable::setMaterialName");
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | const MaterialPtr& OgreRenderable::getMaterialPtr()
|
---|
84 | {
|
---|
85 | switch(renderableType)
|
---|
86 | {
|
---|
87 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
88 | return subEntityRenderable->getMaterial();
|
---|
89 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
90 | return billboardSetRenderable->getMaterial();
|
---|
91 | default:
|
---|
92 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
93 | "Unknown renderable type, can't return material pointer! Check RenderTechnique initializations!",
|
---|
94 | "OgreRenderable::getMaterialPtr");
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | void OgreRenderable::setRenderGroup(unsigned char groupID)
|
---|
99 | {
|
---|
100 | switch(renderableType)
|
---|
101 | {
|
---|
102 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
103 | parentEntity->setRenderQueueGroup(groupID);
|
---|
104 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
105 | billboardSetRenderable->setRenderQueueGroup(groupID);
|
---|
106 | default:
|
---|
107 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
108 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
109 | "OgreRenderable::setRenderGroup");
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | bool OgreRenderable::isVisible()
|
---|
114 | {
|
---|
115 | switch(renderableType)
|
---|
116 | {
|
---|
117 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
118 | return subEntityRenderable->isVisible();
|
---|
119 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
120 | return billboardSetRenderable->isVisible();
|
---|
121 | default:
|
---|
122 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
123 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
124 | "OgreRenderable::isVisible");
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | void OgreRenderable::updateBounds()
|
---|
129 | {
|
---|
130 | switch(renderableType)
|
---|
131 | {
|
---|
132 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
133 | {
|
---|
134 | parentEntity->getParentSceneNode()->_updateBounds();
|
---|
135 | boundingBox = parentEntity->getWorldBoundingBox(true);
|
---|
136 |
|
---|
137 | Vector3 center = (boundingBox.getMaximum() + boundingBox.getMinimum()) / 2.0;
|
---|
138 | float radius = (center - boundingBox.getMaximum()).length();
|
---|
139 | boundingSphere.setRadius(radius);
|
---|
140 | boundingSphere.setCenter(center);
|
---|
141 | // boundingSphere = parentEntity->getWorldBoundingSphere(true);
|
---|
142 | break;
|
---|
143 | }
|
---|
144 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
145 | {
|
---|
146 | /* billboardSetRenderable->getParentSceneNode()->_updateBounds();
|
---|
147 | boundingBox = billboardSetRenderable->getWorldBoundingBox(true);
|
---|
148 | boundingSphere = billboardSetRenderable->getWorldBoundingSphere(true);*/
|
---|
149 | parentParticleSystem->getParentSceneNode()->_updateBounds();
|
---|
150 | boundingBox = parentParticleSystem->getParentSceneNode()->_getWorldAABB();
|
---|
151 | boundingSphere.setRadius( (boundingBox.getMaximum() - boundingBox.getMinimum()).length() / 2.0);
|
---|
152 | boundingSphere.setCenter( (boundingBox.getMaximum() + boundingBox.getMinimum()) / 2.0);
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | default:
|
---|
156 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
157 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
158 | "OgreRenderable::updateBounds");
|
---|
159 | }
|
---|
160 |
|
---|
161 | }
|
---|
162 |
|
---|
163 | SceneNode* OgreRenderable::getParentSceneNode()
|
---|
164 | {
|
---|
165 | switch(renderableType)
|
---|
166 | {
|
---|
167 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
168 | {
|
---|
169 | return parentEntity->getParentSceneNode();
|
---|
170 | }
|
---|
171 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
172 | {
|
---|
173 | return parentParticleSystem->getParentSceneNode();
|
---|
174 | }
|
---|
175 | default:
|
---|
176 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
177 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
178 | "OgreRenderable::getParentSceneNode");
|
---|
179 | }
|
---|
180 | return 0;
|
---|
181 | }
|
---|
182 |
|
---|
183 | Renderable* OgreRenderable::getRenderable()
|
---|
184 | {
|
---|
185 | switch(renderableType)
|
---|
186 | {
|
---|
187 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
188 | return subEntityRenderable;
|
---|
189 | break;
|
---|
190 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
191 | return billboardSetRenderable;
|
---|
192 | break;
|
---|
193 | default:
|
---|
194 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
195 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
196 | "OgreRenderable::getRenderable");
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | void OgreRenderable::notifyCamera(Camera* cam)
|
---|
201 | {
|
---|
202 | switch(renderableType)
|
---|
203 | {
|
---|
204 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
205 | parentEntity->_notifyCurrentCamera(cam);
|
---|
206 | break;
|
---|
207 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
208 | parentParticleSystem->_notifyCurrentCamera(cam);
|
---|
209 | break;
|
---|
210 | default:
|
---|
211 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
212 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
213 | "OgreRenderable::notifyCamera");
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 |
|
---|
218 | void OgreRenderable::updateRenderQueue(RenderQueue* rq)
|
---|
219 | {
|
---|
220 | switch(renderableType)
|
---|
221 | {
|
---|
222 | case OGRE_RENDERABLETYPE_SUBENTITY:
|
---|
223 | parentEntity->_updateRenderQueue(rq);
|
---|
224 | break;
|
---|
225 | case OGRE_RENDERABLETYPE_BILLBOARDSET:
|
---|
226 | parentParticleSystem->_updateRenderQueue(rq);
|
---|
227 | break;
|
---|
228 | default:
|
---|
229 | OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
|
---|
230 | "Unknown renderable type! Check RenderTechnique initializations!",
|
---|
231 | "OgreRenderable::notifyCamera");
|
---|
232 | }
|
---|
233 | } |
---|