Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreBillboardSet.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

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