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 
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 
00079     class _OgreExport BillboardSet : public MovableObject, public Renderable
00080     {
00081     protected:
00084         BillboardSet();
00085 
00087         String mName;
00088 
00090         AxisAlignedBox mAABB;
00092         Real mBoundingRadius;
00093 
00095         BillboardOrigin mOriginType;
00096 
00098         Real mDefaultWidth;
00100         Real mDefaultHeight;
00101 
00103         String mMaterialName;
00105         MaterialPtr mpMaterial;
00106 
00108         bool mAllDefaultSize;
00109 
00111         bool mAutoExtendPool;
00112 
00113         bool mFixedTextureCoords;
00114         bool mWorldSpace;
00115 
00116         typedef std::list<Billboard*> ActiveBillboardList;
00117         typedef std::deque<Billboard*> FreeBillboardQueue;
00118         typedef std::vector<Billboard*> BillboardPool;
00119 
00128         ActiveBillboardList mActiveBillboards;
00129 
00137         FreeBillboardQueue mFreeBillboards;
00138 
00143         BillboardPool mBillboardPool;
00144 
00145 
00147         VertexData* mVertexData;
00149         HardwareVertexBufferSharedPtr mMainBuf;
00151         float* mLockPtr;
00155         Vector3 mVOffset[4];
00157         Camera* mCurrentCamera;
00158         // Parametric offsets of origin
00159         Real mLeftOff, mRightOff, mTopOff, mBottomOff;
00160         // Camera axes in billboard space
00161         Vector3 mCamX, mCamY;
00162 
00164         //unsigned short* mpIndexes;
00165         IndexData* mIndexData;
00166 
00168         bool mCullIndividual;
00169 
00171         BillboardType mBillboardType;
00172 
00174         Vector3 mCommonDirection;
00175 
00177         inline bool billboardVisible(Camera* cam, const Billboard& bill);
00178 
00179         // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false)
00180         unsigned short mNumVisibleBillboards;
00181 
00183         virtual void increasePool(unsigned int size);
00184 
00185 
00186         //-----------------------------------------------------------------------
00187         // The internal methods which follow are here to allow maximum flexibility as to 
00188         //  when various components of the calculation are done. Depending on whether the
00189         //  billboards are of fixed size and whether they are point or oriented type will
00190         //  determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
00191         //-----------------------------------------------------------------------
00196         virtual void genBillboardAxes(Camera* cam, Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
00197 
00200         void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
00201 
00206         void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
00207 
00215         void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
00216             Real width, Real height,
00217             const Vector3& x, const Vector3& y, Vector3* pDestVec);
00218 
00220         static String msMovableType;
00221 
00222     private:
00224         bool mBuffersCreated;
00226         unsigned int mPoolSize;
00228         bool mExternalData;
00229 
00232         void _createBuffers(void);
00233 
00234     public:
00235 
00255         BillboardSet( const String& name, unsigned int poolSize = 20, 
00256             bool externalDataSource = false);
00257 
00258         virtual ~BillboardSet();
00259 
00277         Billboard* createBillboard(
00278             const Vector3& position,
00279             const ColourValue& colour = ColourValue::White );
00280 
00302         Billboard* createBillboard(
00303             Real x, Real y, Real z,
00304             const ColourValue& colour = ColourValue::White );
00305 
00308         virtual int getNumBillboards(void) const;
00309 
00324         virtual void setAutoextend(bool autoextend);
00325 
00330         virtual bool getAutoextend(void) const;
00331 
00342         virtual void setPoolSize(unsigned int size);
00343 
00350         virtual unsigned int getPoolSize(void) const;
00351 
00352 
00355         virtual void clear();
00356 
00368         virtual Billboard* getBillboard(unsigned int index) const;
00369 
00374         virtual void removeBillboard(unsigned int index);
00375 
00380         virtual void removeBillboard(Billboard* pBill);
00381 
00393         virtual void setBillboardOrigin(BillboardOrigin origin);
00394 
00399         virtual BillboardOrigin getBillboardOrigin(void) const;
00400 
00411         virtual void setDefaultDimensions(Real width, Real height);
00412 
00414         virtual void setDefaultWidth(Real width);
00416         virtual Real getDefaultWidth(void) const;
00418         virtual void setDefaultHeight(Real height);
00420         virtual Real getDefaultHeight(void) const;
00421 
00426         virtual void setMaterialName(const String& name);
00427 
00431         virtual const String& getMaterialName(void) const;
00432 
00437         virtual void _notifyCurrentCamera(Camera* cam);
00438 
00442         void beginBillboards(void);
00444         void injectBillboard(const Billboard& bb);
00446         void endBillboards(void);
00447 
00448 
00453         virtual const AxisAlignedBox& getBoundingBox(void) const;
00454 
00459         virtual Real getBoundingRadius(void) const;
00464         virtual void _updateRenderQueue(RenderQueue* queue);
00465 
00470         virtual const MaterialPtr& getMaterial(void) const;
00471 
00476         virtual void getRenderOperation(RenderOperation& op);
00477 
00482         virtual void getWorldTransforms(Matrix4* xform) const;
00483 
00485         const Quaternion& getWorldOrientation(void) const;
00487         const Vector3& getWorldPosition(void) const;
00490         virtual void _notifyBillboardResized(void);
00491 
00494         virtual void _notifyBillboardTextureCoordsModified(void) {
00495             mFixedTextureCoords = false; }
00496 
00498         virtual bool getCullIndividually(void) const;
00519         virtual void setCullIndividually(bool cullIndividual);
00520 
00531         virtual void setBillboardType(BillboardType bbt);
00532 
00534         virtual BillboardType getBillboardType(void) const;
00535 
00543         virtual void setCommonDirection(const Vector3& vec);
00544 
00546         virtual const Vector3& getCommonDirection(void) const;
00547 
00549         virtual const String& getName(void) const;
00550 
00552         virtual const String& getMovableType(void) const;
00553 
00555         Real getSquaredViewDepth(const Camera* cam) const;
00556 
00558         virtual void _updateBounds(void);
00560         const LightList& getLights(void) const;
00561 
00567         virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
00568 
00569     };
00570 
00571 }
00572 
00573 
00574 #endif

Copyright © 2000-2005 by The OGRE Team
Last modified Sun Apr 10 23:21:12 2005