# OgreManualObject.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-2009 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 #ifndef __OgreManualObject_H__
    00030 #define __OgreManualObject_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreMovableObject.h"
    00034 #include "OgreRenderable.h"
    00035 #include "OgreResourceGroupManager.h"
    00036
    00037
    00038 namespace Ogre
    00039 {
    00106     class _OgreExport ManualObject : public MovableObject
    00107     {
    00108     public:
    00109         ManualObject(const String& name);
    00110         virtual ~ManualObject();
    00111
    00112         //pre-declare ManualObjectSection
    00113         class ManualObjectSection;
    00114
    00124         virtual void clear(void);
    00125
    00133         virtual void estimateVertexCount(size_t vcount);
    00134
    00142         virtual void estimateIndexCount(size_t icount);
    00143
    00153         virtual void begin(const String& materialName,
    00154             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST, const String & groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00155
    00159         virtual void setDynamic(bool dyn) { mDynamic = dyn; }
    00161         virtual bool getDynamic() const { return mDynamic; }
    00162
    00174         virtual void beginUpdate(size_t sectionIndex);
    00182         virtual void position(const Vector3& pos);
    00184         virtual void position(Real x, Real y, Real z);
    00185
    00191         virtual void normal(const Vector3& norm);
    00193         virtual void normal(Real x, Real y, Real z);
    00194
    00202         virtual void tangent(const Vector3& tan);
    00204         virtual void tangent(Real x, Real y, Real z);
    00205
    00214         virtual void textureCoord(Real u);
    00216         virtual void textureCoord(Real u, Real v);
    00218         virtual void textureCoord(Real u, Real v, Real w);
    00220         virtual void textureCoord(Real x, Real y, Real z, Real w);
    00222         virtual void textureCoord(const Vector2& uv);
    00224         virtual void textureCoord(const Vector3& uvw);
    00226         virtual void textureCoord(const Vector4& xyzw);
    00227
    00230         virtual void colour(const ColourValue& col);
    00234         virtual void colour(Real r, Real g, Real b, Real a = 1.0f);
    00235
    00247         virtual void index(uint32 idx);
    00256         virtual void triangle(uint32 i1, uint32 i2, uint32 i3);
    00265         virtual void quad(uint32 i1, uint32 i2, uint32 i3, uint32 i4);
    00266
    00271         virtual ManualObjectSection* end(void);
    00272
    00282         virtual void setMaterialName(size_t subindex, const String& name, const String & group = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00283
    00295         virtual MeshPtr convertToMesh(const String& meshName,
    00296             const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00297
    00307         void setUseIdentityProjection(bool useIdentityProjection);
    00308
    00318         bool getUseIdentityProjection(void) const { return mUseIdentityProjection; }
    00319
    00329         void setUseIdentityView(bool useIdentityView);
    00330
    00340         bool getUseIdentityView(void) const { return mUseIdentityView; }
    00341
    00349         void setBoundingBox(const AxisAlignedBox& box) { mAABB = box; }
    00350
    00353         ManualObjectSection* getSection(unsigned int index) const;
    00354
    00357         unsigned int getNumSections(void) const;
    00367         void setKeepDeclarationOrder(bool keepOrder) { mKeepDeclarationOrder = keepOrder; }
    00368
    00373         bool getKeepDeclarationOrder() const { return mKeepDeclarationOrder; }
    00374         // MovableObject overrides
    00375
    00377         const String& getMovableType(void) const;
    00379         const AxisAlignedBox& getBoundingBox(void) const;
    00381         Real getBoundingRadius(void) const;
    00383         void _updateRenderQueue(RenderQueue* queue);
    00385         EdgeData* getEdgeList(void);
    00387         bool hasEdgeList(void);
    00389         ShadowRenderableListIterator getShadowVolumeRenderableIterator(
    00390             ShadowTechnique shadowTechnique, const Light* light,
    00391             HardwareIndexBufferSharedPtr* indexBuffer,
    00392             bool extrudeVertices, Real extrusionDist, unsigned long flags = 0);
    00393
    00394
    00396         class _OgreExport ManualObjectSection : public Renderable, public MovableAlloc
    00397         {
    00398         protected:
    00399             ManualObject* mParent;
    00400             String mMaterialName;
    00401             String mGroupName;
    00402             mutable MaterialPtr mMaterial;
    00403             RenderOperation mRenderOperation;
    00404             bool m32BitIndices;
    00405
    00406
    00407         public:
    00408             ManualObjectSection(ManualObject* parent, const String& materialName,
    00409                 RenderOperation::OperationType opType, const String & groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    00410             virtual ~ManualObjectSection();
    00411
    00413             RenderOperation* getRenderOperation(void);
    00415             const String& getMaterialName(void) const { return mMaterialName; }
    00417             const String& getMaterialGroup(void) const { return mGroupName; }
    00419             void setMaterialName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME );
    00421             void set32BitIndices(bool n32) { m32BitIndices = n32; }
    00423             bool get32BitIndices() const { return m32BitIndices; }
    00424
    00425             // Renderable overrides
    00427             const MaterialPtr& getMaterial(void) const;
    00429             void getRenderOperation(RenderOperation& op);
    00431             void getWorldTransforms(Matrix4* xform) const;
    00433             Real getSquaredViewDepth(const Ogre::Camera *) const;
    00435             const LightList &getLights(void) const;
    00436
    00437
    00438
    00439         };
    00441         class _OgreExport ManualObjectSectionShadowRenderable : public ShadowRenderable
    00442         {
    00443         protected:
    00444             ManualObject* mParent;
    00445             // Shared link to position buffer
    00446             HardwareVertexBufferSharedPtr mPositionBuffer;
    00447             // Shared link to w-coord buffer (optional)
    00448             HardwareVertexBufferSharedPtr mWBuffer;
    00449
    00450         public:
    00451             ManualObjectSectionShadowRenderable(ManualObject* parent,
    00452                 HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
    00453                 bool createSeparateLightCap, bool isLightCap = false);
    00454             ~ManualObjectSectionShadowRenderable();
    00456             void getWorldTransforms(Matrix4* xform) const;
    00457             HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
    00458             HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
    00459
    00460         };
    00461
    00462         typedef vector<ManualObjectSection*>::type SectionList;
    00463
    00465         void visitRenderables(Renderable::Visitor* visitor,
    00466             bool debugRenderables = false);
    00467
    00468
    00469     protected:
    00471         bool mDynamic;
    00473         SectionList mSectionList;
    00475         ManualObjectSection* mCurrentSection;
    00477         bool mCurrentUpdating;
    00479         struct TempVertex
    00480         {
    00481             Vector3 position;
    00482             Vector3 normal;
    00483             Vector3 tangent;
    00484             Vector4 texCoord[OGRE_MAX_TEXTURE_COORD_SETS];
    00485             ushort texCoordDims[OGRE_MAX_TEXTURE_COORD_SETS];
    00486             ColourValue colour;
    00487         };
    00489         TempVertex mTempVertex;
    00491         bool mFirstVertex;
    00493         bool mTempVertexPending;
    00495         char* mTempVertexBuffer;
    00497         size_t mTempVertexSize;
    00499         uint32* mTempIndexBuffer;
    00501         size_t mTempIndexSize;
    00503         size_t mDeclSize;
    00505         size_t mEstVertexCount;
    00507         size_t mEstIndexCount;
    00509         ushort mTexCoordIndex;
    00511         AxisAlignedBox mAABB;
    00513         Real mRadius;
    00515         bool mAnyIndexed;
    00517         EdgeData* mEdgeList;
    00519         ShadowRenderableList mShadowRenderables;
    00521         bool mUseIdentityProjection;
    00523         bool mUseIdentityView;
    00525         bool mKeepDeclarationOrder;
    00526
    00527
    00529         virtual void resetTempAreas(void);
    00531         virtual void resizeTempVertexBufferIfNeeded(size_t numVerts);
    00533         virtual void resizeTempIndexBufferIfNeeded(size_t numInds);
    00534
    00536         virtual void copyTempVertexToBuffer(void);
    00537
    00538     };
    00539
    00540
    00542     class _OgreExport ManualObjectFactory : public MovableObjectFactory
    00543     {
    00544     protected:
    00545         MovableObject* createInstanceImpl( const String& name, const NameValuePairList* params);
    00546     public:
    00547         ManualObjectFactory() {}
    00548         ~ManualObjectFactory() {}
    00549
    00550         static String FACTORY_TYPE_NAME;
    00551
    00552         const String& getType(void) const;
    00553         void destroyInstance( MovableObject* obj);
    00554
    00555     };
    00558 }
    00559
    00560 #endif
    00561
    00562

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08