# 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-2005 The OGRE Team
    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 */
    00025
    00026 #ifndef __BillboardSet_H__
    00027 #define __BillboardSet_H__
    00028
    00029 #include "OgrePrerequisites.h"
    00030
    00031 #include "OgreMovableObject.h"
    00032 #include "OgreRenderable.h"
    00033
    00034 namespace Ogre {
    00035
    00041     enum BillboardOrigin
    00042     {
    00043         BBO_TOP_LEFT,
    00044         BBO_TOP_CENTER,
    00045         BBO_TOP_RIGHT,
    00046         BBO_CENTER_LEFT,
    00047         BBO_CENTER,
    00048         BBO_CENTER_RIGHT,
    00049         BBO_BOTTOM_LEFT,
    00050         BBO_BOTTOM_CENTER,
    00051         BBO_BOTTOM_RIGHT
    00052     };
    00054     enum BillboardType
    00055     {
    00057         BBT_POINT,
    00059         BBT_ORIENTED_COMMON,
    00061         BBT_ORIENTED_SELF
    00062
    00063     };
    00064
    00086     class _OgreExport BillboardSet : public MovableObject, public Renderable
    00087     {
    00088     protected:
    00091         BillboardSet();
    00092
    00094         String mName;
    00095
    00097         AxisAlignedBox mAABB;
    00099         Real mBoundingRadius;
    00100
    00102         BillboardOrigin mOriginType;
    00103
    00105         Real mDefaultWidth;
    00107         Real mDefaultHeight;
    00108
    00110         String mMaterialName;
    00112         MaterialPtr mpMaterial;
    00113
    00115         bool mAllDefaultSize;
    00116
    00118         bool mAutoExtendPool;
    00119
    00120         bool mFixedTextureCoords;
    00121         bool mWorldSpace;
    00122
    00123         typedef std::list<Billboard*> ActiveBillboardList;
    00124         typedef std::deque<Billboard*> FreeBillboardQueue;
    00125         typedef std::vector<Billboard*> BillboardPool;
    00126
    00135         ActiveBillboardList mActiveBillboards;
    00136
    00144         FreeBillboardQueue mFreeBillboards;
    00145
    00150         BillboardPool mBillboardPool;
    00151
    00152
    00154         VertexData* mVertexData;
    00156         HardwareVertexBufferSharedPtr mMainBuf;
    00158         float* mLockPtr;
    00162         Vector3 mVOffset[4];
    00164         Camera* mCurrentCamera;
    00165         // Parametric offsets of origin
    00166         Real mLeftOff, mRightOff, mTopOff, mBottomOff;
    00167         // Camera axes in billboard space
    00168         Vector3 mCamX, mCamY;
    00169
    00171         //unsigned short* mpIndexes;
    00172         IndexData* mIndexData;
    00173
    00175         bool mCullIndividual;
    00176
    00178         BillboardType mBillboardType;
    00179
    00181         Vector3 mCommonDirection;
    00182
    00184         inline bool billboardVisible(Camera* cam, const Billboard& bill);
    00185
    00186         // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false)
    00187         unsigned short mNumVisibleBillboards;
    00188
    00190         virtual void increasePool(unsigned int size);
    00191
    00192
    00193         //-----------------------------------------------------------------------
    00194         // The internal methods which follow are here to allow maximum flexibility as to
    00195         //  when various components of the calculation are done. Depending on whether the
    00196         //  billboards are of fixed size and whether they are point or oriented type will
    00197         //  determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
    00198         //-----------------------------------------------------------------------
    00203         virtual void genBillboardAxes(Camera* cam, Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
    00204
    00207         void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
    00208
    00213         void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
    00214
    00222         void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
    00223             Real width, Real height,
    00224             const Vector3& x, const Vector3& y, Vector3* pDestVec);
    00225
    00227         static String msMovableType;
    00228
    00229     private:
    00231         bool mBuffersCreated;
    00233         unsigned int mPoolSize;
    00235         bool mExternalData;
    00236
    00239         void _createBuffers(void);
    00240
    00241     public:
    00242
    00262         BillboardSet( const String& name, unsigned int poolSize = 20,
    00263             bool externalDataSource = false);
    00264
    00265         virtual ~BillboardSet();
    00266
    00284         Billboard* createBillboard(
    00285             const Vector3& position,
    00286             const ColourValue& colour = ColourValue::White );
    00287
    00309         Billboard* createBillboard(
    00310             Real x, Real y, Real z,
    00311             const ColourValue& colour = ColourValue::White );
    00312
    00315         virtual int getNumBillboards(void) const;
    00316
    00331         virtual void setAutoextend(bool autoextend);
    00332
    00337         virtual bool getAutoextend(void) const;
    00338
    00349         virtual void setPoolSize(unsigned int size);
    00350
    00357         virtual unsigned int getPoolSize(void) const;
    00358
    00359
    00362         virtual void clear();
    00363
    00375         virtual Billboard* getBillboard(unsigned int index) const;
    00376
    00381         virtual void removeBillboard(unsigned int index);
    00382
    00387         virtual void removeBillboard(Billboard* pBill);
    00388
    00400         virtual void setBillboardOrigin(BillboardOrigin origin);
    00401
    00406         virtual BillboardOrigin getBillboardOrigin(void) const;
    00407
    00418         virtual void setDefaultDimensions(Real width, Real height);
    00419
    00421         virtual void setDefaultWidth(Real width);
    00423         virtual Real getDefaultWidth(void) const;
    00425         virtual void setDefaultHeight(Real height);
    00427         virtual Real getDefaultHeight(void) const;
    00428
    00433         virtual void setMaterialName(const String& name);
    00434
    00438         virtual const String& getMaterialName(void) const;
    00439
    00444         virtual void _notifyCurrentCamera(Camera* cam);
    00445
    00449         void beginBillboards(void);
    00451         void injectBillboard(const Billboard& bb);
    00453         void endBillboards(void);
    00459         void setBounds(const AxisAlignedBox& box, Real radius);
    00460
    00461
    00466         virtual const AxisAlignedBox& getBoundingBox(void) const;
    00467
    00472         virtual Real getBoundingRadius(void) const;
    00477         virtual void _updateRenderQueue(RenderQueue* queue);
    00478
    00483         virtual const MaterialPtr& getMaterial(void) const;
    00484
    00489         virtual void getRenderOperation(RenderOperation& op);
    00490
    00495         virtual void getWorldTransforms(Matrix4* xform) const;
    00496
    00498         const Quaternion& getWorldOrientation(void) const;
    00500         const Vector3& getWorldPosition(void) const;
    00503         virtual void _notifyBillboardResized(void);
    00504
    00507         virtual void _notifyBillboardTextureCoordsModified(void) {
    00508             mFixedTextureCoords = false; }
    00509
    00511         virtual bool getCullIndividually(void) const;
    00532         virtual void setCullIndividually(bool cullIndividual);
    00533
    00544         virtual void setBillboardType(BillboardType bbt);
    00545
    00547         virtual BillboardType getBillboardType(void) const;
    00548
    00556         virtual void setCommonDirection(const Vector3& vec);
    00557
    00559         virtual const Vector3& getCommonDirection(void) const;
    00560
    00562         virtual const String& getName(void) const;
    00563
    00565         virtual const String& getMovableType(void) const;
    00566
    00568         Real getSquaredViewDepth(const Camera* cam) const;
    00569
    00571         virtual void _updateBounds(void);
    00573         const LightList& getLights(void) const;
    00574
    00580         virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
    00581
    00582     };
    00583
    00584 }
    00585
    00586
    00587 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Feb 12 12:59:41 2006