Google

Main Page   Class Hierarchy   Compound List   File List   Compound 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 
00046 #include "csutil/cstreend.h"
00047 #include "csgeom/vector3.h"
00048 #include "csgeom/math3d.h"
00049 #include "csgeom/transfrm.h"
00050 #include "ivaria/polymesh.h"
00051 
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 (const csCrystalBallVec *normal, int tri1, int tri2, int tri3,
00079               csVector *vP, csVector *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 csVector *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, csVector &indexVector,
00101                     int useSign, long cookie,
00102                     const csVector *vP, const csVector *vTP,
00103                     const csVector3 &v1, const csVector3 &v2,
00104                     const csVector3 &v3);
00105   };
00106 
00107  protected:
00108   // here we store the normals (pointers to csCrystalBallVec)
00109   csVector vPoints;
00110   // we divide a triangle into 3 sub triangles by inserting a divider point.
00111   // and <vTrianglePoints> is the place where we store those points (pointers to csVector3)
00112   csVector vTrianglePoints;
00113   // our crystal ball is initially made of 8 spherical triangles (in the octants of a 3d cartesian coo system)
00114   csTriNode tri[8];
00115 
00116  public:
00117   csCrystalBall ();
00118   ~csCrystalBall ();
00119 
00120   // add all polygons in <polyset> to the crystal ball
00121   void Build (iPolygonMesh *polyset);
00122 
00123   // add a single polygon to the crystal ball
00124   void InsertPolygon (iPolygonMesh *polyset, int idx);
00125 
00126   // rotate the unitsphere by <t>. Add all polygon indices to <indexVector>
00127   // which normlals point to the <useSign> side
00128   void Transform (const csTransform &t, csVector &indexVector, int useSign, long cookie);
00129 };
00130 
00131 #endif // __CS_CRYSBALL_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000