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-2006 Torus Knot Software Ltd |
---|
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 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef __BillboardSet_H__ |
---|
31 | #define __BillboardSet_H__ |
---|
32 | |
---|
33 | #include "OgrePrerequisites.h" |
---|
34 | |
---|
35 | #include "OgreMovableObject.h" |
---|
36 | #include "OgreRenderable.h" |
---|
37 | #include "OgreRadixSort.h" |
---|
38 | #include "OgreCommon.h" |
---|
39 | |
---|
40 | namespace Ogre { |
---|
41 | |
---|
42 | /** Enum covering what exactly a billboard's position means (center, |
---|
43 | top-left etc). |
---|
44 | @see |
---|
45 | BillboardSet::setBillboardOrigin |
---|
46 | */ |
---|
47 | enum BillboardOrigin |
---|
48 | { |
---|
49 | BBO_TOP_LEFT, |
---|
50 | BBO_TOP_CENTER, |
---|
51 | BBO_TOP_RIGHT, |
---|
52 | BBO_CENTER_LEFT, |
---|
53 | BBO_CENTER, |
---|
54 | BBO_CENTER_RIGHT, |
---|
55 | BBO_BOTTOM_LEFT, |
---|
56 | BBO_BOTTOM_CENTER, |
---|
57 | BBO_BOTTOM_RIGHT |
---|
58 | }; |
---|
59 | /** The rotation type of billboard. */ |
---|
60 | enum BillboardRotationType |
---|
61 | { |
---|
62 | /// Rotate the billboard's vertices around their facing direction |
---|
63 | BBR_VERTEX, |
---|
64 | /// Rotate the billboard's texture coordinates |
---|
65 | BBR_TEXCOORD |
---|
66 | }; |
---|
67 | /** The type of billboard to use. */ |
---|
68 | enum BillboardType |
---|
69 | { |
---|
70 | /// Standard point billboard (default), always faces the camera completely and is always upright |
---|
71 | BBT_POINT, |
---|
72 | /// Billboards are oriented around a shared direction vector (used as Y axis) and only rotate around this to face the camera |
---|
73 | BBT_ORIENTED_COMMON, |
---|
74 | /// Billboards are oriented around their own direction vector (their own Y axis) and only rotate around this to face the camera |
---|
75 | BBT_ORIENTED_SELF, |
---|
76 | /// Billboards are perpendicular to a shared direction vector (used as Z axis, the facing direction) and X, Y axis are determined by a shared up-vertor |
---|
77 | BBT_PERPENDICULAR_COMMON, |
---|
78 | /// Billboards are perpendicular to their own direction vector (their own Z axis, the facing direction) and X, Y axis are determined by a shared up-vertor |
---|
79 | BBT_PERPENDICULAR_SELF |
---|
80 | }; |
---|
81 | |
---|
82 | /** A collection of billboards (faces which are always facing the given direction) with the same (default) dimensions, material |
---|
83 | and which are fairly close proximity to each other. |
---|
84 | @remarks |
---|
85 | Billboards are rectangles made up of 2 tris which are always facing the given direction. They are typically used |
---|
86 | for special effects like particles. This class collects together a set of billboards with the same (default) dimensions, |
---|
87 | material and relative locality in order to process them more efficiently. The entire set of billboards will be |
---|
88 | culled as a whole (by default, although this can be changed if you want a large set of billboards |
---|
89 | which are spread out and you want them culled individually), individual Billboards have locations which are relative to the set (which itself derives it's |
---|
90 | position from the SceneNode it is attached to since it is a MoveableObject), they will be rendered as a single rendering operation, |
---|
91 | and some calculations will be sped up by the fact that they use the same dimensions so some workings can be reused. |
---|
92 | @par |
---|
93 | A BillboardSet can be created using the SceneManager::createBillboardSet method. They can also be used internally |
---|
94 | by other classes to create effects. |
---|
95 | @note |
---|
96 | Billboard bounds are only automatically calculated when you create them. |
---|
97 | If you modify the position of a billboard you may need to call |
---|
98 | _updateBounds if the billboard moves outside the original bounds. |
---|
99 | Similarly, the bounds do no shrink when you remove a billboard, |
---|
100 | if you want them to call _updateBounds, but note this requires a |
---|
101 | potentially expensive examination of every billboard in the set. |
---|
102 | */ |
---|
103 | class _OgreExport BillboardSet : public MovableObject, public Renderable |
---|
104 | { |
---|
105 | protected: |
---|
106 | /** Private constructor (instances cannot be created directly). |
---|
107 | */ |
---|
108 | BillboardSet(); |
---|
109 | |
---|
110 | /// Bounds of all billboards in this set |
---|
111 | AxisAlignedBox mAABB; |
---|
112 | /// Bounding radius |
---|
113 | Real mBoundingRadius; |
---|
114 | |
---|
115 | /// Origin of each billboard |
---|
116 | BillboardOrigin mOriginType; |
---|
117 | /// Rotation type of each billboard |
---|
118 | BillboardRotationType mRotationType; |
---|
119 | |
---|
120 | /// Default width of each billboard |
---|
121 | Real mDefaultWidth; |
---|
122 | /// Default height of each billboard |
---|
123 | Real mDefaultHeight; |
---|
124 | |
---|
125 | /// Name of the material to use |
---|
126 | String mMaterialName; |
---|
127 | /// Pointer to the material to use |
---|
128 | MaterialPtr mpMaterial; |
---|
129 | |
---|
130 | /// True if no billboards in this set have been resized - greater efficiency. |
---|
131 | bool mAllDefaultSize; |
---|
132 | |
---|
133 | /// Flag indicating whether to autoextend pool |
---|
134 | bool mAutoExtendPool; |
---|
135 | |
---|
136 | /// Flag indicating whether the billboards has to be sorted |
---|
137 | bool mSortingEnabled; |
---|
138 | |
---|
139 | // Use 'true' billboard to cam position facing, rather than camera direcion |
---|
140 | bool mAccurateFacing; |
---|
141 | |
---|
142 | bool mAllDefaultRotation; |
---|
143 | bool mWorldSpace; |
---|
144 | |
---|
145 | typedef std::list<Billboard*> ActiveBillboardList; |
---|
146 | typedef std::list<Billboard*> FreeBillboardList; |
---|
147 | typedef std::vector<Billboard*> BillboardPool; |
---|
148 | |
---|
149 | /** Active billboard list. |
---|
150 | @remarks |
---|
151 | This is a linked list of pointers to billboards in the billboard pool. |
---|
152 | @par |
---|
153 | This allows very fast instertions and deletions from anywhere in the list to activate / deactivate billboards |
---|
154 | (required for particle systems etc) as well as resuse of Billboard instances in the pool |
---|
155 | without construction & destruction which avoids memory thrashing. |
---|
156 | */ |
---|
157 | ActiveBillboardList mActiveBillboards; |
---|
158 | |
---|
159 | /** Free billboard queue. |
---|
160 | @remarks |
---|
161 | This contains a list of the billboards free for use as new instances |
---|
162 | as required by the set. Billboard instances are preconstructed up to the estimated size in the |
---|
163 | mBillboardPool vector and are referenced on this deque at startup. As they get used this deque |
---|
164 | reduces, as they get released back to to the set they get added back to the deque. |
---|
165 | */ |
---|
166 | FreeBillboardList mFreeBillboards; |
---|
167 | |
---|
168 | /** Pool of billboard instances for use and reuse in the active billboard list. |
---|
169 | @remarks |
---|
170 | This vector will be preallocated with the estimated size of the set,and will extend as required. |
---|
171 | */ |
---|
172 | BillboardPool mBillboardPool; |
---|
173 | |
---|
174 | /// The vertex position data for all billboards in this set. |
---|
175 | VertexData* mVertexData; |
---|
176 | /// Shortcut to main buffer (positions, colours, texture coords) |
---|
177 | HardwareVertexBufferSharedPtr mMainBuf; |
---|
178 | /// Locked pointer to buffer |
---|
179 | float* mLockPtr; |
---|
180 | /// Boundary offsets based on origin and camera orientation |
---|
181 | /// Vector3 vLeftOff, vRightOff, vTopOff, vBottomOff; |
---|
182 | /// Final vertex offsets, used where sizes all default to save calcs |
---|
183 | Vector3 mVOffset[4]; |
---|
184 | /// Current camera |
---|
185 | Camera* mCurrentCamera; |
---|
186 | // Parametric offsets of origin |
---|
187 | Real mLeftOff, mRightOff, mTopOff, mBottomOff; |
---|
188 | // Camera axes in billboard space |
---|
189 | Vector3 mCamX, mCamY; |
---|
190 | // Camera direction in billboard space |
---|
191 | Vector3 mCamDir; |
---|
192 | // Camera orientation in billboard space |
---|
193 | Quaternion mCamQ; |
---|
194 | // Camera position in billboard space |
---|
195 | Vector3 mCamPos; |
---|
196 | |
---|
197 | /// The vertex index data for all billboards in this set (1 set only) |
---|
198 | //unsigned short* mpIndexes; |
---|
199 | IndexData* mIndexData; |
---|
200 | |
---|
201 | /// Flag indicating whether each billboard should be culled separately (default: false) |
---|
202 | bool mCullIndividual; |
---|
203 | |
---|
204 | typedef std::vector< Ogre::FloatRect > TextureCoordSets; |
---|
205 | TextureCoordSets mTextureCoords; |
---|
206 | |
---|
207 | /// The type of billboard to render |
---|
208 | BillboardType mBillboardType; |
---|
209 | |
---|
210 | /// Common direction for billboards of type BBT_ORIENTED_COMMON and BBT_PERPENDICULAR_COMMON |
---|
211 | Vector3 mCommonDirection; |
---|
212 | /// Common up-vector for billboards of type BBT_PERPENDICULAR_SELF and BBT_PERPENDICULAR_COMMON |
---|
213 | Vector3 mCommonUpVector; |
---|
214 | |
---|
215 | /// Internal method for culling individual billboards |
---|
216 | inline bool billboardVisible(Camera* cam, const Billboard& bill); |
---|
217 | |
---|
218 | // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false) |
---|
219 | unsigned short mNumVisibleBillboards; |
---|
220 | |
---|
221 | /// Internal method for increasing pool size |
---|
222 | virtual void increasePool(size_t size); |
---|
223 | |
---|
224 | |
---|
225 | //----------------------------------------------------------------------- |
---|
226 | // The internal methods which follow are here to allow maximum flexibility as to |
---|
227 | // when various components of the calculation are done. Depending on whether the |
---|
228 | // billboards are of fixed size and whether they are point or oriented type will |
---|
229 | // determine how much calculation has to be done per-billboard. NOT a one-size fits all approach. |
---|
230 | //----------------------------------------------------------------------- |
---|
231 | /** Internal method for generating billboard corners. |
---|
232 | @remarks |
---|
233 | Optional parameter pBill is only present for type BBT_ORIENTED_SELF and BBT_PERPENDICULAR_SELF |
---|
234 | */ |
---|
235 | void genBillboardAxes(Vector3* pX, Vector3 *pY, const Billboard* pBill = 0); |
---|
236 | |
---|
237 | /** Internal method, generates parametric offsets based on origin. |
---|
238 | */ |
---|
239 | void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom); |
---|
240 | |
---|
241 | /** Internal method for generating vertex data. |
---|
242 | @param offsets Array of 4 Vector3 offsets |
---|
243 | @param bb Referenceto billboard |
---|
244 | */ |
---|
245 | void genVertices(const Vector3* const offsets, const Billboard& pBillboard); |
---|
246 | |
---|
247 | /** Internal method generates vertex offsets. |
---|
248 | @remarks |
---|
249 | Takes in parametric offsets as generated from getParametericOffsets, width and height values |
---|
250 | and billboard x and y axes as generated from genBillboardAxes. |
---|
251 | Fills output array of 4 vectors with vector offsets |
---|
252 | from origin for left-top, right-top, left-bottom, right-bottom corners. |
---|
253 | */ |
---|
254 | void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom, |
---|
255 | Real width, Real height, |
---|
256 | const Vector3& x, const Vector3& y, Vector3* pDestVec); |
---|
257 | |
---|
258 | |
---|
259 | /** Sort by direction functor */ |
---|
260 | struct SortByDirectionFunctor |
---|
261 | { |
---|
262 | /// Direction to sort in |
---|
263 | Vector3 sortDir; |
---|
264 | |
---|
265 | SortByDirectionFunctor(const Vector3& dir); |
---|
266 | float operator()(Billboard* bill) const; |
---|
267 | }; |
---|
268 | |
---|
269 | /** Sort by distance functor */ |
---|
270 | struct SortByDistanceFunctor |
---|
271 | { |
---|
272 | /// Position to sort in |
---|
273 | Vector3 sortPos; |
---|
274 | |
---|
275 | SortByDistanceFunctor(const Vector3& pos); |
---|
276 | float operator()(Billboard* bill) const; |
---|
277 | }; |
---|
278 | |
---|
279 | static RadixSort<ActiveBillboardList, Billboard*, float> mRadixSorter; |
---|
280 | |
---|
281 | /// Use point rendering? |
---|
282 | bool mPointRendering; |
---|
283 | |
---|
284 | |
---|
285 | |
---|
286 | private: |
---|
287 | /// Flag indicating whether the HW buffers have been created. |
---|
288 | bool mBuffersCreated; |
---|
289 | /// The number of billboard in the pool. |
---|
290 | size_t mPoolSize; |
---|
291 | /// Is external billboard data in use? |
---|
292 | bool mExternalData; |
---|
293 | |
---|
294 | /** Internal method creates vertex and index buffers. |
---|
295 | */ |
---|
296 | void _createBuffers(void); |
---|
297 | /** Internal method destroys vertex and index buffers. |
---|
298 | */ |
---|
299 | void _destroyBuffers(void); |
---|
300 | |
---|
301 | public: |
---|
302 | |
---|
303 | /** Usual constructor - this is called by the SceneManager. |
---|
304 | @param |
---|
305 | name The name to give the billboard set (must be unique) |
---|
306 | @param |
---|
307 | poolSize The initial size of the billboard pool. Estimate of the number of billboards |
---|
308 | which will be required, and pass it using this parameter. The set will |
---|
309 | preallocate this number to avoid memory fragmentation. The default behaviour |
---|
310 | once this pool has run out is to double it. |
---|
311 | @param |
---|
312 | externalDataSource If true, the source of data for drawing the |
---|
313 | billboards will not be the internal billboard list, but external |
---|
314 | data. When driving thebillboard from external data, you must call |
---|
315 | _notifyCurrentCamera to reorient the billboards, setPoolSize to set |
---|
316 | the maximum billboards you want to use, beginBillboards to |
---|
317 | start the update, and injectBillboard per billboard, |
---|
318 | followed by endBillboards. |
---|
319 | @see |
---|
320 | BillboardSet::setAutoextend |
---|
321 | */ |
---|
322 | BillboardSet( const String& name, unsigned int poolSize = 20, |
---|
323 | bool externalDataSource = false); |
---|
324 | |
---|
325 | virtual ~BillboardSet(); |
---|
326 | |
---|
327 | /** Creates a new billboard and adds it to this set. |
---|
328 | @remarks |
---|
329 | Behaviour once the billboard pool has been exhausted depends on the |
---|
330 | BillboardSet::setAutoextendPool option. |
---|
331 | @param |
---|
332 | position The position of the new billboard realtive to the certer of the set |
---|
333 | @param |
---|
334 | colour Optional base colour of the billboard. |
---|
335 | @returns |
---|
336 | On success, a pointer to a newly created Billboard is |
---|
337 | returned. |
---|
338 | @par |
---|
339 | On failiure (i.e. no more space and can't autoextend), |
---|
340 | <b>NULL</b> is returned. |
---|
341 | @see |
---|
342 | BillboardSet::setAutoextend |
---|
343 | */ |
---|
344 | Billboard* createBillboard( |
---|
345 | const Vector3& position, |
---|
346 | const ColourValue& colour = ColourValue::White ); |
---|
347 | |
---|
348 | /** Creates a new billboard and adds it to this set. |
---|
349 | @remarks |
---|
350 | Behaviour once the billboard pool has been exhausted depends on the |
---|
351 | BillboardSet::setAutoextendPool option. |
---|
352 | @param |
---|
353 | x |
---|
354 | @param |
---|
355 | y |
---|
356 | @param |
---|
357 | z The position of the new billboard realtive to the certer of the set |
---|
358 | @param |
---|
359 | colour Optional base colour of the billboard. |
---|
360 | @returns |
---|
361 | On success, a pointer to a newly created Billboard is |
---|
362 | returned. |
---|
363 | @par |
---|
364 | On failiure (i.e. no more space and can't autoextend), |
---|
365 | <b>NULL</b> is returned. |
---|
366 | @see |
---|
367 | BillboardSet::setAutoextend |
---|
368 | */ |
---|
369 | Billboard* createBillboard( |
---|
370 | Real x, Real y, Real z, |
---|
371 | const ColourValue& colour = ColourValue::White ); |
---|
372 | |
---|
373 | /** Returns the number of active billboards which currently make up this set. |
---|
374 | */ |
---|
375 | virtual int getNumBillboards(void) const; |
---|
376 | |
---|
377 | /** Tells the set whether to allow automatic extension of the pool of billboards. |
---|
378 | @remarks |
---|
379 | A BillboardSet stores a pool of pre-constructed billboards which are used as needed when |
---|
380 | a new billboard is requested. This allows applications to create / remove billboards efficiently |
---|
381 | without incurring construction / destruction costs (a must for sets with lots of billboards like |
---|
382 | particle effects). This method allows you to configure the behaviour when a new billboard is requested |
---|
383 | but the billboard pool has been exhausted. |
---|
384 | @par |
---|
385 | The default behaviour is to allow the pool to extend (typically this allocates double the current |
---|
386 | pool of billboards when the pool is expended), equivalent to calling this method with |
---|
387 | autoExtend = true. If you set the parameter to false however, any attempt to create a new billboard |
---|
388 | when the pool has expired will simply fail silently, returning a null pointer. |
---|
389 | @param autoextend true to double the pool every time it runs out, false to fail silently. |
---|
390 | */ |
---|
391 | virtual void setAutoextend(bool autoextend); |
---|
392 | |
---|
393 | /** Returns true if the billboard pool automatically extends. |
---|
394 | @see |
---|
395 | BillboardSet::setAutoextend |
---|
396 | */ |
---|
397 | virtual bool getAutoextend(void) const; |
---|
398 | |
---|
399 | /** Enables sorting for this BillboardSet. (default: off) |
---|
400 | @param sortenable true to sort the billboards according to their distance to the camera |
---|
401 | */ |
---|
402 | virtual void setSortingEnabled(bool sortenable); |
---|
403 | |
---|
404 | /** Returns true if sorting of billboards is enabled based on their distance from the camera |
---|
405 | @see |
---|
406 | BillboardSet::setSortingEnabled |
---|
407 | */ |
---|
408 | virtual bool getSortingEnabled(void) const; |
---|
409 | |
---|
410 | /** Adjusts the size of the pool of billboards available in this set. |
---|
411 | @remarks |
---|
412 | See the BillboardSet::setAutoextend method for full details of the billboard pool. This method adjusts |
---|
413 | the preallocated size of the pool. If you try to reduce the size of the pool, the set has the option |
---|
414 | of ignoring you if too many billboards are already in use. Bear in mind that calling this method will |
---|
415 | incur significant construction / destruction calls so should be avoided in time-critical code. The same |
---|
416 | goes for auto-extension, try to avoid it by estimating the pool size correctly up-front. |
---|
417 | @param |
---|
418 | size The new size for the pool. |
---|
419 | */ |
---|
420 | virtual void setPoolSize(size_t size); |
---|
421 | |
---|
422 | /** Returns the current size of the billboard pool. |
---|
423 | @returns |
---|
424 | The current size of the billboard pool. |
---|
425 | @see |
---|
426 | BillboardSet::setAutoextend |
---|
427 | */ |
---|
428 | virtual unsigned int getPoolSize(void) const; |
---|
429 | |
---|
430 | |
---|
431 | /** Empties this set of all billboards. |
---|
432 | */ |
---|
433 | virtual void clear(); |
---|
434 | |
---|
435 | /** Returns a pointer to the billboard at the supplied index. |
---|
436 | @note |
---|
437 | This method requires linear time since the billboard list is a linked list. |
---|
438 | @param |
---|
439 | index The index of the billboard that is requested. |
---|
440 | @returns |
---|
441 | On success, a valid pointer to the requested billboard is |
---|
442 | returned. |
---|
443 | @par |
---|
444 | On failiure, <b>NULL</b> is returned. |
---|
445 | */ |
---|
446 | virtual Billboard* getBillboard(unsigned int index) const; |
---|
447 | |
---|
448 | /** Removes the billboard at the supplied index. |
---|
449 | @note |
---|
450 | This method requires linear time since the billboard list is a linked list. |
---|
451 | */ |
---|
452 | virtual void removeBillboard(unsigned int index); |
---|
453 | |
---|
454 | /** Removes a billboard from the set. |
---|
455 | @note |
---|
456 | This version is more efficient than removing by index. |
---|
457 | */ |
---|
458 | virtual void removeBillboard(Billboard* pBill); |
---|
459 | |
---|
460 | /** Sets the point which acts as the origin point for all billboards in this set. |
---|
461 | @remarks |
---|
462 | This setting controls the fine tuning of where a billboard appears in relation to it's |
---|
463 | position. It could be that a billboard's position represents it's center (e.g. for fireballs), |
---|
464 | it could mean the center of the bottom edge (e.g. a tree which is positioned on the ground), |
---|
465 | the top-left corner (e.g. a cursor). |
---|
466 | @par |
---|
467 | The default setting is BBO_CENTER. |
---|
468 | @param |
---|
469 | origin A member of the BillboardOrigin enum specifying the origin for all the billboards in this set. |
---|
470 | */ |
---|
471 | virtual void setBillboardOrigin(BillboardOrigin origin); |
---|
472 | |
---|
473 | /** Gets the point which acts as the origin point for all billboards in this set. |
---|
474 | @returns |
---|
475 | A member of the BillboardOrigin enum specifying the origin for all the billboards in this set. |
---|
476 | */ |
---|
477 | virtual BillboardOrigin getBillboardOrigin(void) const; |
---|
478 | |
---|
479 | /** Sets billboard rotation type. |
---|
480 | @remarks |
---|
481 | This setting controls the billboard rotation type, you can deciding rotate the billboard's vertices |
---|
482 | around their facing direction or rotate the billboard's texture coordinates. |
---|
483 | @par |
---|
484 | The default settings is BBR_TEXCOORD. |
---|
485 | @param |
---|
486 | rotationType A member of the BillboardRotationType enum specifying the rotation type for all the billboards in this set. |
---|
487 | */ |
---|
488 | virtual void setBillboardRotationType(BillboardRotationType rotationType); |
---|
489 | |
---|
490 | /** Sets billboard rotation type. |
---|
491 | @returns |
---|
492 | A member of the BillboardRotationType enum specifying the rotation type for all the billboards in this set. |
---|
493 | */ |
---|
494 | virtual BillboardRotationType getBillboardRotationType(void) const; |
---|
495 | |
---|
496 | /** Sets the default dimensions of the billboards in this set. |
---|
497 | @remarks |
---|
498 | All billboards in a set are created with these default dimensions. The set will render most efficiently if |
---|
499 | all the billboards in the set are the default size. It is possible to alter the size of individual |
---|
500 | billboards at the expense of extra calculation. See the Billboard class for more info. |
---|
501 | @param width |
---|
502 | The new default width for the billboards in this set. |
---|
503 | @param height |
---|
504 | The new default height for the billboards in this set. |
---|
505 | */ |
---|
506 | virtual void setDefaultDimensions(Real width, Real height); |
---|
507 | |
---|
508 | /** See setDefaultDimensions - this sets 1 component individually. */ |
---|
509 | virtual void setDefaultWidth(Real width); |
---|
510 | /** See setDefaultDimensions - this gets 1 component individually. */ |
---|
511 | virtual Real getDefaultWidth(void) const; |
---|
512 | /** See setDefaultDimensions - this sets 1 component individually. */ |
---|
513 | virtual void setDefaultHeight(Real height); |
---|
514 | /** See setDefaultDimensions - this gets 1 component individually. */ |
---|
515 | virtual Real getDefaultHeight(void) const; |
---|
516 | |
---|
517 | /** Sets the name of the material to be used for this billboard set. |
---|
518 | @param |
---|
519 | name The new name of the material to use for this set. |
---|
520 | */ |
---|
521 | virtual void setMaterialName(const String& name); |
---|
522 | |
---|
523 | /** Sets the name of the material to be used for this billboard set. |
---|
524 | @returns The name of the material that is used for this set. |
---|
525 | */ |
---|
526 | virtual const String& getMaterialName(void) const; |
---|
527 | |
---|
528 | /** Overridden from MovableObject |
---|
529 | @see |
---|
530 | MovableObject |
---|
531 | */ |
---|
532 | virtual void _notifyCurrentCamera(Camera* cam); |
---|
533 | |
---|
534 | /** Begin injection of billboard data; applicable when |
---|
535 | constructing the BillboardSet for external data use. |
---|
536 | @param numBillboards If you know the number of billboards you will be |
---|
537 | issuing, state it here to make the update more efficient. |
---|
538 | */ |
---|
539 | void beginBillboards(size_t numBillboards = 0); |
---|
540 | /** Define a billboard. */ |
---|
541 | void injectBillboard(const Billboard& bb); |
---|
542 | /** Finish defining billboards. */ |
---|
543 | void endBillboards(void); |
---|
544 | /** Set the bounds of the BillboardSet. |
---|
545 | @remarks |
---|
546 | You may need to call this if you're injecting billboards manually, |
---|
547 | and you're relying on the BillboardSet to determine culling. |
---|
548 | */ |
---|
549 | void setBounds(const AxisAlignedBox& box, Real radius); |
---|
550 | |
---|
551 | |
---|
552 | /** Overridden from MovableObject |
---|
553 | @see |
---|
554 | MovableObject |
---|
555 | */ |
---|
556 | virtual const AxisAlignedBox& getBoundingBox(void) const; |
---|
557 | |
---|
558 | /** Overridden from MovableObject |
---|
559 | @see |
---|
560 | MovableObject |
---|
561 | */ |
---|
562 | virtual Real getBoundingRadius(void) const; |
---|
563 | /** Overridden from MovableObject |
---|
564 | @see |
---|
565 | MovableObject |
---|
566 | */ |
---|
567 | virtual void _updateRenderQueue(RenderQueue* queue); |
---|
568 | |
---|
569 | /** Overridden from MovableObject |
---|
570 | @see |
---|
571 | MovableObject |
---|
572 | */ |
---|
573 | virtual const MaterialPtr& getMaterial(void) const; |
---|
574 | |
---|
575 | /** Overridden from MovableObject |
---|
576 | @see |
---|
577 | MovableObject |
---|
578 | */ |
---|
579 | virtual void getRenderOperation(RenderOperation& op); |
---|
580 | |
---|
581 | /** Overridden from MovableObject |
---|
582 | @see |
---|
583 | MovableObject |
---|
584 | */ |
---|
585 | virtual void getWorldTransforms(Matrix4* xform) const; |
---|
586 | |
---|
587 | /** @copydoc Renderable::getWorldOrientation */ |
---|
588 | const Quaternion& getWorldOrientation(void) const; |
---|
589 | /** @copydoc Renderable::getWorldPosition */ |
---|
590 | const Vector3& getWorldPosition(void) const; |
---|
591 | /** Internal callback used by Billboards to notify their parent that they have been resized. |
---|
592 | */ |
---|
593 | virtual void _notifyBillboardResized(void); |
---|
594 | |
---|
595 | /** Internal callback used by Billboards to notify their parent that they have been rotated.. |
---|
596 | */ |
---|
597 | virtual void _notifyBillboardRotated(void); |
---|
598 | |
---|
599 | /** Returns whether or not billbards in this are tested individually for culling. */ |
---|
600 | virtual bool getCullIndividually(void) const; |
---|
601 | /** Sets whether culling tests billboards in this individually as well as in a group. |
---|
602 | @remarks |
---|
603 | Billboard sets are always culled as a whole group, based on a bounding box which |
---|
604 | encloses all billboards in the set. For fairly localised sets, this is enough. However, you |
---|
605 | can optionally tell the set to also cull individual billboards in the set, i.e. to test |
---|
606 | each individual billboard before rendering. The default is not to do this. |
---|
607 | @par |
---|
608 | This is useful when you have a large, fairly distributed set of billboards, like maybe |
---|
609 | trees on a landscape. You probably still want to group them into more than one |
---|
610 | set (maybe one set per section of landscape), which will be culled coarsely, but you also |
---|
611 | want to cull the billboards individually because they are spread out. Whilst you could have |
---|
612 | lots of single-tree sets which are culled separately, this would be inefficient to render |
---|
613 | because each tree would be issued as it's own rendering operation. |
---|
614 | @par |
---|
615 | By calling this method with a parameter of true, you can have large billboard sets which |
---|
616 | are spaced out and so get the benefit of batch rendering and coarse culling, but also have |
---|
617 | fine-grained culling so unnecessary rendering is avoided. |
---|
618 | @param cullIndividual If true, each billboard is tested before being sent to the pipeline as well |
---|
619 | as the whole set having to pass the coarse group bounding test. |
---|
620 | */ |
---|
621 | virtual void setCullIndividually(bool cullIndividual); |
---|
622 | |
---|
623 | /** Sets the type of billboard to render. |
---|
624 | @remarks |
---|
625 | The default sort of billboard (BBT_POINT), always has both x and y axes parallel to |
---|
626 | the camera's local axes. This is fine for 'point' style billboards (e.g. flares, |
---|
627 | smoke, anything which is symmetrical about a central point) but does not look good for |
---|
628 | billboards which have an orientation (e.g. an elongated raindrop). In this case, the |
---|
629 | oriented billboards are more suitable (BBT_ORIENTED_COMMON or BBT_ORIENTED_SELF) since |
---|
630 | they retain an independant Y axis and only the X axis is generated, perpendicular to both |
---|
631 | the local Y and the camera Z. |
---|
632 | @par |
---|
633 | In some case you might want the billboard has fixed Z axis and doesn't need to face to |
---|
634 | camera (e.g. an aureola around the player and parallel to the ground). You can use |
---|
635 | BBT_PERPENDICULAR_SELF which the billboard plane perpendicular to the billboard own |
---|
636 | direction. Or BBT_PERPENDICULAR_COMMON which the billboard plane perpendicular to the |
---|
637 | common direction. |
---|
638 | @note |
---|
639 | BBT_PERPENDICULAR_SELF and BBT_PERPENDICULAR_COMMON can't guarantee counterclockwise, you might |
---|
640 | use double-side material (<b>cull_hardware node</b>) to ensure no billboard are culled. |
---|
641 | @param bbt The type of billboard to render |
---|
642 | */ |
---|
643 | virtual void setBillboardType(BillboardType bbt); |
---|
644 | |
---|
645 | /** Returns the billboard type in use. */ |
---|
646 | virtual BillboardType getBillboardType(void) const; |
---|
647 | |
---|
648 | /** Use this to specify the common direction given to billboards of type BBT_ORIENTED_COMMON or BBT_PERPENDICULAR_COMMON. |
---|
649 | @remarks |
---|
650 | Use BBT_ORIENTED_COMMON when you want oriented billboards but you know they are always going to |
---|
651 | be oriented the same way (e.g. rain in calm weather). It is faster for the system to calculate |
---|
652 | the billboard vertices if they have a common direction. |
---|
653 | @par |
---|
654 | The common direction also use in BBT_PERPENDICULAR_COMMON, in this case the common direction |
---|
655 | treat as Z axis, and an additional common up-vector was use to determine billboard X and Y |
---|
656 | axis. |
---|
657 | @see setCommonUpVector |
---|
658 | @param vec The direction for all billboards. |
---|
659 | @note |
---|
660 | The direction are use as is, never normalised in internal, user are supposed to normalise it himself. |
---|
661 | */ |
---|
662 | virtual void setCommonDirection(const Vector3& vec); |
---|
663 | |
---|
664 | /** Gets the common direction for all billboards (BBT_ORIENTED_COMMON) */ |
---|
665 | virtual const Vector3& getCommonDirection(void) const; |
---|
666 | |
---|
667 | /** Use this to specify the common up-vector given to billboards of type BBT_PERPENDICULAR_SELF or BBT_PERPENDICULAR_COMMON. |
---|
668 | @remarks |
---|
669 | Use BBT_PERPENDICULAR_SELF or BBT_PERPENDICULAR_COMMON when you want oriented billboards |
---|
670 | perpendicular to specify direction vector (or, Z axis), and doesn't face to camera. |
---|
671 | In this case, we need an additional up-vector to determine the billboard X and Y axis. |
---|
672 | The generated billboard plane and X-axis guarantee perpendicular to specify direction. |
---|
673 | @see setCommonDirection |
---|
674 | @par |
---|
675 | The specify direction is billboard own direction when billboard type is BBT_PERPENDICULAR_SELF, |
---|
676 | and it's shared common direction when billboard type is BBT_PERPENDICULAR_COMMON. |
---|
677 | @param vec The up-vector for all billboards. |
---|
678 | @note |
---|
679 | The up-vector are use as is, never normalised in internal, user are supposed to normalise it himself. |
---|
680 | */ |
---|
681 | virtual void setCommonUpVector(const Vector3& vec); |
---|
682 | |
---|
683 | /** Gets the common up-vector for all billboards (BBT_PERPENDICULAR_SELF and BBT_PERPENDICULAR_COMMON) */ |
---|
684 | virtual const Vector3& getCommonUpVector(void) const; |
---|
685 | |
---|
686 | /** Sets whether or not billboards should use an 'accurate' facing model |
---|
687 | based on the vector from each billboard to the camera, rather than |
---|
688 | an optimised version using just the camera direction. |
---|
689 | @remarks |
---|
690 | By default, the axes for all billboards are calulated using the |
---|
691 | camera's view direction, not the vector from the camera position to |
---|
692 | the billboard. The former is faster, and most of the time the difference |
---|
693 | is not noticeable. However for some purposes (e.g. very large, static |
---|
694 | billboards) the changing billboard orientation when rotating the camera |
---|
695 | can be off putting, therefore you can enable this option to use a |
---|
696 | more expensive, but more accurate version. |
---|
697 | @param acc True to use the slower but more accurate model. Default is false. |
---|
698 | */ |
---|
699 | virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; } |
---|
700 | /** Gets whether or not billboards use an 'accurate' facing model |
---|
701 | based on the vector from each billboard to the camera, rather than |
---|
702 | an optimised version using just the camera direction. |
---|
703 | */ |
---|
704 | virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; } |
---|
705 | |
---|
706 | /** Overridden from MovableObject */ |
---|
707 | virtual const String& getMovableType(void) const; |
---|
708 | |
---|
709 | /** Overridden, see Renderable */ |
---|
710 | Real getSquaredViewDepth(const Camera* cam) const; |
---|
711 | |
---|
712 | /** Update the bounds of the billboardset */ |
---|
713 | virtual void _updateBounds(void); |
---|
714 | /** @copydoc Renderable::getLights */ |
---|
715 | const LightList& getLights(void) const; |
---|
716 | |
---|
717 | /** Sort the billboard set. Only called when enabled via setSortingEnabled */ |
---|
718 | virtual void _sortBillboards( Camera* cam); |
---|
719 | |
---|
720 | /** Gets the sort mode of this billboard set */ |
---|
721 | virtual SortMode _getSortMode(void) const; |
---|
722 | |
---|
723 | /** Sets whether billboards should be treated as being in world space. |
---|
724 | @remarks |
---|
725 | This is most useful when you are driving the billboard set from |
---|
726 | an external data source. |
---|
727 | */ |
---|
728 | virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; } |
---|
729 | |
---|
730 | /** BillboardSet can use custom texture coordinates for various billboards. |
---|
731 | This is useful for selecting one of many particle images out of a tiled |
---|
732 | texture sheet, or doing flipbook animation within a single texture. |
---|
733 | @par |
---|
734 | The generic functionality is setTextureCoords(), which will copy the |
---|
735 | texture coordinate rects you supply into internal storage for the |
---|
736 | billboard set. If your texture sheet is a square grid, you can also |
---|
737 | use setTextureStacksAndSlices() for more convenience, which will construct |
---|
738 | the set of texture coordinates for you. |
---|
739 | @par |
---|
740 | When a Billboard is created, it can be assigned a texture coordinate |
---|
741 | set from within the sets you specify (that set can also be re-specified |
---|
742 | later). When drawn, the billboard will use those texture coordinates, |
---|
743 | rather than the full 0-1 range. |
---|
744 | @par |
---|
745 | @param coords is a vector of texture coordinates (in UV space) to choose |
---|
746 | from for each billboard created in the set. |
---|
747 | @param numCoords is how many such coordinate rectangles there are to |
---|
748 | choose from. |
---|
749 | @remarks |
---|
750 | Set 'coords' to 0 and/or 'numCoords' to 0 to reset the texture coord |
---|
751 | rects to the initial set of a single rectangle spanning 0 through 1 in |
---|
752 | both U and V (i e, the entire texture). |
---|
753 | @see |
---|
754 | BillboardSet::setTextureStacksAndSlices() |
---|
755 | Billboard::setTexcoordIndex() |
---|
756 | */ |
---|
757 | virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords ); |
---|
758 | |
---|
759 | /** setTextureStacksAndSlices() will generate texture coordinate rects as if the |
---|
760 | texture for the billboard set contained 'stacks' rows of 'slices' |
---|
761 | images each, all equal size. Thus, if the texture size is 512x512 |
---|
762 | and 'stacks' is 4 and 'slices' is 8, each sub-rectangle of the texture |
---|
763 | would be 128 texels tall and 64 texels wide. |
---|
764 | @remarks |
---|
765 | This function is short-hand for creating a regular set and calling |
---|
766 | setTextureCoords() yourself. The numbering used for Billboard::setTexcoordIndex() |
---|
767 | counts first across, then down, so top-left is 0, the one to the right |
---|
768 | of that is 1, and the lower-right is stacks*slices-1. |
---|
769 | @see |
---|
770 | BillboardSet::setTextureCoords() |
---|
771 | */ |
---|
772 | virtual void setTextureStacksAndSlices( uchar stacks, uchar slices ); |
---|
773 | |
---|
774 | /** getTextureCoords() returns the current texture coordinate rects in |
---|
775 | effect. By default, there is only one texture coordinate rect in the |
---|
776 | set, spanning the entire texture from 0 through 1 in each direction. |
---|
777 | @see |
---|
778 | BillboardSet::setTextureCoords() |
---|
779 | */ |
---|
780 | virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords ); |
---|
781 | |
---|
782 | /** Set whether or not the BillboardSet will use point rendering |
---|
783 | rather than manually generated quads. |
---|
784 | @remarks |
---|
785 | By default a billboardset is rendered by generating geometry for a |
---|
786 | textured quad in memory, taking into account the size and |
---|
787 | orientation settings, and uploading it to the video card. |
---|
788 | The alternative is to use hardware point rendering, which means that |
---|
789 | only one position needs to be sent per billboard rather than 4 and |
---|
790 | the hardware sorts out how this is rendered based on the render |
---|
791 | state. |
---|
792 | @par |
---|
793 | Using point rendering is faster than generating quads manually, but |
---|
794 | is more restrictive. The following restrictions apply: |
---|
795 | \li Only the BBT_POINT type is supported |
---|
796 | \li Size and appearance of each billboard is controlled by the |
---|
797 | material (Pass::setPointSize, Pass::setPointSizeAttenuation, |
---|
798 | Pass::setPointSpritesEnabled) |
---|
799 | \li Per-billboard size is not supported (stems from the above) |
---|
800 | \li Per-billboard rotation is not supported, this can only be |
---|
801 | controlled through texture unit rotation |
---|
802 | \li Only BBO_CENTER origin is supported |
---|
803 | \li Per-billboard texture coordinates are not supported |
---|
804 | |
---|
805 | @par |
---|
806 | You will almost certainly want to enable in your material pass |
---|
807 | both point attenuation and point sprites if you use this option. |
---|
808 | @param enabled True to enable point rendering, false otherwise |
---|
809 | */ |
---|
810 | virtual void setPointRenderingEnabled(bool enabled); |
---|
811 | |
---|
812 | /** Returns whether point rendering is enabled. */ |
---|
813 | virtual bool isPointRenderingEnabled(void) const |
---|
814 | { return mPointRendering; } |
---|
815 | |
---|
816 | /// Override to return specific type flag |
---|
817 | uint32 getTypeFlags(void) const; |
---|
818 | |
---|
819 | }; |
---|
820 | |
---|
821 | /** Factory object for creating BillboardSet instances */ |
---|
822 | class _OgreExport BillboardSetFactory : public MovableObjectFactory |
---|
823 | { |
---|
824 | protected: |
---|
825 | MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); |
---|
826 | public: |
---|
827 | BillboardSetFactory() {} |
---|
828 | ~BillboardSetFactory() {} |
---|
829 | |
---|
830 | static String FACTORY_TYPE_NAME; |
---|
831 | |
---|
832 | const String& getType(void) const; |
---|
833 | void destroyInstance( MovableObject* obj); |
---|
834 | |
---|
835 | }; |
---|
836 | |
---|
837 | |
---|
838 | } |
---|
839 | |
---|
840 | |
---|
841 | #endif |
---|