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-2012 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 mMaterial; 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* mIndexes; 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 setMaterial( const MaterialPtr& material ); 00590 00595 virtual void getRenderOperation(RenderOperation& op); 00596 00601 virtual void getWorldTransforms(Matrix4* xform) const; 00602 00605 virtual void _notifyBillboardResized(void); 00606 00609 virtual void _notifyBillboardRotated(void); 00610 00612 virtual bool getCullIndividually(void) const; 00633 virtual void setCullIndividually(bool cullIndividual); 00634 00655 virtual void setBillboardType(BillboardType bbt); 00656 00658 virtual BillboardType getBillboardType(void) const; 00659 00674 virtual void setCommonDirection(const Vector3& vec); 00675 00677 virtual const Vector3& getCommonDirection(void) const; 00678 00693 virtual void setCommonUpVector(const Vector3& vec); 00694 00696 virtual const Vector3& getCommonUpVector(void) const; 00697 00711 virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; } 00716 virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; } 00717 00719 virtual const String& getMovableType(void) const; 00720 00722 Real getSquaredViewDepth(const Camera* cam) const; 00723 00725 virtual void _updateBounds(void); 00727 const LightList& getLights(void) const; 00728 00730 void visitRenderables(Renderable::Visitor* visitor, 00731 bool debugRenderables = false); 00732 00734 virtual void _sortBillboards( Camera* cam); 00735 00737 virtual SortMode _getSortMode(void) const; 00738 00744 virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; } 00745 00773 virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords ); 00774 00788 virtual void setTextureStacksAndSlices( uchar stacks, uchar slices ); 00789 00796 virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords ); 00797 00826 virtual void setPointRenderingEnabled(bool enabled); 00827 00829 virtual bool isPointRenderingEnabled(void) const 00830 { return mPointRendering; } 00831 00833 uint32 getTypeFlags(void) const; 00834 00844 void setAutoUpdate(bool autoUpdate); 00845 00847 bool getAutoUpdate(void) const { return mAutoUpdate; } 00848 00853 void notifyBillboardDataChanged(void) { mBillboardDataChanged = true; } 00854 00855 }; 00856 00858 class _OgreExport BillboardSetFactory : public MovableObjectFactory 00859 { 00860 protected: 00861 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00862 public: 00863 BillboardSetFactory() {} 00864 ~BillboardSetFactory() {} 00865 00866 static String FACTORY_TYPE_NAME; 00867 00868 const String& getType(void) const; 00869 void destroyInstance( MovableObject* obj); 00870 00871 }; 00875 } 00876 00877 00878 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:23 2012