Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
crysball.h
00001 /* 00002 Copyright (C) 2000 by Norman Kraemer 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 "csextern.h" 00023 00024 #include "csutil/tree.h" 00025 #include "csutil/array.h" 00026 #include "csgeom/vector3.h" 00027 #include "csgeom/math3d.h" 00028 #include "csgeom/transfrm.h" 00029 #include "igeom/polymesh.h" 00030 00054 class CS_CSGEOM_EXPORT csCrystalBall 00055 { 00056 class csCrystalBallVec : public csVector3 00057 { 00058 protected: 00059 int idx; // holds the index of the polygon 00060 public: 00061 csCrystalBallVec (int polyidx) { idx = polyidx; } 00062 inline int GetIndex () { return idx; } 00063 }; 00064 00065 class csTriNode : public csTreeNode 00066 { 00067 public: 00068 enum 00069 { 00070 INSIDE = 0, 00071 OUTSIDE = 1 00072 }; 00073 00074 size_t from, len; // contains <len> points in vPoints starting at <from> 00075 size_t divider; // index to point that divides this triangle 00076 csTriNode (csTriNode *theParent=0, size_t from=(size_t)-1, size_t len=0) : csTreeNode (theParent) 00077 {this->from = from; this->len = len;} 00078 00079 // find a triangle for <normal> and return the index where its been inserted into vP 00080 int Add (csCrystalBallVec *normal, size_t tri1, size_t tri2, size_t tri3, 00081 csArray<csCrystalBallVec*> *vP, csArray<csVector3*> *vTP); 00082 00083 // adjust (from,len) pairs after a new point was inserted 00084 void Adjust (size_t nPos); 00085 00086 // classify a point to lie inside or outside the spherical triangle 00087 int Classify (const csVector3 &n, size_t i1, size_t i2, size_t i3, 00088 const csArray<csVector3*> *vTP) const; 00089 00090 // are all 3 normals on the side <useSign> 00091 // 0 ... yes 00092 // 1 ... partly 00093 // 2 ... all on other side 00094 int SignMatches (const csVector3 *n1, const csVector3 *n2, 00095 const csVector3 *td, int useSign); 00096 00097 // is the normal tn on the <useSign> side ? 00098 bool SignMatches (const csVector3 *tn, int useSign); 00099 00100 // rotate the unitsphere by matrix <m>. Add all polygon indices to <indexVector> 00101 // which normlals point to the <useSign> side 00102 void Transform (const csMatrix3 &m, csDirtyAccessArray<int> &indexVector, 00103 int useSign, long cookie, 00104 const csArray<csCrystalBallVec*> *vP, 00105 const csArray<csVector3*> *vTP, 00106 const csVector3 &v1, const csVector3 &v2, 00107 const csVector3 &v3); 00108 }; 00109 00110 protected: 00111 // here we store the normals (pointers to csCrystalBallVec) 00112 csArray<csCrystalBallVec*> vPoints; 00113 // we divide a triangle into 3 sub triangles by inserting a divider point. 00114 // and <vTrianglePoints> is the place where we store those points (pointers to csVector3) 00115 csArray<csVector3*> vTrianglePoints; 00116 // our crystal ball is initially made of 8 spherical triangles (in the octants of a 3d cartesian coo system) 00117 csTriNode tri[8]; 00118 00119 public: 00120 csCrystalBall (); 00121 ~csCrystalBall (); 00122 00123 // add all polygons in <polyset> to the crystal ball 00124 void Build (iPolygonMesh *polyset); 00125 00126 // add a single polygon to the crystal ball 00127 void InsertPolygon (iPolygonMesh *polyset, int idx); 00128 00129 // rotate the unitsphere by <t>. Add all polygon indices to <indexVector> 00130 // which normlals point to the <useSign> side 00131 void Transform (const csTransform &t, csDirtyAccessArray<int> &indexVector, int useSign, long cookie); 00132 }; 00133 00134 #endif // __CS_CRYSBALL_H__
Generated for Crystal Space by doxygen 1.3.9.1