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-2013 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 #include "OgreHeaderPrefix.h" 00040 00041 namespace Ogre { 00054 enum BillboardOrigin 00055 { 00056 BBO_TOP_LEFT, 00057 BBO_TOP_CENTER, 00058 BBO_TOP_RIGHT, 00059 BBO_CENTER_LEFT, 00060 BBO_CENTER, 00061 BBO_CENTER_RIGHT, 00062 BBO_BOTTOM_LEFT, 00063 BBO_BOTTOM_CENTER, 00064 BBO_BOTTOM_RIGHT 00065 }; 00067 enum BillboardRotationType 00068 { 00070 BBR_VERTEX, 00072 BBR_TEXCOORD 00073 }; 00075 enum BillboardType 00076 { 00078 BBT_POINT, 00080 BBT_ORIENTED_COMMON, 00082 BBT_ORIENTED_SELF, 00084 BBT_PERPENDICULAR_COMMON, 00086 BBT_PERPENDICULAR_SELF 00087 }; 00088 00110 class _OgreExport BillboardSet : public MovableObject, public Renderable 00111 { 00112 protected: 00115 BillboardSet(); 00116 00118 AxisAlignedBox mAABB; 00120 Real mBoundingRadius; 00121 00123 BillboardOrigin mOriginType; 00125 BillboardRotationType mRotationType; 00126 00128 Real mDefaultWidth; 00130 Real mDefaultHeight; 00131 00133 String mMaterialName; 00135 MaterialPtr mMaterial; 00136 00138 bool mAllDefaultSize; 00139 00141 bool mAutoExtendPool; 00142 00144 bool mSortingEnabled; 00145 00147 bool mAccurateFacing; 00148 00149 bool mAllDefaultRotation; 00150 bool mWorldSpace; 00151 00152 typedef list<Billboard*>::type ActiveBillboardList; 00153 typedef list<Billboard*>::type FreeBillboardList; 00154 typedef vector<Billboard*>::type BillboardPool; 00155 00164 ActiveBillboardList mActiveBillboards; 00165 00173 FreeBillboardList mFreeBillboards; 00174 00179 BillboardPool mBillboardPool; 00180 00182 VertexData* mVertexData; 00184 HardwareVertexBufferSharedPtr mMainBuf; 00186 float* mLockPtr; 00190 Vector3 mVOffset[4]; 00192 Camera* mCurrentCamera; 00194 Real mLeftOff, mRightOff, mTopOff, mBottomOff; 00196 Vector3 mCamX, mCamY; 00198 Vector3 mCamDir; 00200 Quaternion mCamQ; 00202 Vector3 mCamPos; 00203 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 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 00402 virtual void setAutoextend(bool autoextend); 00403 00408 virtual bool getAutoextend(void) const; 00409 00413 virtual void setSortingEnabled(bool sortenable); 00414 00419 virtual bool getSortingEnabled(void) const; 00420 00431 virtual void setPoolSize(size_t size); 00432 00439 virtual unsigned int getPoolSize(void) const; 00440 00441 00444 virtual void clear(); 00445 00457 virtual Billboard* getBillboard(unsigned int index) const; 00458 00463 virtual void removeBillboard(unsigned int index); 00464 00469 virtual void removeBillboard(Billboard* pBill); 00470 00482 virtual void setBillboardOrigin(BillboardOrigin origin); 00483 00488 virtual BillboardOrigin getBillboardOrigin(void) const; 00489 00499 virtual void setBillboardRotationType(BillboardRotationType rotationType); 00500 00505 virtual BillboardRotationType getBillboardRotationType(void) const; 00506 00517 virtual void setDefaultDimensions(Real width, Real height); 00518 00520 virtual void setDefaultWidth(Real width); 00522 virtual Real getDefaultWidth(void) const; 00524 virtual void setDefaultHeight(Real height); 00526 virtual Real getDefaultHeight(void) const; 00527 00532 virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ); 00533 00537 virtual const String& getMaterialName(void) const; 00538 00543 virtual void _notifyCurrentCamera(Camera* cam); 00544 00550 void beginBillboards(size_t numBillboards = 0); 00552 void injectBillboard(const Billboard& bb); 00554 void endBillboards(void); 00560 void setBounds(const AxisAlignedBox& box, Real radius); 00561 00562 00567 virtual const AxisAlignedBox& getBoundingBox(void) const; 00568 00573 virtual Real getBoundingRadius(void) const; 00578 virtual void _updateRenderQueue(RenderQueue* queue); 00579 00584 virtual const MaterialPtr& getMaterial(void) const; 00585 00590 virtual void setMaterial( const MaterialPtr& material ); 00591 00596 virtual void getRenderOperation(RenderOperation& op); 00597 00602 virtual void getWorldTransforms(Matrix4* xform) const; 00603 00606 virtual void _notifyBillboardResized(void); 00607 00610 virtual void _notifyBillboardRotated(void); 00611 00613 virtual bool getCullIndividually(void) const; 00634 virtual void setCullIndividually(bool cullIndividual); 00635 00656 virtual void setBillboardType(BillboardType bbt); 00657 00659 virtual BillboardType getBillboardType(void) const; 00660 00675 virtual void setCommonDirection(const Vector3& vec); 00676 00678 virtual const Vector3& getCommonDirection(void) const; 00679 00694 virtual void setCommonUpVector(const Vector3& vec); 00695 00697 virtual const Vector3& getCommonUpVector(void) const; 00698 00712 virtual void setUseAccurateFacing(bool acc) { mAccurateFacing = acc; } 00717 virtual bool getUseAccurateFacing(void) const { return mAccurateFacing; } 00718 00720 virtual const String& getMovableType(void) const; 00721 00723 Real getSquaredViewDepth(const Camera* cam) const; 00724 00726 virtual void _updateBounds(void); 00728 const LightList& getLights(void) const; 00729 00731 void visitRenderables(Renderable::Visitor* visitor, 00732 bool debugRenderables = false); 00733 00735 virtual void _sortBillboards( Camera* cam); 00736 00738 virtual SortMode _getSortMode(void) const; 00739 00745 virtual void setBillboardsInWorldSpace(bool ws) { mWorldSpace = ws; } 00746 00774 virtual void setTextureCoords( Ogre::FloatRect const * coords, uint16 numCoords ); 00775 00789 virtual void setTextureStacksAndSlices( uchar stacks, uchar slices ); 00790 00797 virtual Ogre::FloatRect const * getTextureCoords( uint16 * oNumCoords ); 00798 00827 virtual void setPointRenderingEnabled(bool enabled); 00828 00830 virtual bool isPointRenderingEnabled(void) const 00831 { return mPointRendering; } 00832 00834 uint32 getTypeFlags(void) const; 00835 00845 void setAutoUpdate(bool autoUpdate); 00846 00848 bool getAutoUpdate(void) const { return mAutoUpdate; } 00849 00854 void notifyBillboardDataChanged(void) { mBillboardDataChanged = true; } 00855 00856 }; 00857 00859 class _OgreExport BillboardSetFactory : public MovableObjectFactory 00860 { 00861 protected: 00862 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00863 public: 00864 BillboardSetFactory() {} 00865 ~BillboardSetFactory() {} 00866 00867 static String FACTORY_TYPE_NAME; 00868 00869 const String& getType(void) const; 00870 void destroyInstance( MovableObject* obj); 00871 00872 }; 00876 } // namespace Ogre 00877 00878 #include "OgreHeaderSuffix.h" 00879 00880 #endif // __BillboardSet_H__
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:40