lugre_robrenderable.h

Go to the documentation of this file.
00001 /*
00002 http://www.opensource.org/licenses/mit-license.php  (MIT-License)
00003 
00004 Copyright (c) 2007 Lugre-Team
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022 THE SOFTWARE.
00023 */
00024 #ifndef LUGRE_ROBRENDERABLE_H
00025 #define LUGRE_ROBRENDERABLE_H
00026 #undef min
00027 #undef max
00028 #include <OgrePrerequisites.h>
00029 //#include <Ogre.h>
00030 //#include <OgreRenderOperation.h>
00031 #include <OgreSimpleRenderable.h>
00032 #include <OgreCamera.h>
00033 #include <OgreVector3.h>
00034 
00035 namespace Lugre {
00036 
00037 class cRobRenderOp { public :
00038     // set dynamic if the vertex data is rewritten frequently
00039     // bDynamic == true ->  Ogre::HardwareBuffer::Usage hbu=Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY
00040     // bDynamic == false -> Ogre::HardwareBuffer::Usage hbu=Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE
00041     // opType is one of OT_POINT_LIST,OT_LINE_LIST,OT_LINE_STRIP,OT_TRIANGLE_LIST,OT_TRIANGLE_STRIP,OT_TRIANGLE_FAN
00042     
00044     enum eVertexFormat {
00045         kVertexFormat_none,
00046         kVertexFormat_p,
00047         kVertexFormat_puv,
00048         kVertexFormat_pn,
00049         kVertexFormat_pnuv,
00050         kVertexFormat_pc,
00051         kVertexFormat_puvc,
00052         kVertexFormat_pnc,
00053         kVertexFormat_pnuvc,
00054     };
00055     Ogre::Vector3   mvAABMin;
00056     Ogre::Vector3   mvAABMax;
00057     bool            mbBoundingBoxEmpty;
00058     Ogre::Real      mfBoundingRadius;
00059     Ogre::RenderOperation*  mpRenderOp;
00060     Ogre::AxisAlignedBox*   mpBox;
00061     size_t          miVertexCapacity;
00062     size_t          miIndexCapacity;
00063     size_t          miVertexCount;
00064     size_t          miIndexCount;
00065     size_t          miVertexSize;
00066     bool            mbBufferIsDynamic; 
00067     bool            mbBufferIsReadable; 
00068     bool            mbDynamic;
00069     bool            mbReadable;
00070     bool            mbKeepOldIndices;
00071     eVertexFormat   miVertexFormat;
00072     size_t          miReceivedVertices;
00073     size_t          miReceivedIndices;
00074     Ogre::RenderSystem* mpRenderSys; // for color conversion
00075     
00076     char*           mVertexWritePtr;
00077     unsigned short* mIndexWritePtr;
00078     Ogre::HardwareVertexBufferSharedPtr mHWVBuf;
00079     Ogre::HardwareIndexBufferSharedPtr  mHWIBuf;
00080     
00081     cRobRenderOp(Ogre::RenderOperation* pRenderOp=0,Ogre::AxisAlignedBox* pBox=0);
00082     virtual ~cRobRenderOp();
00083     
00084     void    Begin   (const size_t iVertexCount,const size_t iIndexCount=0,const bool bDynamic=false,const bool bKeepOldIndices=false,
00085                         const Ogre::RenderOperation::OperationType opType=Ogre::RenderOperation::OT_TRIANGLE_LIST,const bool bReadable=false);
00086     void    Vertex  (const Ogre::Vector3& p);
00087     void    Vertex  (const Ogre::Vector3& p,const Ogre::Real u,const Ogre::Real v);
00088     void    Vertex  (const Ogre::Vector3& p,const Ogre::Vector3& n);
00089     void    Vertex  (const Ogre::Vector3& p,const Ogre::Vector3& n,const Ogre::Real u,const Ogre::Real v);
00090     void    Vertex  (const Ogre::Vector3& p,const Ogre::ColourValue& c);
00091     void    Vertex  (const Ogre::Vector3& p,const Ogre::Real u,const Ogre::Real v,const Ogre::ColourValue& c);
00092     void    Vertex  (const Ogre::Vector3& p,const Ogre::Vector3& n,const Ogre::ColourValue& c);
00093     void    Vertex  (const Ogre::Vector3& p,const Ogre::Vector3& n,const Ogre::Real u,const Ogre::Real v,const Ogre::ColourValue& c);
00094     void    Index   (const int i);
00095     void    Index   (const int i,const int j,const int k);
00096     void    End     ();
00097     void    SkipVertices    (const size_t iNum=1);
00098     void    SkipIndices     (const size_t iNum=1);
00099     void    AddToMesh       (Ogre::MeshPtr pMesh, const std::string& sMatName);
00100     void    ConvertToMesh   (const std::string& sMeshName,const std::string& sMatName);
00101     
00102 
00109     Ogre::Real*     StartCustomWriter   (const Ogre::Vector3& vBoundsMin,const Ogre::Vector3& vBoundsMax);
00110     
00114     void            SetVertexFormatFromEnum     (const eVertexFormat miVertexFormat,const int iNumTexCoordsSets=1); 
00115     
00120     Ogre::VertexDeclaration*    GetVertexDecl   ();
00121     
00123     void            _StartWrite                     (const bool bVertexFormatChanged); 
00124     void            _AllocateIndexBufferIfNeeded    (); 
00126     Ogre::Real*     PrepareAddVertex    (const eVertexFormat miVertexFormat,const Ogre::Vector3& p);
00127 
00128     static Ogre::Real GetMaxZ ();
00129 };
00130 
00131 class cRobSimpleRenderable : public cRobRenderOp,  public Ogre::SimpleRenderable { public :
00132     cRobSimpleRenderable();
00133     virtual ~cRobSimpleRenderable();
00134     
00135     void    ConvertToMesh   (const std::string& sMeshName);
00136     void    AddToMesh       (const std::string& sMeshName);
00137     void    AddToMesh       (Ogre::MeshPtr pMesh);
00138     virtual Ogre::Real getBoundingRadius(void) const;
00139     virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
00140 };
00141 
00142 
00143 };
00144 
00145 #endif

Generated on Wed Feb 8 06:00:12 2012 for cpp by  doxygen 1.5.6