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-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 #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 
00038 namespace Ogre {
00039 
00052     class _OgreExport PatchSurface : public PatchAlloc
00053     {
00054     public:
00055         PatchSurface();
00056         ~PatchSurface();
00057 
00058         enum PatchSurfaceType
00059         {
00061             PST_BEZIER
00062         };
00063 
00065         enum
00066         {
00067             AUTO_LEVEL = -1
00068         };
00069 
00070         enum VisibleSide {
00072             VS_FRONT,
00074             VS_BACK,
00076             VS_BOTH
00077         };
00105         void defineSurface(void* controlPointBuffer, 
00106             VertexDeclaration *declaration, size_t width, size_t height,
00107             PatchSurfaceType pType = PST_BEZIER, 
00108             size_t uMaxSubdivisionLevel = AUTO_LEVEL, size_t vMaxSubdivisionLevel = AUTO_LEVEL,
00109             VisibleSide visibleSide = VS_FRONT);
00110 
00116         size_t getRequiredVertexCount(void) const;
00122         size_t getRequiredIndexCount(void) const;
00123 
00125         size_t getCurrentIndexCount(void) const;
00127         size_t getIndexOffset(void) const { return mIndexOffset; }
00129         size_t getVertexOffset(void) const { return mVertexOffset; }
00130 
00131 
00133         const AxisAlignedBox& getBounds(void) const;
00136         Real getBoundingSphereRadius(void) const;
00152         void build(HardwareVertexBufferSharedPtr destVertexBuffer, size_t vertexStart,
00153             HardwareIndexBufferSharedPtr destIndexBuffer, size_t indexStart);
00154 
00163         void setSubdivisionFactor(Real factor);
00164 
00166         Real getSubdivisionFactor(void) const;
00167 
00168         void* getControlPointBuffer(void) const
00169         {
00170             return mControlPointBuffer;
00171         }
00174         void notifyControlPointBufferDeallocated(void) { 
00175             mControlPointBuffer = 0;
00176         }
00177     protected:
00179         VertexDeclaration* mDeclaration;
00181         void* mControlPointBuffer;
00183         PatchSurfaceType mType;
00185         size_t mCtlWidth;
00187         size_t mCtlHeight;
00189         size_t mCtlCount;
00191         size_t mULevel;
00193         size_t mVLevel;
00195         size_t mMaxULevel;
00196         size_t mMaxVLevel;
00198         size_t mMeshWidth;
00200         size_t mMeshHeight;
00202         VisibleSide mVSide;
00203 
00204         Real mSubdivisionFactor;
00205 
00206         vector<Vector3>::type mVecCtlPoints;
00207 
00210         size_t findLevel( Vector3& a, Vector3& b, Vector3& c);
00211 
00212         void distributeControlPoints(void* lockedBuffer);
00213         void subdivideCurve(void* lockedBuffer, size_t startIdx, size_t stepSize, size_t numSteps, size_t iterations);
00214         void interpolateVertexData(void* lockedBuffer, size_t leftIndex, size_t rightIndex, size_t destIndex);
00215         void makeTriangles(void);
00216 
00217         size_t getAutoULevel(bool forMax = false);
00218         size_t getAutoVLevel(bool forMax = false);
00219 
00220         HardwareVertexBufferSharedPtr mVertexBuffer;
00221         HardwareIndexBufferSharedPtr mIndexBuffer;
00222         size_t mVertexOffset;
00223         size_t mIndexOffset;
00224         size_t mRequiredVertexCount;
00225         size_t mRequiredIndexCount;
00226         size_t mCurrIndexCount;
00227 
00228         AxisAlignedBox mAABB;
00229         Real mBoundingSphere;
00230 
00231 
00232 
00233     };
00234 
00238 } // namespace
00239 
00240 #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 Fri May 25 23:36:25 2012