Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# deBrush_priv.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deBrush_priv.hpp
    00003 ///
    00004 /// @brief Private Geometry Calculation & storage header
    00005 ///
    00006 /// @author Assassin
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date Oct 2002
    00023 /// @author Assassin
    00024 /// @remarks Creation
    00025 ///
    00026 ///////////////////////////////////////////////////////////////////////////////
    00027
    00028 #ifndef DEBRUSH_PRIV_HPP
    00029 #define DEBRUSH_PRIV_HPP
    00030
    00031 #include "deBrush.hpp"
    00032 #include "deMath.hpp"
    00033 #include "deLine.hpp"
    00034 #include "deHash.hpp"
    00035 #include "deFunctors.hpp"
    00036 #include "deWorld_Helper.hpp"
    00037
    00038 class deBPoly
    00039 {
    00040 public:
    00041     deVec3d Normal;
    00042     deDouble Dist;
    00043     deLVert *Verts;
    00044     long TextureIndex;
    00045     long NumVerts;
    00046     deBPoly(long verts = 3);
    00047     ~deBPoly();
    00048     deBPoly(const deBPoly & ref) ;
    00049     deBPoly & operator=(deBPoly & ref);
    00050     void Resize(long verts);
    00051 };
    00052
    00053 #pragma warning (disable : 4512) // assignment operator
    00054 //=======================================================
    00055 class deBrush : public deWorldObject, virtual public IdeBrush
    00056 {
    00057 public:
    00058     virtual ~deBrush();
    00059
    00060     void* GetWOInterface(long interface_id);
    00061     deBoolean Serialize(IdeFile* FS);
    00062     deBoolean DeSerialize(IdeFile* FS, long DataLength);
    00063     deBoolean DeSerializeLoad();
    00064
    00065     void* GetBrushInterface(deBrushType Type) const;
    00066
    00067     void GetWorldTransform(deTransformInfo & Matrix) const;
    00068 //  void SetWorldTransform(deTransformInfo & Matrix);
    00069     void Rotate(deVec3d &Center, deVec3d &Axis, deDouble Degrees);
    00070     void Rotate(deVec3d &Center, deTransformInfo &M);
    00071     void Translate(deVec3d &Delta);
    00072     void Scale(deVec3d &Center, deDouble Scale);
    00073
    00074     deBoolean Update();
    00075     long GetLOD() const;
    00076     long GetLOD2() const;
    00077     void SetLOD(long LOD);
    00078     void SetLOD2(long LOD2);
    00079
    00080     long GetTexFacesNum();
    00081     long GetTexCoordsNum(long faceindex);
    00082     deTexCoord GetTexCoord(long faceindex, long index);
    00083     void SetTexCoord(long faceindex, long index, deTexCoord &coord);
    00084     void SetTexCoord(long faceindex, long index, deFloat u, deFloat v);
    00085     void SetTexture(long faceindex, IdeRenderTexture * tex);
    00086     IdeRenderTexture* GetTexture(long faceindex);
    00087     void SetSmooth(deBoolean SmoothNotSharp);
    00088     deBoolean GetSmooth();
    00089
    00090     long GetNumCVs();
    00091     void GetCVList(deVec3d buffer[]);
    00092     deVec3d GetCV(long num);
    00093     deBoolean SetCV(long num, deVec3d & CV);
    00094     deBoolean SetCVList(long num, deVec3d CVList[]);
    00095     deBoolean AddCV(deVec3d & point);
    00096
    00097     IdeBrush * Copy();
    00098
    00099     void GetAABB(deVec3d &Mins, deVec3d &Maxs);
    00100 //  deTList <deBPoly> & GetPolyList();
    00101 //  void GetPolyList(deTList <deBPoly*> & list);
    00102     long GetNumVBs();
    00103     IdeVertexBuffer * GetVertexBuffer(long index);
    00104     void SetDiffuseColor(deARGB color);
    00105     deARGB GetDiffuseColor();
    00106
    00107     void Subtract(IdeBrush * cutter);
    00108
    00109     static void MakeTri(deBPoly & Result,
    00110                 deVec3d &Vert1, deVec3d &Vert2, deVec3d &Vert3);
    00111     static void MakeTri(deBPoly & Result,
    00112                 deVec3d &Vert1, deVec3d &Vert2, deVec3d &Vert3,
    00113                 deVec3d &Norm1, deVec3d &Norm2, deVec3d &Norm3);
    00114     static void MakeTri(deBPoly & Result,
    00115                 deVec3d &Vert1, deVec3d &Vert2, deVec3d &Vert3,
    00116                 deVec3d &Norm1, deVec3d &Norm2, deVec3d &Norm3,
    00117                 deColor &Color1, deColor &Color2, deColor &Color3);
    00118     static void MakeTri(deBPoly & Result,
    00119                 deVec3d &Vert1, deVec3d &Vert2, deVec3d &Vert3,
    00120                 deVec3d &Norm1, deVec3d &Norm2, deVec3d &Norm3,
    00121                 deTexCoord &Coord1, deTexCoord &Coord2, deTexCoord &Coord3);
    00122     static void MakeTri(deBPoly & Result,
    00123                 deVec3d &Vert1, deVec3d &Vert2, deVec3d &Vert3,
    00124                 deVec3d &Norm1, deVec3d &Norm2, deVec3d &Norm3,
    00125                 deColor &Color1, deColor &Color2, deColor &Color3,
    00126                 deTexCoord &Coord1, deTexCoord &Coord2, deTexCoord &Coord3);
    00127
    00128     struct DataQuantity_t
    00129     {
    00130         enum QuantityRatio_t
    00131         {
    00132             Quantity_Unmanaged = 0,
    00133             Quantity_Constant,
    00134             Quantity_PerCV,
    00135             Quantity_Force32 = 0x7fffffff,
    00136         } QuantityRatio;
    00137         long CVNum;         // used to allow fractional amounts (example: 2 CVs = 1 texture)
    00138         long NumFaces;      // number of textured faces
    00139         long CoordsPerFace; // number of UV coordinate pairs per face (don't all need to be used)
    00140     };
    00141
    00142
    00143 protected:
    00144     // methods
    00145     deBrush(IdeBrush::deBrushType Type, const DataQuantity_t &QuantityDefs);
    00146
    00147     enum DrawType
    00148     {
    00149         Points,
    00150         LineList,
    00151         LineStrip,
    00152         TriList = 0,
    00153         TriStrip,
    00154         TriFan
    00155     };
    00156     // methods for specific brushes to implement
    00157     virtual void SpecificRotate(deVec3d Center, deTransformInfo &M);
    00158     virtual void SpecificTranslate(deVec3d Delta);
    00159     virtual void SpecificScale(deVec3d Center, deDouble Scale);
    00160     virtual void UpdateBrush() = 0;
    00161     virtual deBrush * CopyBrush() = 0;
    00162     // internal data-handling methods
    00163     deBoolean FillVertexBuffers();
    00164     deBoolean FillIndexedBuffers();
    00165     void ClearGeometry();
    00166     void ResizeLists(long size);
    00167     deBoolean RecalcListQuantities(deBoolean Creation = deFALSE);
    00168
    00169 protected:
    00170     // variables for storing persistent data
    00171     const DataQuantity_t&               m_QuantityDefs;
    00172     deTransform                         m_WorldTransform;
    00173     long                                m_CVNum;
    00174     deTArray <deVec3d>                  m_CVList;
    00175     deTArray <deTArray<deTexCoord> >    m_FaceList;
    00176     deTArray <IdeRenderTexture*>        m_TextureList;
    00177     deTArray <IdeVertexBuffer*>         m_SubVBs;
    00178     deTArray <DrawType>                 m_DrawTypeList;
    00179     IdeVertexBuffer*                    m_MainVBuffer;
    00180     long                                m_LOD, m_LOD2;
    00181     deBoolean                           m_SmoothNormals;
    00182     deBoolean                           m_Changed;
    00183     deBoolean                           m_UsingIndexedBuffer;
    00184     deBoolean                           m_SaveVBuffers;
    00185     deARGB                              m_DiffuseColor;
    00186
    00187     // variables for storing "built" data
    00188     deTList <deBPoly>                   m_PolyList;
    00189     deTArray <deTList <BIndexList> >    m_IndexedBuffers;
    00190     deTArray <deIDPair>                 m_CachedTextures;
    00191
    00192     // variables that need removing
    00193 //  deTArray <IdeVertexBuffer*> m_VBuffers;
    00194
    00195 //  deTArray <IdeRenderTexture*> m_TextureList;
    00196 //  IdeGroupBrush * m_GroupParent;
    00197 //  BrushOctree *m_Octree;
    00198
    00199 private:
    00200     const IdeBrush::deBrushType m_Type;
    00201 };
    00202
    00203 class deGroupBrush : public IdeGroupBrush, public deBrush
    00204 {
    00205 public:
    00206     deGroupBrush();
    00207     ~deGroupBrush();
    00208
    00209     WorldObjectClassDef;
    00210
    00211     bool AddBrush(IdeBrush* brush);
    00212     bool RemoveBrush(IdeBrush* brush);
    00213
    00214     void GetBrushList(deTList <IdeBrush*> &list);
    00215
    00216 protected:
    00217     deBrush * CopyBrush();
    00218     void SpecificRotate(deVec3d Center, deTransformInfo &M);
    00219     void SpecificTranslate(deVec3d Delta);
    00220     void SpecificScale(deVec3d Center, deDouble Scale);
    00221
    00222 private:
    00223     void UpdateBrush();
    00224     deTList <IdeBrush*> m_BrushList;
    00225 };
    00226
    00227 class deLineBrush : public IdeLineBrush, public deBrush
    00228 {
    00229 public:
    00230     deLineBrush();
    00231     ~deLineBrush();
    00232
    00233     WorldObjectClassDef;
    00234
    00235 protected:
    00236     deBrush * CopyBrush();
    00237
    00238 private:
    00239     void UpdateBrush();
    00240 };
    00241
    00242 struct edge_normals { bool PairedFaces; short CV1, CV2; deVec3d Norm1, Norm2; };
    00243 struct edge { short p1, p2, p_opp; };
    00244 class deBlockBrush : public IdeBlockBrush, public deBrush
    00245 {
    00246 public:
    00247     deBlockBrush();
    00248     ~deBlockBrush();
    00249
    00250     WorldObjectClassDef;
    00251
    00252     deBoolean GetProjectedEdgePlanes(const deVec3d & Position, const deTransformInfo & transform, IdePlaneFrustum* pFrustum);
    00253
    00254 protected:
    00255     deBrush * CopyBrush();
    00256
    00257 private:
    00258     void UpdateBrush();
    00259
    00260     void SubdivideSurfaces();   // LOD calculator
    00261
    00262     // convex hull functions
    00263     // based on methods described at
    00264     // http://www.cse.unsw.edu.au/~lambert/java/3d/giftwrap.html
    00265     void GiftWrap();
    00266     short FindA();
    00267     short FindB(short A);
    00268     short FindC(short A, short B, short DontUse);
    00269     bool PointTotallyUsed(short p);
    00270     void RecalcEdgeConnectivity();
    00271
    00272     deTArray <bool> m_TotallyUsed;
    00273     deTArray< deTList<edge> > m_EdgesOnVert;
    00274     deTArray <edge> m_FaceList;
    00275     deTArray<edge_normals> m_EdgeNormals;
    00276     deBoolean m_EdgesUpdated;
    00277
    00278     deDouble Dist(deBPoly & poly, deVec3d Point);   // positive in front
    00279     void MakeTri(long v1, long v2, long v3, deBPoly&);  // CCW winding
    00280 };
    00281
    00282 class deCylinderBrush : public IdeCylinderBrush, public deBrush
    00283 {
    00284 public:
    00285     deCylinderBrush();
    00286     ~deCylinderBrush();
    00287
    00288     WorldObjectClassDef;
    00289
    00290 protected:
    00291     deBrush * CopyBrush();
    00292
    00293 private:
    00294     void UpdateBrush();
    00295
    00296     void GenerateHull();
    00297     void GenerateHull2();
    00298     deDouble Dist(const deVec3d &LineP1, const deVec3d &LineP2, const deVec3d &P3);
    00299 };
    00300
    00301 class deLathedBrush : public IdeLathedBrush, public deBrush
    00302 {
    00303 public:
    00304     deLathedBrush();
    00305     ~deLathedBrush();
    00306
    00307     WorldObjectClassDef;
    00308
    00309     void SetLine(IdeLine * line);
    00310     IdeLine * GetLine();
    00311
    00312     void SetStyle(LatheStyle style);
    00313     LatheStyle GetStyle();
    00314     void SetDegree(deDouble RotDegree);
    00315     deDouble GetDegree();
    00316
    00317 protected:
    00318     deBrush * CopyBrush();
    00319
    00320 private:
    00321     void UpdateBrush();
    00322
    00323     void Lathe();
    00324     deDouble Dist(deVec3d LineP1, deVec3d LineP2, deVec3d Pt);
    00325
    00326     IdeLine * m_Line;
    00327     LatheStyle m_Style;
    00328     deDouble m_Degree;
    00329 };
    00330
    00331 class deExtrudedBrush : public IdeExtrudedBrush, public deBrush
    00332 {
    00333 public:
    00334     deExtrudedBrush();
    00335     ~deExtrudedBrush();
    00336
    00337     WorldObjectClassDef;
    00338
    00339     void SetSourceLine(IdeLine * line);
    00340     void SetExtrudeLine(IdeLine * line);
    00341     void MakeSolid(deBoolean IsSolid);
    00342
    00343 protected:
    00344     deBrush * CopyBrush();
    00345
    00346 private:
    00347     void UpdateBrush();
    00348
    00349     void Extrude();
    00350
    00351     IdeLine * m_SourceLine;
    00352     IdeLine * m_ExtrudeLine;
    00353     bool m_Solid;
    00354 };
    00355
    00356 class deXMesh;
    00357 class deStaticBrush : public IdeStaticBrush, public deBrush
    00358 {
    00359 public:
    00360     deStaticBrush();
    00361     ~deStaticBrush();
    00362
    00363     WorldObjectClassDef;
    00364
    00365     void SetTextureState(IdeRenderTexture* texture);
    00366     void AddPoly(deBPoly & poly);
    00367     void AddIndexedBuffer(BIndexList indexbuffer);
    00368     void BuildIndexedBuffers();
    00369
    00370     deBoolean AddVertices(const deBrushVertexData & vertexdata, long & indexoffset);
    00371     deBoolean AddIndices(const deBrushIndexData & vertexdata, long indexoffset);
    00372
    00373     friend deBoolean IdeBrush_LoadFromXFile(char * filename, deTList<IdeStaticBrush*> & brushplist);
    00374     friend deBoolean MakeStaticBrushList(deXMesh * mesh, deTList<IdeStaticBrush*> & brushplist);
    00375
    00376 protected:
    00377     deBrush * CopyBrush();
    00378     void SpecificRotate(deVec3d Center, deTransformInfo &M);
    00379     void SpecificTranslate(deVec3d Delta);
    00380     void SpecificScale(deVec3d Center, deDouble Scale);
    00381
    00382 private:
    00383     void UpdateBrush();
    00384
    00385     void MakeArrays();
    00386
    00387     long m_CurrentTexture;
    00388 };
    00389
    00390 class dePrismBrush : public IdePrismBrush, public deBrush
    00391 {
    00392 public:
    00393     dePrismBrush();
    00394     ~dePrismBrush();
    00395
    00396     WorldObjectClassDef;
    00397
    00398 protected:
    00399     deBrush * CopyBrush();
    00400
    00401 private:
    00402     void UpdateBrush();
    00403
    00404     deTArray <dePlane> m_Planes;
    00405
    00406     void GenerateHull();
    00407     deBoolean PlaneIntersectionPoint(dePlane &p1, dePlane &p2, dePlane &p3, deVec3d &p);
    00408 };
    00409
    00410 class deBezierBrush : public deBrush, public IdeBezierBrush
    00411 {
    00412 public:
    00413     deBezierBrush();
    00414     ~deBezierBrush();
    00415
    00416     WorldObjectClassDef;
    00417
    00418 protected:
    00419     deBrush * CopyBrush();
    00420
    00421 private:
    00422     void UpdateBrush();
    00423
    00424     void MakePatches();
    00425     deBoolean m_IsSolid;
    00426 };
    00427
    00428 class deLargeStaticBrush : public deBrush, public IdeLargeStaticBrush
    00429 {
    00430 public:
    00431     deLargeStaticBrush();
    00432     ~deLargeStaticBrush();
    00433
    00434     WorldObjectClassDef;
    00435
    00436     deBoolean SetNumTextures(long NumTextures);
    00437     void SetWorldTransform(deTransformInfo & Matrix);
    00438     deBoolean SetVertexBuffer(long TextureNum, IdeVertexBuffer* VBuffer);
    00439
    00440 protected:
    00441     deBrush * CopyBrush();
    00442
    00443 private:
    00444     void UpdateBrush();
    00445
    00446     void MakePatches();
    00447 };
    00448
    00449 #endif