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-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 #ifndef __PatchSurface_H__
00029 #define __PatchSurface_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 
00033 #include "OgreVector3.h"
00034 #include "OgreString.h"
00035 #include "OgreRenderOperation.h"
00036 #include "OgreAxisAlignedBox.h"
00037 #include "OgreHeaderPrefix.h"
00038 
00039 namespace Ogre {
00040 
00053     class _OgreExport PatchSurface : public PatchAlloc
00054     {
00055     public:
00056         PatchSurface();
00057         ~PatchSurface();
00058 
00059         enum PatchSurfaceType
00060         {
00062             PST_BEZIER
00063         };
00064 
00066         enum
00067         {
00068             AUTO_LEVEL = -1
00069         };
00070 
00071         enum VisibleSide {
00073             VS_FRONT,
00075             VS_BACK,
00077             VS_BOTH
00078         };
00106         void defineSurface(void* controlPointBuffer, 
00107             VertexDeclaration *declaration, size_t width, size_t height,
00108             PatchSurfaceType pType = PST_BEZIER, 
00109             size_t uMaxSubdivisionLevel = AUTO_LEVEL, size_t vMaxSubdivisionLevel = AUTO_LEVEL,
00110             VisibleSide visibleSide = VS_FRONT);
00111 
00117         size_t getRequiredVertexCount(void) const;
00123         size_t getRequiredIndexCount(void) const;
00124 
00126         size_t getCurrentIndexCount(void) const;
00128         size_t getIndexOffset(void) const { return mIndexOffset; }
00130         size_t getVertexOffset(void) const { return mVertexOffset; }
00131 
00132 
00134         const AxisAlignedBox& getBounds(void) const;
00137         Real getBoundingSphereRadius(void) const;
00153         void build(HardwareVertexBufferSharedPtr destVertexBuffer, size_t vertexStart,
00154             HardwareIndexBufferSharedPtr destIndexBuffer, size_t indexStart);
00155 
00164         void setSubdivisionFactor(Real factor);
00165 
00167         Real getSubdivisionFactor(void) const;
00168 
00169         void* getControlPointBuffer(void) const
00170         {
00171             return mControlPointBuffer;
00172         }
00175         void notifyControlPointBufferDeallocated(void) { 
00176             mControlPointBuffer = 0;
00177         }
00178     protected:
00180         VertexDeclaration* mDeclaration;
00182         void* mControlPointBuffer;
00184         PatchSurfaceType mType;
00186         size_t mCtlWidth;
00188         size_t mCtlHeight;
00190         size_t mCtlCount;
00192         size_t mULevel;
00194         size_t mVLevel;
00196         size_t mMaxULevel;
00197         size_t mMaxVLevel;
00199         size_t mMeshWidth;
00201         size_t mMeshHeight;
00203         VisibleSide mVSide;
00204 
00205         Real mSubdivisionFactor;
00206 
00207         vector<Vector3>::type mVecCtlPoints;
00208 
00211         size_t findLevel( Vector3& a, Vector3& b, Vector3& c);
00212 
00213         void distributeControlPoints(void* lockedBuffer);
00214         void subdivideCurve(void* lockedBuffer, size_t startIdx, size_t stepSize, size_t numSteps, size_t iterations);
00215         void interpolateVertexData(void* lockedBuffer, size_t leftIndex, size_t rightIndex, size_t destIndex);
00216         void makeTriangles(void);
00217 
00218         size_t getAutoULevel(bool forMax = false);
00219         size_t getAutoVLevel(bool forMax = false);
00220 
00221         HardwareVertexBufferSharedPtr mVertexBuffer;
00222         HardwareIndexBufferSharedPtr mIndexBuffer;
00223         size_t mVertexOffset;
00224         size_t mIndexOffset;
00225         size_t mRequiredVertexCount;
00226         size_t mRequiredIndexCount;
00227         size_t mCurrIndexCount;
00228 
00229         AxisAlignedBox mAABB;
00230         Real mBoundingSphere;
00231 
00232 
00233 
00234     };
00235 
00239 } // namespace
00240 
00241 #include "OgreHeaderSuffix.h"
00242 
00243 #endif

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:44