00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 CS_DECLARE_STATIC_CLASSVAR(poly_fact,GetPolygonFact,csBspPolygonFactory)
00085 CS_DECLARE_STATIC_CLASSVAR_REF(poly_pool,GetPolygonPool,csPolygonIntPool)
00086
00088 void Dump();
00089
00090 private:
00092 csBspPolygon () { }
00093
00094 public:
00096 virtual ~csBspPolygon () { }
00097
00099 csPolyTreeBBox* GetParent () { return parent; }
00100
00102 void SetParent (csPolyTreeBBox* par) { parent = par; }
00103
00107 csVisObjInfo* GetOriginator () { return originator; }
00108
00110 void SetOriginator (csVisObjInfo* org) { originator = org; }
00111
00113 csPolyIndexed& GetPolygon () { return polygon; }
00114
00116 virtual int GetVertexCount () { return polygon.GetVertexCount (); }
00117
00119 virtual int* GetVertexIndices () { return polygon.GetVertexIndices (); }
00120
00122 virtual csPolygonInt* GetUnsplitPolygon () { return NULL; }
00123
00125 void SetPolyPlane (const csPlane3& pl) { plane = pl; }
00126
00128 csPlane3* GetPolyPlane () { return &plane; }
00129
00131 int Classify (const csPlane3& pl);
00132
00134 int ClassifyX (float x);
00135
00137 int ClassifyY (float y);
00138
00140 int ClassifyZ (float z);
00141
00143 void SplitWithPlane (csPolygonInt** front, csPolygonInt** back,
00144 const csPlane3& split_plane);
00145
00147 void SplitWithPlaneX (csPolygonInt** front, csPolygonInt** back, float x);
00148
00150 void SplitWithPlaneY (csPolygonInt** front, csPolygonInt** back, float y);
00151
00153 void SplitWithPlaneZ (csPolygonInt** front, csPolygonInt** back, float z);
00154
00156 int GetType () { return 3; }
00157
00159 void Transform (const csTransform& trans);
00160
00167 bool ClipToPlane (csPlane3* portal_plane, const csVector3& v_w2c,
00168 csVector3*& pverts, int& num_verts, bool cw = true);
00169
00175 bool DoPerspective (const csTransform& trans,
00176 csVector3* source, int num_verts, csPolygon2D* dest, bool mirror);
00177
00181 bool Overlaps (csPolygonInt* ) { return false; }
00182
00187 bool IntersectSegment (const csVector3& start, const csVector3& end,
00188 csVector3& isect, float* pr = NULL);
00189 };
00190
00197 class csPolyTreeBBox
00198 {
00199 private:
00207 csPolygonStub* first_stub;
00208
00210 csVector3Array vertices;
00212 csVector3Array cam_vertices;
00213
00215 csPolygonStub* base_stub;
00216
00222 int camera_nr;
00223
00225 csBox3 world_bbox;
00226
00227 public:
00229 csPolyTreeBBox ();
00231 ~csPolyTreeBBox ();
00232
00233 CS_DECLARE_STATIC_CLASSVAR(stub_pool,GetPolyStubPool,csPolygonStubPool)
00234 CS_DECLARE_STATIC_CLASSVAR(stub_fact,GetPolyStubFactory,csPolygonStubFactory)
00235
00239 void RemoveFromTree ();
00240
00246 void UnlinkStub (csPolygonStub* ps);
00247
00251 void LinkStub (csPolygonStub* ps);
00252
00258 const csBox3& GetWorldBoundingBox ()
00259 {
00260 return world_bbox;
00261 }
00262
00269 csPolygonStub* GetBaseStub () { return base_stub; }
00270
00272 csVector3Array& GetVertices () { return vertices; }
00273
00275 csVector3Array& GetCameraVertices () { return cam_vertices; }
00276
00281 void Update (const csBox3& object_bbox, const csTransform& o2w,
00282 csVisObjInfo* vinf);
00283
00287 void Update (const csBox3& world_bbox,
00288 csVisObjInfo* vinf);
00289
00291 void AddPolygon (csPolygonInt* poly)
00292 {
00293 base_stub->GetPolygonArray ().AddPolygon (poly);
00294 ((csBspPolygon*)poly)->SetParent (this);
00295 }
00296
00298 int GetPolygonCount () { return base_stub->GetPolygonCount (); }
00299
00301 csPolygonInt* GetPolygon (int idx)
00302 {
00303 return base_stub->GetPolygonArray ().GetPolygon (idx);
00304 }
00305
00307 csPolygonInt** GetPolygons () { return base_stub->GetPolygons (); }
00308
00310 void World2Camera (const csTransform& trans, int cur_camera_nr);
00311
00313 bool IsTransformed (int cur_camera_nr)
00314 {
00315 if (cur_camera_nr != camera_nr) return false;
00316 return (cam_vertices.GetVertexCount () == vertices.GetVertexCount ());
00317 }
00318
00320 void ClearTransform () { camera_nr = -1; }
00321
00337 void SplitWithPlane (csPolygonStub* stub,
00338 csPolygonStub** stub_on, csPolygonStub** stub_front,
00339 csPolygonStub** stub_back,
00340 const csPlane3& plane);
00341
00345 void SplitWithPlaneX (csPolygonStub* stub,
00346 csPolygonStub** stub_on, csPolygonStub** stub_front,
00347 csPolygonStub** stub_back,
00348 float x);
00349
00353 void SplitWithPlaneY (csPolygonStub* stub,
00354 csPolygonStub** stub_on, csPolygonStub** stub_front,
00355 csPolygonStub** stub_back,
00356 float y);
00357
00361 void SplitWithPlaneZ (csPolygonStub* stub,
00362 csPolygonStub** stub_on, csPolygonStub** stub_front,
00363 csPolygonStub** stub_back,
00364 float z);
00365 };
00366
00367 #endif // __CS_BSPBBOX_H__