CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

crysball.h

00001 /*
00002     Copyright (C) 2000 by Norman Krämer
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_CRYSBALL_H__
00020 #define __CS_CRYSBALL_H__
00021 
00022 #include "csutil/tree.h"
00023 #include "csutil/parray.h"
00024 #include "csgeom/vector3.h"
00025 #include "csgeom/math3d.h"
00026 #include "csgeom/transfrm.h"
00027 #include "igeom/polymesh.h"
00028 
00052 class csCrystalBall
00053 {
00054   class csCrystalBallVec : public csVector3
00055   {
00056   protected:
00057     int idx; // holds the index of the polygon
00058   public:
00059     csCrystalBallVec (int polyidx) { idx = polyidx; }
00060     inline int GetIndex () { return idx; }
00061   };
00062 
00063   class csTriNode : public csTreeNode
00064   {
00065   public:
00066     enum
00067     {
00068       INSIDE = 0,
00069       OUTSIDE = 1
00070     };
00071 
00072     int from, len; // contains <len> points in vPoints starting at <from>
00073     int divider; // index to point that divides this triangle
00074     csTriNode (csTriNode *theParent=NULL, int from=-1, int len=0) : csTreeNode (theParent)
00075       {this->from = from; this->len = len;}
00076 
00077     // find a triangle for <normal> and return the index where its been inserted into vP
00078     int Add (csCrystalBallVec *normal, int tri1, int tri2, int tri3,
00079               csPArray<csCrystalBallVec> *vP, csPArray<csVector3> *vTP);
00080 
00081     // adjust (from,len) pairs after a new point was inserted
00082     void Adjust (int nPos);
00083 
00084     // classify a point to lie inside or outside the spherical triangle
00085     int Classify (const csVector3 &n, int i1, int i2, int i3,
00086                   const csPArray<csVector3> *vTP) const;
00087 
00088     // are all 3 normals on the side <useSign>
00089     // 0 ... yes
00090     // 1 ... partly
00091     // 2 ... all on other side
00092     int SignMatches (const csVector3 *n1, const csVector3 *n2, const csVector3 *td,
00093                      int useSign);
00094 
00095     // is the normal tn on the <useSign> side ?
00096     bool SignMatches (const csVector3 *tn, int useSign);
00097 
00098     // rotate the unitsphere by matrix <m>. Add all polygon indices to <indexVector>
00099     // which normlals point to the <useSign> side
00100     void Transform (const csMatrix3 &m, csGrowingArray<int> &indexVector,
00101                     int useSign, long cookie,
00102                     const csPArray<csCrystalBallVec> *vP,
00103                     const csPArray<csVector3> *vTP,
00104                     const csVector3 &v1, const csVector3 &v2,
00105                     const csVector3 &v3);
00106   };
00107 
00108  protected:
00109   // here we store the normals (pointers to csCrystalBallVec)
00110   csPArray<csCrystalBallVec> vPoints;
00111   // we divide a triangle into 3 sub triangles by inserting a divider point.
00112   // and <vTrianglePoints> is the place where we store those points (pointers to csVector3)
00113   csPArray<csVector3> vTrianglePoints;
00114   // our crystal ball is initially made of 8 spherical triangles (in the octants of a 3d cartesian coo system)
00115   csTriNode tri[8];
00116 
00117  public:
00118   csCrystalBall ();
00119   ~csCrystalBall ();
00120 
00121   // add all polygons in <polyset> to the crystal ball
00122   void Build (iPolygonMesh *polyset);
00123 
00124   // add a single polygon to the crystal ball
00125   void InsertPolygon (iPolygonMesh *polyset, int idx);
00126 
00127   // rotate the unitsphere by <t>. Add all polygon indices to <indexVector>
00128   // which normlals point to the <useSign> side
00129   void Transform (const csTransform &t, csGrowingArray<int> &indexVector, int useSign, long cookie);
00130 };
00131 
00132 #endif // __CS_CRYSBALL_H__

Generated for Crystal Space by doxygen 1.2.14