OgrePatchSurface.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-2006 Torus Knot Software Ltd
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 
00024 You may alternatively use this source under the terms of a specific version of
00025 the OGRE Unrestricted License provided you have obtained such a license from
00026 Torus Knot Software Ltd.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef __PatchSurface_H__
00030 #define __PatchSurface_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 
00034 #include "OgreVector3.h"
00035 #include "OgreString.h"
00036 #include "OgreRenderOperation.h"
00037 #include "OgreAxisAlignedBox.h"
00038 
00039 namespace Ogre {
00040 
00047     class _OgreExport PatchSurface : public PatchAlloc
00048     {
00049     public:
00050         PatchSurface();
00051         ~PatchSurface();
00052 
00053         enum PatchSurfaceType
00054         {
00056             PST_BEZIER
00057         };
00058 
00060         enum
00061         {
00062             AUTO_LEVEL = -1
00063         };
00064 
00065         enum VisibleSide {
00067             VS_FRONT,
00069             VS_BACK,
00071             VS_BOTH
00072         };
00100         void defineSurface(void* controlPointBuffer, 
00101             VertexDeclaration *declaration, size_t width, size_t height,
00102             PatchSurfaceType pType = PST_BEZIER, 
00103             size_t uMaxSubdivisionLevel = AUTO_LEVEL, size_t vMaxSubdivisionLevel = AUTO_LEVEL,
00104             VisibleSide visibleSide = VS_FRONT);
00105 
00111         size_t getRequiredVertexCount(void) const;
00117         size_t getRequiredIndexCount(void) const;
00118 
00120         size_t getCurrentIndexCount(void) const;
00122         size_t getIndexOffset(void) const { return mIndexOffset; }
00124         size_t getVertexOffset(void) const { return mVertexOffset; }
00125 
00126 
00128         const AxisAlignedBox& getBounds(void) const;
00131         Real getBoundingSphereRadius(void) const;
00147         void build(HardwareVertexBufferSharedPtr destVertexBuffer, size_t vertexStart,
00148             HardwareIndexBufferSharedPtr destIndexBuffer, size_t indexStart);
00149 
00158         void setSubdivisionFactor(Real factor);
00159 
00161         Real getSubdivisionFactor(void) const;
00162 
00163         void* getControlPointBuffer(void) const
00164         {
00165             return mControlPointBuffer;
00166         }
00169         void notifyControlPointBufferDeallocated(void) { 
00170             mControlPointBuffer = 0;
00171         }
00172     protected:
00174         VertexDeclaration* mDeclaration;
00176         void* mControlPointBuffer;
00178         PatchSurfaceType mType;
00180         size_t mCtlWidth;
00182         size_t mCtlHeight;
00184         size_t mCtlCount;
00186         size_t mULevel;
00188         size_t mVLevel;
00190         size_t mMaxULevel;
00191         size_t mMaxVLevel;
00193         size_t mMeshWidth;
00195         size_t mMeshHeight;
00197         VisibleSide mVSide;
00198 
00199         Real mSubdivisionFactor;
00200 
00201         std::vector<Vector3> mVecCtlPoints;
00202 
00205         size_t findLevel( Vector3& a, Vector3& b, Vector3& c);
00206 
00207         void distributeControlPoints(void* lockedBuffer);
00208         void subdivideCurve(void* lockedBuffer, size_t startIdx, size_t stepSize, size_t numSteps, size_t iterations);
00209         void interpolateVertexData(void* lockedBuffer, size_t leftIndex, size_t rightIndex, size_t destIndex);
00210         void makeTriangles(void);
00211 
00212         size_t getAutoULevel(bool forMax = false);
00213         size_t getAutoVLevel(bool forMax = false);
00214 
00215         HardwareVertexBufferSharedPtr mVertexBuffer;
00216         HardwareIndexBufferSharedPtr mIndexBuffer;
00217         size_t mVertexOffset;
00218         size_t mIndexOffset;
00219         size_t mRequiredVertexCount;
00220         size_t mRequiredIndexCount;
00221         size_t mCurrIndexCount;
00222 
00223         AxisAlignedBox mAABB;
00224         Real mBoundingSphere;
00225 
00226 
00227 
00228     };
00229 
00230 
00231 } // namespace
00232 
00233 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:24 2009