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 // 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 00041 namespace Ogre { 00042 00076 class _OgreExport BillboardChain : public MovableObject, public Renderable 00077 { 00078 00079 public: 00080 00083 class _OgreExport Element 00084 { 00085 00086 public: 00087 00088 Element(); 00089 00090 Element(const Vector3 &position, 00091 Real width, 00092 Real texCoord, 00093 const ColourValue &colour, 00094 const Quaternion &orientation); 00095 00096 Vector3 position; 00097 Real width; 00099 Real texCoord; 00100 ColourValue colour; 00101 00102 //Only used when mFaceCamera == false 00103 Quaternion orientation; 00104 }; 00105 typedef vector<Element>::type ElementList; 00106 00115 BillboardChain(const String& name, size_t maxElements = 20, size_t numberOfChains = 1, 00116 bool useTextureCoords = true, bool useColours = true, bool dynamic = true); 00118 virtual ~BillboardChain(); 00119 00122 virtual void setMaxChainElements(size_t maxElements); 00125 virtual size_t getMaxChainElements(void) const { return mMaxElementsPerChain; } 00129 virtual void setNumberOfChains(size_t numChains); 00133 virtual size_t getNumberOfChains(void) const { return mChainCount; } 00134 00141 virtual void setUseTextureCoords(bool use); 00145 virtual bool getUseTextureCoords(void) const { return mUseTexCoords; } 00146 00150 enum TexCoordDirection 00151 { 00153 TCD_U, 00155 TCD_V 00156 }; 00161 virtual void setTextureCoordDirection(TexCoordDirection dir); 00165 virtual TexCoordDirection getTextureCoordDirection(void) { return mTexCoordDir; } 00166 00172 virtual void setOtherTextureCoordRange(Real start, Real end); 00176 virtual const Real* getOtherTextureCoordRange(void) const { return mOtherTexCoordRange; } 00177 00184 virtual void setUseVertexColours(bool use); 00188 virtual bool getUseVertexColours(void) const { return mUseVertexColour; } 00189 00193 virtual void setDynamic(bool dyn); 00194 00198 virtual bool getDynamic(void) const { return mDynamic; } 00199 00208 virtual void addChainElement(size_t chainIndex, 00209 const Element& billboardChainElement); 00213 virtual void removeChainElement(size_t chainIndex); 00220 virtual void updateChainElement(size_t chainIndex, size_t elementIndex, 00221 const Element& billboardChainElement); 00227 virtual const Element& getChainElement(size_t chainIndex, size_t elementIndex) const; 00228 00230 virtual size_t getNumChainElements(size_t chainIndex) const; 00231 00233 virtual void clearChain(size_t chainIndex); 00235 virtual void clearAllChains(void); 00236 00253 void setFaceCamera( bool faceCamera, const Vector3 &normalVector=Vector3::UNIT_X ); 00254 00256 virtual const String& getMaterialName(void) const { return mMaterialName; } 00258 virtual void setMaterialName( const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ); 00259 00260 00261 // Overridden members follow 00262 Real getSquaredViewDepth(const Camera* cam) const; 00263 Real getBoundingRadius(void) const; 00264 const AxisAlignedBox& getBoundingBox(void) const; 00265 const MaterialPtr& getMaterial(void) const; 00266 const String& getMovableType(void) const; 00267 void _updateRenderQueue(RenderQueue *); 00268 void getRenderOperation(RenderOperation &); 00269 virtual bool preRender(SceneManager* sm, RenderSystem* rsys); 00270 void getWorldTransforms(Matrix4 *) const; 00271 const LightList& getLights(void) const; 00273 void visitRenderables(Renderable::Visitor* visitor, 00274 bool debugRenderables = false); 00275 00276 00277 00278 protected: 00279 00281 size_t mMaxElementsPerChain; 00283 size_t mChainCount; 00285 bool mUseTexCoords; 00287 bool mUseVertexColour; 00289 bool mDynamic; 00291 VertexData* mVertexData; 00293 IndexData* mIndexData; 00295 bool mVertexDeclDirty; 00297 bool mBuffersNeedRecreating; 00299 mutable bool mBoundsDirty; 00301 bool mIndexContentDirty; 00303 bool mVertexContentDirty; 00305 mutable AxisAlignedBox mAABB; 00307 mutable Real mRadius; 00309 String mMaterialName; 00310 MaterialPtr mMaterial; 00312 TexCoordDirection mTexCoordDir; 00314 Real mOtherTexCoordRange[2]; 00316 Camera *mVertexCameraUsed; 00318 bool mFaceCamera; 00322 Vector3 mNormalBase; 00323 00324 00326 ElementList mChainElementList; 00327 00335 struct ChainSegment 00336 { 00338 size_t start; 00340 size_t head; 00342 size_t tail; 00343 }; 00344 typedef vector<ChainSegment>::type ChainSegmentList; 00345 ChainSegmentList mChainSegmentList; 00346 00348 virtual void setupChainContainers(void); 00350 virtual void setupVertexDeclaration(void); 00351 // Setup buffers 00352 virtual void setupBuffers(void); 00354 virtual void updateVertexBuffer(Camera* cam); 00356 virtual void updateIndexBuffer(void); 00357 virtual void updateBoundingBox(void) const; 00358 00360 static const size_t SEGMENT_EMPTY; 00361 }; 00362 00363 00365 class _OgreExport BillboardChainFactory : public MovableObjectFactory 00366 { 00367 protected: 00368 MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params); 00369 public: 00370 BillboardChainFactory() {} 00371 ~BillboardChainFactory() {} 00372 00373 static String FACTORY_TYPE_NAME; 00374 00375 const String& getType(void) const; 00376 void destroyInstance( MovableObject* obj); 00377 00378 }; 00379 00383 } // namespace 00384 00385 #endif 00386 00387
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:20