OgreBillboardChain.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-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 // Thanks to Vincent Cantin (karmaGfa) for the original implementation of this
00030 // class, although it has now been mostly rewritten
00031 
00032 #ifndef _BillboardChain_H__
00033 #define _BillboardChain_H__
00034 
00035 #include "OgrePrerequisites.h"
00036 
00037 #include "OgreMovableObject.h"
00038 #include "OgreRenderable.h"
00039 #include "OgreResourceGroupManager.h"
00040 #include "OgreHeaderPrefix.h"
00041 
00042 namespace Ogre {
00043 
00077     class _OgreExport BillboardChain : public MovableObject, public Renderable
00078     {
00079 
00080     public:
00081 
00084         class _OgreExport Element
00085         {
00086 
00087         public:
00088 
00089             Element();
00090 
00091             Element(const Vector3 &position,
00092                 Real width,
00093                 Real texCoord,
00094                 const ColourValue &colour,
00095                 const Quaternion &orientation);
00096 
00097             Vector3 position;
00098             Real width;
00100             Real texCoord;
00101             ColourValue colour;
00102 
00104             Quaternion orientation;
00105         };
00106         typedef vector<Element>::type ElementList;
00107 
00116         BillboardChain(const String& name, size_t maxElements = 20, size_t numberOfChains = 1, 
00117             bool useTextureCoords = true, bool useColours = true, bool dynamic = true);
00119         virtual ~BillboardChain();
00120 
00123         virtual void setMaxChainElements(size_t maxElements);
00126         virtual size_t getMaxChainElements(void) const { return mMaxElementsPerChain; }
00130         virtual void setNumberOfChains(size_t numChains);
00134         virtual size_t getNumberOfChains(void) const { return mChainCount; }
00135 
00142         virtual void setUseTextureCoords(bool use);
00146         virtual bool getUseTextureCoords(void) const { return mUseTexCoords; }
00147 
00151         enum TexCoordDirection
00152         {
00154             TCD_U,
00156             TCD_V
00157         };
00162         virtual void setTextureCoordDirection(TexCoordDirection dir);
00166         virtual TexCoordDirection getTextureCoordDirection(void) { return mTexCoordDir; }
00167 
00173         virtual void setOtherTextureCoordRange(Real start, Real end);
00177         virtual const Real* getOtherTextureCoordRange(void) const { return mOtherTexCoordRange; }
00178 
00185         virtual void setUseVertexColours(bool use);
00189         virtual bool getUseVertexColours(void) const { return mUseVertexColour; }
00190 
00194         virtual void setDynamic(bool dyn);
00195 
00199         virtual bool getDynamic(void) const { return mDynamic; }
00200         
00209         virtual void addChainElement(size_t chainIndex, 
00210             const Element& billboardChainElement);
00214         virtual void removeChainElement(size_t chainIndex);
00221         virtual void updateChainElement(size_t chainIndex, size_t elementIndex, 
00222             const Element& billboardChainElement);
00228         virtual const Element& getChainElement(size_t chainIndex, size_t elementIndex) const;
00229 
00231         virtual size_t getNumChainElements(size_t chainIndex) const;
00232 
00234         virtual void clearChain(size_t chainIndex);
00236         virtual void clearAllChains(void);
00237 
00254         void setFaceCamera( bool faceCamera, const Vector3 &normalVector=Vector3::UNIT_X );
00255 
00257         virtual const String& getMaterialName(void) const { return mMaterialName; }
00259         virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
00260 
00261 
00262         // Overridden members follow
00263         Real getSquaredViewDepth(const Camera* cam) const;
00264         Real getBoundingRadius(void) const;
00265         const AxisAlignedBox& getBoundingBox(void) const;
00266         const MaterialPtr& getMaterial(void) const;
00267         const String& getMovableType(void) const;
00268         void _updateRenderQueue(RenderQueue *);
00269         void getRenderOperation(RenderOperation &);
00270         virtual bool preRender(SceneManager* sm, RenderSystem* rsys);
00271         void getWorldTransforms(Matrix4 *) const;
00272         const LightList& getLights(void) const;
00274         void visitRenderables(Renderable::Visitor* visitor, 
00275             bool debugRenderables = false);
00276 
00277 
00278 
00279     protected:
00280 
00282         size_t mMaxElementsPerChain;
00284         size_t mChainCount;
00286         bool mUseTexCoords;
00288         bool mUseVertexColour;
00290         bool mDynamic;
00292         VertexData* mVertexData;
00294         IndexData* mIndexData;
00296         bool mVertexDeclDirty;
00298         bool mBuffersNeedRecreating;
00300         mutable bool mBoundsDirty;
00302         bool mIndexContentDirty;
00304         bool mVertexContentDirty;
00306         mutable AxisAlignedBox mAABB;
00308         mutable Real mRadius;
00310         String mMaterialName;
00311         MaterialPtr mMaterial;
00313         TexCoordDirection mTexCoordDir;
00315         Real mOtherTexCoordRange[2];
00317         Camera *mVertexCameraUsed;
00319         bool mFaceCamera;
00323         Vector3 mNormalBase;
00324 
00325 
00327         ElementList mChainElementList;
00328 
00336         struct ChainSegment
00337         {
00339             size_t start;
00341             size_t head;
00343             size_t tail;
00344         };
00345         typedef vector<ChainSegment>::type ChainSegmentList;
00346         ChainSegmentList mChainSegmentList;
00347 
00349         virtual void setupChainContainers(void);
00351         virtual void setupVertexDeclaration(void);
00353         virtual void setupBuffers(void);
00355         virtual void updateVertexBuffer(Camera* cam);
00357         virtual void updateIndexBuffer(void);
00358         virtual void updateBoundingBox(void) const;
00359 
00361         static const size_t SEGMENT_EMPTY;
00362     };
00363 
00364 
00366     class _OgreExport BillboardChainFactory : public MovableObjectFactory
00367     {
00368     protected:
00369         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
00370     public:
00371         BillboardChainFactory() {}
00372         ~BillboardChainFactory() {}
00373 
00374         static String FACTORY_TYPE_NAME;
00375 
00376         const String& getType(void) const;
00377         void destroyInstance( MovableObject* obj);  
00378 
00379     };
00380 
00384 } // namespace
00385 
00386 #include "OgreHeaderSuffix.h"
00387 
00388 #endif
00389 
00390 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:40