Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

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 #include "OgreStringInterface.h"
00034 
00035 namespace Ogre {
00036 
00042     enum BillboardOrigin
00043     {
00044         BBO_TOP_LEFT,
00045         BBO_TOP_CENTER,
00046         BBO_TOP_RIGHT,
00047         BBO_CENTER_LEFT,
00048         BBO_CENTER,
00049         BBO_CENTER_RIGHT,
00050         BBO_BOTTOM_LEFT,
00051         BBO_BOTTOM_CENTER,
00052         BBO_BOTTOM_RIGHT
00053     };
00055     enum BillboardType
00056     {
00058         BBT_POINT,
00060         BBT_ORIENTED_COMMON,
00062         BBT_ORIENTED_SELF
00063 
00064     };
00065 
00080     class _OgreExport BillboardSet : public StringInterface, public MovableObject, public Renderable
00081     {
00082     protected:
00085         BillboardSet();
00086 
00088         String mName;
00089 
00091         AxisAlignedBox mAABB;
00093         Real mBoundingRadius;
00094 
00096         BillboardOrigin mOriginType;
00097 
00099         Real mDefaultWidth;
00101         Real mDefaultHeight;
00102 
00104         String mMaterialName;
00106         MaterialPtr mpMaterial;
00107 
00109         bool mAllDefaultSize;
00110 
00112         bool mAutoExtendPool;
00113 
00114         bool mFixedTextureCoords;
00115         bool mWorldSpace;
00116 
00117         typedef std::list<Billboard*> ActiveBillboardList;
00118         typedef std::deque<Billboard*> FreeBillboardQueue;
00119         typedef std::vector<Billboard*> BillboardPool;
00120 
00129         ActiveBillboardList mActiveBillboards;
00130 
00138         FreeBillboardQueue mFreeBillboards;
00139 
00144         BillboardPool mBillboardPool;
00145 
00146 
00148         VertexData* mVertexData;
00150         HardwareVertexBufferSharedPtr mMainBuf;
00152         float* mLockPtr;
00156         Vector3 mVOffset[4];
00158         Camera* mCurrentCamera;
00159         // Parametric offsets of origin
00160         Real mLeftOff, mRightOff, mTopOff, mBottomOff;
00161         // Camera axes in billboard space
00162         Vector3 mCamX, mCamY;
00163 
00165         //unsigned short* mpIndexes;
00166         IndexData* mIndexData;
00167 
00169         bool mCullIndividual;
00170 
00172         BillboardType mBillboardType;
00173 
00175         Vector3 mCommonDirection;
00176 
00178         inline bool billboardVisible(Camera* cam, const Billboard& bill);
00179 
00180         // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false)
00181         unsigned short mNumVisibleBillboards;
00182 
00184         virtual void increasePool(unsigned int size);
00185 
00186 
00187         //-----------------------------------------------------------------------
00188         // The internal methods which follow are here to allow maximum flexibility as to 
00189         //  when various components of the calculation are done. Depending on whether the
00190         //  billboards are of fixed size and whether they are point or oriented type will
00191         //  determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
00192         //-----------------------------------------------------------------------
00197         virtual void genBillboardAxes(Camera* cam, Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
00198 
00201         void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
00202 
00207         void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
00208 
00216         void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
00217             Real width, Real height,
00218             const Vector3& x, const Vector3& y, Vector3* pDestVec);
00219 
00221         static String msMovableType;
00222 
00223     private:
00225         bool mBuffersCreated;
00227         unsigned int mPoolSize;
00229         bool mExternalData;
00230 
00233         void _createBuffers(void);
00234 
00235     public:
00236 
00256         BillboardSet( const String& name, unsigned int poolSize = 20, 
00257             bool externalDataSource = false);
00258 
00259         virtual ~BillboardSet();
00260 
00278         Billboard* createBillboard(
00279             const Vector3& position,
00280             const ColourValue& colour = ColourValue::White );
00281 
00303         Billboard* createBillboard(
00304             Real x, Real y, Real z,
00305             const ColourValue& colour = ColourValue::White );
00306 
00309         virtual int getNumBillboards(void) const;
00310 
00325         virtual void setAutoextend(bool autoextend);
00326 
00331         virtual bool getAutoextend(void) const;
00332 
00343         virtual void setPoolSize(unsigned int size);
00344 
00351         virtual unsigned int getPoolSize(void) const;
00352 
00353 
00356         virtual void clear();
00357 
00369         virtual Billboard* getBillboard(unsigned int index) const;
00370 
00375         virtual void removeBillboard(unsigned int index);
00376 
00381         virtual void removeBillboard(Billboard* pBill);
00382 
00394         virtual void setBillboardOrigin(BillboardOrigin origin);
00395 
00400         virtual BillboardOrigin getBillboardOrigin(void) const;
00401 
00412         virtual void setDefaultDimensions(Real width, Real height);
00413 
00415         virtual void setDefaultWidth(Real width);
00417         virtual Real getDefaultWidth(void) const;
00419         virtual void setDefaultHeight(Real height);
00421         virtual Real getDefaultHeight(void) const;
00422 
00427         virtual void setMaterialName(const String& name);
00428 
00432         virtual const String& getMaterialName(void) const;
00433 
00438         virtual void _notifyCurrentCamera(Camera* cam);
00439 
00443         void beginBillboards(void);
00445         void injectBillboard(const Billboard& bb);
00447         void endBillboards(void);
00448 
00449 
00454         virtual const AxisAlignedBox& getBoundingBox(void) const;
00455 
00460         virtual Real getBoundingRadius(void) const;
00465         virtual void _updateRenderQueue(RenderQueue* queue);
00466 
00471         virtual const MaterialPtr& getMaterial(void) const;
00472 
00477         virtual void getRenderOperation(RenderOperation& op);
00478 
00483         virtual void getWorldTransforms(Matrix4* xform) const;
00484 
00486         const Quaternion& getWorldOrientation(void) const;
00488         const Vector3& getWorldPosition(void) const;
00491         virtual void _notifyBillboardResized(void);
00492 
00495         virtual void _notifyBillboardTextureCoordsModified(void) {
00496             mFixedTextureCoords = false; }
00497 
00499         virtual bool getCullIndividually(void) const;
00520         virtual void setCullIndividually(bool cullIndividual);
00521 
00532         virtual void setBillboardType(BillboardType bbt);
00533 
00535         virtual BillboardType getBillboardType(void) const;
00536 
00544         virtual void setCommonDirection(const Vector3& vec);
00545 
00547         virtual const Vector3& getCommonDirection(void) const;
00548 
00550         virtual const String& getName(void) const;
00551 
00553         virtual const String& getMovableType(void) const;
00554 
00556         Real getSquaredViewDepth(const Camera* cam) const;
00557 
00559         virtual void _updateBounds(void);
00561         const LightList& getLights(void) const;
00562 
00568         virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
00569 
00570     };
00571 
00572 }
00573 
00574 
00575 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Wed Feb 23 00:19:02 2005