OGRE: OgreBillboardSet.h Source File - OGRE Documentation

# 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-2009 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __BillboardSet_H__
    00030 #define __BillboardSet_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033
    00034 #include "OgreMovableObject.h"
    00035 #include "OgreRenderable.h"
    00036 #include "OgreRadixSort.h"
    00037 #include "OgreCommon.h"
    00038 #include "OgreResourceGroupManager.h"
    00039
    00040 namespace Ogre {
    00053     enum BillboardOrigin
    00054     {
    00055         BBO_TOP_LEFT,
    00056         BBO_TOP_CENTER,
    00057         BBO_TOP_RIGHT,
    00058         BBO_CENTER_LEFT,
    00059         BBO_CENTER,
    00060         BBO_CENTER_RIGHT,
    00061         BBO_BOTTOM_LEFT,
    00062         BBO_BOTTOM_CENTER,
    00063         BBO_BOTTOM_RIGHT
    00064     };
    00066     enum BillboardRotationType
    00067     {
    00069         BBR_VERTEX,
    00071         BBR_TEXCOORD
    00072     };
    00074     enum BillboardType
    00075     {
    00077         BBT_POINT,
    00079         BBT_ORIENTED_COMMON,
    00081         BBT_ORIENTED_SELF,
    00083         BBT_PERPENDICULAR_COMMON,
    00085         BBT_PERPENDICULAR_SELF
    00086     };
    00087
    00109     class _OgreExport BillboardSet : public MovableObject, public Renderable
    00110     {
    00111     protected:
    00114         BillboardSet();
    00115
    00117         AxisAlignedBox mAABB;
    00119         Real mBoundingRadius;
    00120
    00122         BillboardOrigin mOriginType;
    00124         BillboardRotationType mRotationType;
    00125
    00127         Real mDefaultWidth;
    00129         Real mDefaultHeight;
    00130
    00132         String mMaterialName;
    00134         MaterialPtr mpMaterial;
    00135
    00137         bool mAllDefaultSize;
    00138
    00140         bool mAutoExtendPool;
    00141
    00143         bool mSortingEnabled;
    00144
    00145         // Use 'true' billboard to cam position facing, rather than camera direcion
    00146         bool mAccurateFacing;
    00147
    00148         bool mAllDefaultRotation;
    00149         bool mWorldSpace;
    00150
    00151         typedef list<Billboard*>::type ActiveBillboardList;
    00152         typedef list<Billboard*>::type FreeBillboardList;
    00153         typedef vector<Billboard*>::type BillboardPool;
    00154
    00163         ActiveBillboardList mActiveBillboards;
    00164
    00172         FreeBillboardList mFreeBillboards;
    00173
    00178         BillboardPool mBillboardPool;
    00179
    00181         VertexData* mVertexData;
    00183         HardwareVertexBufferSharedPtr mMainBuf;
    00185         float* mLockPtr;
    00189         Vector3 mVOffset[4];
    00191         Camera* mCurrentCamera;
    00192         // Parametric offsets of origin
    00193         Real mLeftOff, mRightOff, mTopOff, mBottomOff;
    00194         // Camera axes in billboard space
    00195         Vector3 mCamX, mCamY;
    00196         // Camera direction in billboard space
    00197         Vector3 mCamDir;
    00198         // Camera orientation in billboard space
    00199         Quaternion mCamQ;
    00200         // Camera position in billboard space
    00201         Vector3 mCamPos;
    00202
    00204         //unsigned short* mpIndexes;
    00205         IndexData* mIndexData;
    00206
    00208         bool mCullIndividual;
    00209
    00210         typedef vector< Ogre::FloatRect >::type TextureCoordSets;
    00211         TextureCoordSets mTextureCoords;
    00212
    00214         BillboardType mBillboardType;
    00215
    00217         Vector3 mCommonDirection;
    00219         Vector3 mCommonUpVector;
    00220
    00222         inline bool billboardVisible(Camera* cam, const Billboard& bill);
    00223
    00224         // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false)
    00225         unsigned short mNumVisibleBillboards;
    00226
    00228         virtual void increasePool(size_t size);
    00229
    00230
    00231         //-----------------------------------------------------------------------
    00232         // The internal methods which follow are here to allow maximum flexibility as to
    00233         //  when various components of the calculation are done. Depending on whether the
    00234         //  billboards are of fixed size and whether they are point or oriented type will
    00235         //  determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
    00236         //-----------------------------------------------------------------------
    00241         void genBillboardAxes(Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
    00242
    00245         void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
    00246
    00251         void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
    00252
    00260         void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
    00261             Real width, Real height,
    00262             const Vector3& x, const Vector3& y, Vector3* pDestVec);
    00263
    00264
    00266         struct SortByDirectionFunctor
    00267         {
    00269             Vector3 sortDir;
    00270
    00271             SortByDirectionFunctor(const Vector3& dir);
    00272             float operator()(Billboard* bill) const;
    00273         };
    00274
    00276         struct SortByDistanceFunctor
    00277         {
    00279             Vector3 sortPos;
    00280
    00281             SortByDistanceFunctor(const Vector3& pos);
    00282             float operator()(Billboard* bill) const;
    00283         };
    00284
    00285         static RadixSort<ActiveBillboardList, Billboard*, float> mRadixSorter;
    00286
    00288         bool mPointRendering;
    00289
    00290
    00291
    00292     private:
    00294         bool mBuffersCreated;
    00296         size_t mPoolSize;
    00298         bool mExternalData;
    00300         bool mAutoUpdate;
    00302         bool mBillboardDataChanged;
    00303
    00306         void _createBuffers(void);
    00309         void _destroyBuffers(void);
    00310
    00311     public:
    00312
    00332         BillboardSet( const String& name, unsigned int poolSize = 20,
    00333             bool externalDataSource = false);
    00334
    00335         virtual ~BillboardSet();
    00336
    00354         Billboard* createBillboard(
    00355             const Vector3& position,
    00356             const ColourValue& colour = ColourValue::White );
    00357
    00379         Billboard* createBillboard(
    00380             Real x, Real y, Real z,
    00381             const ColourValue& colour = ColourValue::White );
    00382
    00385         virtual int getNumBillboards(void) const;
    00386
    00401         virtual void setAutoextend(bool autoextend);
    00402
    00407         virtual bool getAutoextend(void) const;
    00408
    00412         virtual void setSortingEnabled(bool sortenable);
    00413
    00418         virtual bool getSortingEnabled(void) const;
    00419
    00430         virtual void setPoolSize(size_t size);
    00431
    00438         virtual unsigned int getPoolSize(void) const;
    00439
    00440
    00443         virtual void clear();
    00444
    00456         virtual Billboard* getBillboard(unsigned int index) const;
    00457
    00462         virtual void removeBillboard(unsigned int index);
    00463
    00468         virtual void removeBillboard(Billboard* pBill);
    00469
    00481         virtual void setBillboardOrigin(BillboardOrigin origin);
    00482
    00487         virtual BillboardOrigin getBillboardOrigin(void) const;
    00488
    00498         virtual void setBillboardRotationType(BillboardRotationType rotationType);
    00499
    00504         virtual BillboardRotationType getBillboardRotationType(void) const;
    00505
    00516         virtual void setDefaultDimensions(Real width, Real height);
    00517
    00519         virtual void setDefaultWidth(Real width);
    00521         virtual Real getDefaultWidth(void) const;
    00523         virtual void setDefaultHeight(Real height);
    00525         virtual Real getDefaultHeight(void) const;
    00526
    00531         virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
    00532
    00536         virtual const String& getMaterialName(void) const;
    00537
    00542         virtual void _notifyCurrentCamera(Camera* cam);
    00543
    00549         void beginBillboards(size_t numBillboards = 0);
    00551         void injectBillboard(const Billboard& bb);
    00553         void endBillboards(void);
    00559         void setBounds(const AxisAlignedBox& box, Real radius);
    00560
    00561
    00566         virtual const AxisAlignedBox& getBoundingBox(void) const;
    00567
    00572         virtual Real getBoundingRadius(void) const;
    00577         virtual void _updateRenderQueue(RenderQueue* queue);
    00578
    00583         virtual const MaterialPtr& getMaterial(void) const;
    00584
    00589         virtual void getRenderOperation(RenderOperation& op);
    00590
    00595         virtual void getWorldTransforms(Matrix4* xform) const;
    00596
    00599         virtual void _notifyBillboardResized(void);
    00600
    00603         virtual void _notifyBillboardRotated(void);
    00604
    00606         virtual bool getCullIndividually(void) const;
    00627         virtual void setCullIndividually(bool cullIndividual);
    00628
    00649         virtual void setBillboardType(BillboardType bbt);
    00650
    00652         virtual BillboardType getBillboardType(void) const;
    00653
    00668         virtual void setCommonDirection(const Vector3& vec);
    00669
    00671         virtual const Vector3& getCommonDirection(void) const;
    00672
    00687         virtual void setCommonUpVector(const Vector3& vec);
    00688
    00690         virtual const Vector3& getCommonUpVector(void) const;
    00691
    00705         virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; }
    00710         virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; }
    00711
    00713         virtual const String& getMovableType(void) const;
    00714
    00716         Real getSquaredViewDepth(const Camera* cam) const;
    00717
    00719         virtual void _updateBounds(void);
    00721         const LightList& getLights(void) const;
    00722
    00724         void visitRenderables(Renderable::Visitor* visitor,
    00725             bool debugRenderables = false);
    00726
    00728         virtual void _sortBillboards( Camera* cam);
    00729
    00731         virtual SortMode _getSortMode(void) const;
    00732
    00738         virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
    00739
    00767         virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords );
    00768
    00782         virtual void setTextureStacksAndSlices( uchar stacks, uchar slices );
    00783
    00790         virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords );
    00791
    00820         virtual void setPointRenderingEnabled(bool enabled);
    00821
    00823         virtual bool isPointRenderingEnabled(void) const
    00824         { return mPointRendering; }
    00825
    00827         uint32 getTypeFlags(void) const;
    00828
    00838         void setAutoUpdate(bool autoUpdate);
    00839
    00841         bool getAutoUpdate(void) const { return mAutoUpdate; }
    00842
    00847         void notifyBillboardDataChanged(void) { mBillboardDataChanged = true; }
    00848
    00849     };
    00850
    00852     class _OgreExport BillboardSetFactory : public MovableObjectFactory
    00853     {
    00854     protected:
    00855         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
    00856     public:
    00857         BillboardSetFactory() {}
    00858         ~BillboardSetFactory() {}
    00859
    00860         static String FACTORY_TYPE_NAME;
    00861
    00862         const String& getType(void) const;
    00863         void destroyInstance( MovableObject* obj);
    00864
    00865     };
    00869 }
    00870
    00871
    00872 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:51