# OgreBillboardSet.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029
    00030 #ifndef __BillboardSet_H__
    00031 #define __BillboardSet_H__
    00032
    00033 #include "OgrePrerequisites.h"
    00034
    00035 #include "OgreMovableObject.h"
    00036 #include "OgreRenderable.h"
    00037 #include "OgreRadixSort.h"
    00038 #include "OgreCommon.h"
    00039
    00040 namespace Ogre {
    00041
    00047     enum BillboardOrigin
    00048     {
    00049         BBO_TOP_LEFT,
    00050         BBO_TOP_CENTER,
    00051         BBO_TOP_RIGHT,
    00052         BBO_CENTER_LEFT,
    00053         BBO_CENTER,
    00054         BBO_CENTER_RIGHT,
    00055         BBO_BOTTOM_LEFT,
    00056         BBO_BOTTOM_CENTER,
    00057         BBO_BOTTOM_RIGHT
    00058     };
    00060     enum BillboardRotationType
    00061     {
    00063         BBR_VERTEX,
    00065         BBR_TEXCOORD
    00066     };
    00068     enum BillboardType
    00069     {
    00071         BBT_POINT,
    00073         BBT_ORIENTED_COMMON,
    00075         BBT_ORIENTED_SELF,
    00077         BBT_PERPENDICULAR_COMMON,
    00079         BBT_PERPENDICULAR_SELF
    00080     };
    00081
    00103     class _OgreExport BillboardSet : public MovableObject, public Renderable
    00104     {
    00105     protected:
    00108         BillboardSet();
    00109
    00111         AxisAlignedBox mAABB;
    00113         Real mBoundingRadius;
    00114
    00116         BillboardOrigin mOriginType;
    00118         BillboardRotationType mRotationType;
    00119
    00121         Real mDefaultWidth;
    00123         Real mDefaultHeight;
    00124
    00126         String mMaterialName;
    00128         MaterialPtr mpMaterial;
    00129
    00131         bool mAllDefaultSize;
    00132
    00134         bool mAutoExtendPool;
    00135
    00137         bool mSortingEnabled;
    00138
    00139         // Use 'true' billboard to cam position facing, rather than camera direcion
    00140         bool mAccurateFacing;
    00141
    00142         bool mAllDefaultRotation;
    00143         bool mWorldSpace;
    00144
    00145         typedef std::list<Billboard*> ActiveBillboardList;
    00146         typedef std::list<Billboard*> FreeBillboardList;
    00147         typedef std::vector<Billboard*> BillboardPool;
    00148
    00157         ActiveBillboardList mActiveBillboards;
    00158
    00166         FreeBillboardList mFreeBillboards;
    00167
    00172         BillboardPool mBillboardPool;
    00173
    00175         VertexData* mVertexData;
    00177         HardwareVertexBufferSharedPtr mMainBuf;
    00179         float* mLockPtr;
    00183         Vector3 mVOffset[4];
    00185         Camera* mCurrentCamera;
    00186         // Parametric offsets of origin
    00187         Real mLeftOff, mRightOff, mTopOff, mBottomOff;
    00188         // Camera axes in billboard space
    00189         Vector3 mCamX, mCamY;
    00190         // Camera direction in billboard space
    00191         Vector3 mCamDir;
    00192         // Camera orientation in billboard space
    00193         Quaternion mCamQ;
    00194         // Camera position in billboard space
    00195         Vector3 mCamPos;
    00196
    00198         //unsigned short* mpIndexes;
    00199         IndexData* mIndexData;
    00200
    00202         bool mCullIndividual;
    00203
    00204         typedef std::vector< Ogre::FloatRect > TextureCoordSets;
    00205         TextureCoordSets mTextureCoords;
    00206
    00208         BillboardType mBillboardType;
    00209
    00211         Vector3 mCommonDirection;
    00213         Vector3 mCommonUpVector;
    00214
    00216         inline bool billboardVisible(Camera* cam, const Billboard& bill);
    00217
    00218         // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false)
    00219         unsigned short mNumVisibleBillboards;
    00220
    00222         virtual void increasePool(size_t size);
    00223
    00224
    00225         //-----------------------------------------------------------------------
    00226         // The internal methods which follow are here to allow maximum flexibility as to
    00227         //  when various components of the calculation are done. Depending on whether the
    00228         //  billboards are of fixed size and whether they are point or oriented type will
    00229         //  determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
    00230         //-----------------------------------------------------------------------
    00235         void genBillboardAxes(Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
    00236
    00239         void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
    00240
    00245         void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
    00246
    00254         void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
    00255             Real width, Real height,
    00256             const Vector3& x, const Vector3& y, Vector3* pDestVec);
    00257
    00258
    00260         struct SortByDirectionFunctor
    00261         {
    00263             Vector3 sortDir;
    00264
    00265             SortByDirectionFunctor(const Vector3& dir);
    00266             float operator()(Billboard* bill) const;
    00267         };
    00268
    00270         struct SortByDistanceFunctor
    00271         {
    00273             Vector3 sortPos;
    00274
    00275             SortByDistanceFunctor(const Vector3& pos);
    00276             float operator()(Billboard* bill) const;
    00277         };
    00278
    00279         static RadixSort<ActiveBillboardList, Billboard*, float> mRadixSorter;
    00280
    00282         bool mPointRendering;
    00283
    00284
    00285
    00286     private:
    00288         bool mBuffersCreated;
    00290         size_t mPoolSize;
    00292         bool mExternalData;
    00293
    00296         void _createBuffers(void);
    00299         void _destroyBuffers(void);
    00300
    00301     public:
    00302
    00322         BillboardSet( const String& name, unsigned int poolSize = 20,
    00323             bool externalDataSource = false);
    00324
    00325         virtual ~BillboardSet();
    00326
    00344         Billboard* createBillboard(
    00345             const Vector3& position,
    00346             const ColourValue& colour = ColourValue::White );
    00347
    00369         Billboard* createBillboard(
    00370             Real x, Real y, Real z,
    00371             const ColourValue& colour = ColourValue::White );
    00372
    00375         virtual int getNumBillboards(void) const;
    00376
    00391         virtual void setAutoextend(bool autoextend);
    00392
    00397         virtual bool getAutoextend(void) const;
    00398
    00402         virtual void setSortingEnabled(bool sortenable);
    00403
    00408         virtual bool getSortingEnabled(void) const;
    00409
    00420         virtual void setPoolSize(size_t size);
    00421
    00428         virtual unsigned int getPoolSize(void) const;
    00429
    00430
    00433         virtual void clear();
    00434
    00446         virtual Billboard* getBillboard(unsigned int index) const;
    00447
    00452         virtual void removeBillboard(unsigned int index);
    00453
    00458         virtual void removeBillboard(Billboard* pBill);
    00459
    00471         virtual void setBillboardOrigin(BillboardOrigin origin);
    00472
    00477         virtual BillboardOrigin getBillboardOrigin(void) const;
    00478
    00488         virtual void setBillboardRotationType(BillboardRotationType rotationType);
    00489
    00494         virtual BillboardRotationType getBillboardRotationType(void) const;
    00495
    00506         virtual void setDefaultDimensions(Real width, Real height);
    00507
    00509         virtual void setDefaultWidth(Real width);
    00511         virtual Real getDefaultWidth(void) const;
    00513         virtual void setDefaultHeight(Real height);
    00515         virtual Real getDefaultHeight(void) const;
    00516
    00521         virtual void setMaterialName(const String& name);
    00522
    00526         virtual const String& getMaterialName(void) const;
    00527
    00532         virtual void _notifyCurrentCamera(Camera* cam);
    00533
    00539         void beginBillboards(size_t numBillboards = 0);
    00541         void injectBillboard(const Billboard& bb);
    00543         void endBillboards(void);
    00549         void setBounds(const AxisAlignedBox& box, Real radius);
    00550
    00551
    00556         virtual const AxisAlignedBox& getBoundingBox(void) const;
    00557
    00562         virtual Real getBoundingRadius(void) const;
    00567         virtual void _updateRenderQueue(RenderQueue* queue);
    00568
    00573         virtual const MaterialPtr& getMaterial(void) const;
    00574
    00579         virtual void getRenderOperation(RenderOperation& op);
    00580
    00585         virtual void getWorldTransforms(Matrix4* xform) const;
    00586
    00589         virtual void _notifyBillboardResized(void);
    00590
    00593         virtual void _notifyBillboardRotated(void);
    00594
    00596         virtual bool getCullIndividually(void) const;
    00617         virtual void setCullIndividually(bool cullIndividual);
    00618
    00639         virtual void setBillboardType(BillboardType bbt);
    00640
    00642         virtual BillboardType getBillboardType(void) const;
    00643
    00658         virtual void setCommonDirection(const Vector3& vec);
    00659
    00661         virtual const Vector3& getCommonDirection(void) const;
    00662
    00677         virtual void setCommonUpVector(const Vector3& vec);
    00678
    00680         virtual const Vector3& getCommonUpVector(void) const;
    00681
    00695         virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; }
    00700         virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; }
    00701
    00703         virtual const String& getMovableType(void) const;
    00704
    00706         Real getSquaredViewDepth(const Camera* cam) const;
    00707
    00709         virtual void _updateBounds(void);
    00711         const LightList& getLights(void) const;
    00712
    00714         void visitRenderables(Renderable::Visitor* visitor,
    00715             bool debugRenderables = false);
    00716
    00718         virtual void _sortBillboards( Camera* cam);
    00719
    00721         virtual SortMode _getSortMode(void) const;
    00722
    00728         virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
    00729
    00757         virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords );
    00758
    00772         virtual void setTextureStacksAndSlices( uchar stacks, uchar slices );
    00773
    00780         virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords );
    00781
    00810         virtual void setPointRenderingEnabled(bool enabled);
    00811
    00813         virtual bool isPointRenderingEnabled(void) const
    00814         { return mPointRendering; }
    00815
    00817         uint32 getTypeFlags(void) const;
    00818
    00819     };
    00820
    00822     class _OgreExport BillboardSetFactory : public MovableObjectFactory
    00823     {
    00824     protected:
    00825         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
    00826     public:
    00827         BillboardSetFactory() {}
    00828         ~BillboardSetFactory() {}
    00829
    00830         static String FACTORY_TYPE_NAME;
    00831
    00832         const String& getType(void) const;
    00833         void destroyInstance( MovableObject* obj);
    00834
    00835     };
    00836
    00837
    00838 }
    00839
    00840
    00841 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Jul 26 11:32:16 2009