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 "OgreRadixSort.h"
00034 #include "OgreCommon.h"
00035 
00036 namespace Ogre {
00037 
00043     enum BillboardOrigin
00044     {
00045         BBO_TOP_LEFT,
00046         BBO_TOP_CENTER,
00047         BBO_TOP_RIGHT,
00048         BBO_CENTER_LEFT,
00049         BBO_CENTER,
00050         BBO_CENTER_RIGHT,
00051         BBO_BOTTOM_LEFT,
00052         BBO_BOTTOM_CENTER,
00053         BBO_BOTTOM_RIGHT
00054     };
00056     enum BillboardRotationType
00057     {
00059         BBR_VERTEX,
00061         BBR_TEXCOORD
00062     };
00064     enum BillboardType
00065     {
00067         BBT_POINT,
00069         BBT_ORIENTED_COMMON,
00071         BBT_ORIENTED_SELF,
00073         BBT_PERPENDICULAR_COMMON,
00075         BBT_PERPENDICULAR_SELF
00076     };
00077 
00099     class _OgreExport BillboardSet : public MovableObject, public Renderable
00100     {
00101     protected:
00104         BillboardSet();
00105 
00107         AxisAlignedBox mAABB;
00109         Real mBoundingRadius;
00110 
00112         BillboardOrigin mOriginType;
00114         BillboardRotationType mRotationType;
00115 
00117         Real mDefaultWidth;
00119         Real mDefaultHeight;
00120 
00122         String mMaterialName;
00124         MaterialPtr mpMaterial;
00125 
00127         bool mAllDefaultSize;
00128 
00130         bool mAutoExtendPool;
00131 
00133         bool mSortingEnabled;
00134 
00135         // Use 'true' billboard to cam position facing, rather than camera direcion
00136         bool mAccurateFacing;
00137 
00138         bool mAllDefaultRotation;
00139         bool mWorldSpace;
00140 
00141         typedef std::list<Billboard*> ActiveBillboardList;
00142         typedef std::list<Billboard*> FreeBillboardList;
00143         typedef std::vector<Billboard*> BillboardPool;
00144 
00153         ActiveBillboardList mActiveBillboards;
00154 
00162         FreeBillboardList mFreeBillboards;
00163 
00168         BillboardPool mBillboardPool;
00169 
00171         VertexData* mVertexData;
00173         HardwareVertexBufferSharedPtr mMainBuf;
00175         float* mLockPtr;
00179         Vector3 mVOffset[4];
00181         Camera* mCurrentCamera;
00182         // Parametric offsets of origin
00183         Real mLeftOff, mRightOff, mTopOff, mBottomOff;
00184         // Camera axes in billboard space
00185         Vector3 mCamX, mCamY;
00186         // Camera direction in billboard space
00187         Vector3 mCamDir;
00188         // Camera orientation in billboard space
00189         Quaternion mCamQ;
00190         // Camera position in billboard space
00191         Vector3 mCamPos;
00192 
00194         //unsigned short* mpIndexes;
00195         IndexData* mIndexData;
00196 
00198         bool mCullIndividual;
00199 
00200         typedef std::vector< Ogre::FloatRect > TextureCoordSets;
00201         TextureCoordSets mTextureCoords;
00202 
00204         BillboardType mBillboardType;
00205 
00207         Vector3 mCommonDirection;
00209         Vector3 mCommonUpVector;
00210 
00212         inline bool billboardVisible(Camera* cam, const Billboard& bill);
00213 
00214         // Number of visible billboards (will be == getNumBillboards if mCullIndividual == false)
00215         unsigned short mNumVisibleBillboards;
00216 
00218         virtual void increasePool(unsigned int size);
00219 
00220 
00221         //-----------------------------------------------------------------------
00222         // The internal methods which follow are here to allow maximum flexibility as to 
00223         //  when various components of the calculation are done. Depending on whether the
00224         //  billboards are of fixed size and whether they are point or oriented type will
00225         //  determine how much calculation has to be done per-billboard. NOT a one-size fits all approach.
00226         //-----------------------------------------------------------------------
00231         void genBillboardAxes(Vector3* pX, Vector3 *pY, const Billboard* pBill = 0);
00232 
00235         void getParametricOffsets(Real& left, Real& right, Real& top, Real& bottom);
00236 
00241         void genVertices(const Vector3* const offsets, const Billboard& pBillboard);
00242 
00250         void genVertOffsets(Real inleft, Real inright, Real intop, Real inbottom,
00251             Real width, Real height,
00252             const Vector3& x, const Vector3& y, Vector3* pDestVec);
00253 
00254 
00256         struct SortByDirectionFunctor
00257         {
00259             Vector3 sortDir;
00260 
00261             SortByDirectionFunctor(const Vector3& dir);
00262             float operator()(Billboard* bill) const;
00263         };
00264 
00266         struct SortByDistanceFunctor
00267         {
00269             Vector3 sortPos;
00270 
00271             SortByDistanceFunctor(const Vector3& pos);
00272             float operator()(Billboard* bill) const;
00273         };
00274 
00275         static RadixSort<ActiveBillboardList, Billboard*, float> mRadixSorter;
00276 
00278         bool mPointRendering;
00279 
00280 
00281 
00282     private:
00284         bool mBuffersCreated;
00286         unsigned int mPoolSize;
00288         bool mExternalData;
00289 
00292         void _createBuffers(void);
00295         void _destroyBuffers(void);
00296 
00297     public:
00298 
00318         BillboardSet( const String& name, unsigned int poolSize = 20, 
00319             bool externalDataSource = false);
00320 
00321         virtual ~BillboardSet();
00322 
00340         Billboard* createBillboard(
00341             const Vector3& position,
00342             const ColourValue& colour = ColourValue::White );
00343 
00365         Billboard* createBillboard(
00366             Real x, Real y, Real z,
00367             const ColourValue& colour = ColourValue::White );
00368 
00371         virtual int getNumBillboards(void) const;
00372 
00387         virtual void setAutoextend(bool autoextend);
00388 
00393         virtual bool getAutoextend(void) const;
00394 
00398         virtual void setSortingEnabled(bool sortenable);
00399 
00404         virtual bool getSortingEnabled(void) const;
00405 
00416         virtual void setPoolSize(unsigned int size);
00417 
00424         virtual unsigned int getPoolSize(void) const;
00425 
00426 
00429         virtual void clear();
00430 
00442         virtual Billboard* getBillboard(unsigned int index) const;
00443 
00448         virtual void removeBillboard(unsigned int index);
00449 
00454         virtual void removeBillboard(Billboard* pBill);
00455 
00467         virtual void setBillboardOrigin(BillboardOrigin origin);
00468 
00473         virtual BillboardOrigin getBillboardOrigin(void) const;
00474 
00484         virtual void setBillboardRotationType(BillboardRotationType rotationType);
00485 
00490         virtual BillboardRotationType getBillboardRotationType(void) const;
00491 
00502         virtual void setDefaultDimensions(Real width, Real height);
00503 
00505         virtual void setDefaultWidth(Real width);
00507         virtual Real getDefaultWidth(void) const;
00509         virtual void setDefaultHeight(Real height);
00511         virtual Real getDefaultHeight(void) const;
00512 
00517         virtual void setMaterialName(const String& name);
00518 
00522         virtual const String& getMaterialName(void) const;
00523 
00528         virtual void _notifyCurrentCamera(Camera* cam);
00529 
00533         void beginBillboards(void);
00535         void injectBillboard(const Billboard& bb);
00537         void endBillboards(void);
00543         void setBounds(const AxisAlignedBox& box, Real radius);
00544 
00545 
00550         virtual const AxisAlignedBox& getBoundingBox(void) const;
00551 
00556         virtual Real getBoundingRadius(void) const;
00561         virtual void _updateRenderQueue(RenderQueue* queue);
00562 
00567         virtual const MaterialPtr& getMaterial(void) const;
00568 
00573         virtual void getRenderOperation(RenderOperation& op);
00574 
00579         virtual void getWorldTransforms(Matrix4* xform) const;
00580 
00582         const Quaternion& getWorldOrientation(void) const;
00584         const Vector3& getWorldPosition(void) const;
00587         virtual void _notifyBillboardResized(void);
00588 
00591         virtual void _notifyBillboardRotated(void);
00592 
00594         virtual bool getCullIndividually(void) const;
00615         virtual void setCullIndividually(bool cullIndividual);
00616 
00637         virtual void setBillboardType(BillboardType bbt);
00638 
00640         virtual BillboardType getBillboardType(void) const;
00641 
00656         virtual void setCommonDirection(const Vector3& vec);
00657 
00659         virtual const Vector3& getCommonDirection(void) const;
00660 
00675         virtual void setCommonUpVector(const Vector3& vec);
00676 
00678         virtual const Vector3& getCommonUpVector(void) const;
00679         
00693         virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; }
00698         virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; }
00699 
00701         virtual const String& getMovableType(void) const;
00702 
00704         Real getSquaredViewDepth(const Camera* cam) const;
00705 
00707         virtual void _updateBounds(void);
00709         const LightList& getLights(void) const;
00710 
00712         virtual void _sortBillboards( Camera* cam);
00713 
00715         virtual SortMode _getSortMode(void) const;
00716 
00722         virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; }
00723 
00751         virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords );
00752 
00766         virtual void setTextureStacksAndSlices( uchar stacks, uchar slices );
00767 
00774         virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords );
00775 
00804         virtual void setPointRenderingEnabled(bool enabled);
00805 
00807         virtual bool isPointRenderingEnabled(void) const
00808         { return mPointRendering; }
00809         
00811         uint32 getTypeFlags(void) const;
00812 
00813     };
00814 
00816     class _OgreExport BillboardSetFactory : public MovableObjectFactory
00817     {
00818     protected:
00819         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00820     public:
00821         BillboardSetFactory() {}
00822         ~BillboardSetFactory() {}
00823 
00824         static String FACTORY_TYPE_NAME;
00825 
00826         const String& getType(void) const;
00827         void destroyInstance( MovableObject* obj);  
00828 
00829     };
00830 
00831 
00832 }
00833 
00834 
00835 #endif

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