Main Page   Class Hierarchy   Compound List   File List   Compound Members  

bspbbox.h

00001 /*
00002     Copyright (C) 1998-2001 by Jorrit Tyberghein
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_BSPBBOX_H__
00020 #define __CS_BSPBBOX_H__
00021 
00022 #include "csgeom/math3d.h"
00023 #include "csgeom/polyidx.h"
00024 #include "csgeom/poly3d.h"
00025 #include "csgeom/transfrm.h"
00026 #include "csengine/polyint.h"
00027 #include "csengine/pol2d.h"
00028 #include "csengine/treeobj.h"
00029 #include "csutil/csobject.h"
00030 
00031 class csPolyTreeBBox;
00032 class csPolygonTree;
00033 class csTransform;
00034 class csBox3;
00035 struct iVisibilityObject;
00036 struct iShadowCaster;
00037 
00041 class csBspPolygonFactory : public csPolygonIntFactory
00042 {
00044   virtual csPolygonInt* Create ();
00046   virtual void Init (csPolygonInt* pi);
00047 };
00048 
00053 struct csVisObjInfo
00054 {
00055   iVisibilityObject* visobj;
00056   iShadowCaster* shadcast;
00057   csPolyTreeBBox* bbox;
00058   long last_movablenr;
00059   long last_shapenr;
00060 };
00061 
00068 class csBspPolygon : public csPolygonInt
00069 {
00070   friend class csBspPolygonFactory;
00071 
00072 private:
00074   csPolyIndexed polygon;
00076   csPlane3 plane;
00078   csPolyTreeBBox* parent;
00080   csVisObjInfo* originator;
00081 
00082 public:
00084   static csPolygonIntPool& GetPolygonPool();
00085 
00087   void Dump();
00088 
00089 private:
00091   csBspPolygon () { }
00092 
00093 public:
00095   virtual ~csBspPolygon () { }
00096 
00098   csPolyTreeBBox* GetParent () { return parent; }
00099 
00101   void SetParent (csPolyTreeBBox* par) { parent = par; }
00102 
00106   csVisObjInfo* GetOriginator () { return originator; }
00107 
00109   void SetOriginator (csVisObjInfo* org) { originator = org; }
00110 
00112   csPolyIndexed& GetPolygon () { return polygon; }
00113 
00115   virtual int GetVertexCount () { return polygon.GetVertexCount (); }
00116 
00118   virtual int* GetVertexIndices () { return polygon.GetVertexIndices (); }
00119 
00121   virtual csPolygonInt* GetUnsplitPolygon () { return NULL; }
00122 
00124   void SetPolyPlane (const csPlane3& pl) { plane = pl; }
00125 
00127   csPlane3* GetPolyPlane () { return &plane; }
00128 
00130   int Classify (const csPlane3& pl);
00131 
00133   int ClassifyX (float x);
00134 
00136   int ClassifyY (float y);
00137 
00139   int ClassifyZ (float z);
00140 
00142   void SplitWithPlane (csPolygonInt** front, csPolygonInt** back,
00143         const csPlane3& split_plane);
00144 
00146   void SplitWithPlaneX (csPolygonInt** front, csPolygonInt** back, float x);
00147 
00149   void SplitWithPlaneY (csPolygonInt** front, csPolygonInt** back, float y);
00150 
00152   void SplitWithPlaneZ (csPolygonInt** front, csPolygonInt** back, float z);
00153 
00155   int GetType () { return 3; }
00156 
00158   void Transform (const csTransform& trans);
00159 
00166   bool ClipToPlane (csPlane3* portal_plane, const csVector3& v_w2c,
00167         csVector3*& pverts, int& num_verts, bool cw = true);
00168 
00174   bool DoPerspective (const csTransform& trans,
00175         csVector3* source, int num_verts, csPolygon2D* dest, bool mirror);
00176 
00180   bool Overlaps (csPolygonInt* /*overlapped*/) { return false; }
00181 
00186   bool IntersectSegment (const csVector3& start, const csVector3& end,
00187                           csVector3& isect, float* pr = NULL);
00188 };
00189 
00196 class csPolyTreeBBox
00197 {
00198 private:
00206   csPolygonStub* first_stub;
00207 
00209   csVector3Array vertices;
00211   csVector3Array cam_vertices;
00212 
00214   csPolygonStub* base_stub;
00215 
00221   int camera_nr;
00222 
00224   csBox3 world_bbox;
00225 
00226 public:
00228   static csPolygonStubPool stub_pool;
00230   static csPolygonStubFactory stub_fact;
00231 
00232 public:
00234   csPolyTreeBBox ();
00236   ~csPolyTreeBBox ();
00237 
00241   void RemoveFromTree ();
00242 
00248   void UnlinkStub (csPolygonStub* ps);
00249 
00253   void LinkStub (csPolygonStub* ps);
00254 
00260   const csBox3& GetWorldBoundingBox ()
00261   {
00262     return world_bbox;
00263   }
00264 
00271   csPolygonStub* GetBaseStub () { return base_stub; }
00272 
00274   csVector3Array& GetVertices () { return vertices; }
00275   
00277   csVector3Array& GetCameraVertices () { return cam_vertices; }
00278 
00283   void Update (const csBox3& object_bbox, const csTransform& o2w,
00284         csVisObjInfo* vinf);
00285 
00289   void Update (const csBox3& world_bbox,
00290         csVisObjInfo* vinf);
00291 
00293   void AddPolygon (csPolygonInt* poly)
00294   {
00295     base_stub->GetPolygonArray ().AddPolygon (poly);
00296     ((csBspPolygon*)poly)->SetParent (this);
00297   }
00298 
00300   int GetPolygonCount () { return base_stub->GetPolygonCount (); }
00301 
00303   csPolygonInt* GetPolygon (int idx)
00304   {
00305     return base_stub->GetPolygonArray ().GetPolygon (idx);
00306   }
00307 
00309   csPolygonInt** GetPolygons () { return base_stub->GetPolygons (); }
00310 
00312   void World2Camera (const csTransform& trans, int cur_camera_nr);
00313 
00315   bool IsTransformed (int cur_camera_nr)
00316   {
00317     if (cur_camera_nr != camera_nr) return false;
00318     return (cam_vertices.GetVertexCount () == vertices.GetVertexCount ());
00319   }
00320 
00322   void ClearTransform () { camera_nr = -1; }
00323 
00339   void SplitWithPlane (csPolygonStub* stub,
00340         csPolygonStub** stub_on, csPolygonStub** stub_front,
00341         csPolygonStub** stub_back,
00342         const csPlane3& plane);
00343 
00347   void SplitWithPlaneX (csPolygonStub* stub,
00348         csPolygonStub** stub_on, csPolygonStub** stub_front,
00349         csPolygonStub** stub_back,
00350         float x);
00351 
00355   void SplitWithPlaneY (csPolygonStub* stub,
00356         csPolygonStub** stub_on, csPolygonStub** stub_front,
00357         csPolygonStub** stub_back,
00358         float y);
00359 
00363   void SplitWithPlaneZ (csPolygonStub* stub,
00364         csPolygonStub** stub_on, csPolygonStub** stub_front,
00365         csPolygonStub** stub_back,
00366         float z);
00367 };
00368 
00369 #endif // __CS_BSPBBOX_H__

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