source: OGRE/trunk/ogre_changes/Ogre1.2/OgreMain/include/OgreBillboardSet.h @ 768

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