00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_CURVE_H__
00020 #define __CS_CURVE_H__
00021
00022 #include "csutil/scf.h"
00023 #include "csutil/csvector.h"
00024 #include "csgeom/math3d.h"
00025 #include "csgeom/math2d.h"
00026 #include "csgeom/box.h"
00027 #include "csengine/bezier.h"
00028 #include "csengine/texture.h"
00029 #include "csengine/material.h"
00030 #include "csengine/lghtmap.h"
00031 #include "csengine/rview.h"
00032 #include "csutil/csobject.h"
00033 #include "ivideo/graph3d.h"
00034 #include "ivideo/vbufmgr.h"
00035 #include "imesh/thing/curve.h"
00036
00037 class csThing;
00038 class csCurveTemplate;
00039 class csLightPatch;
00040 class csSector;
00041 class csRadCurve;
00042 class csBspContainer;
00043 class csFrustumView;
00044 struct csCoverageMatrix;
00045 struct iMaterialHandle;
00046
00050 class csCurveTesselated
00051 {
00052 private:
00053
00054 csVector3* ObjectCoords;
00055
00056 csVector2* TextureCoords;
00057
00058 csVector2* ControlPoints;
00059
00060 csColor* Colors;
00061
00062 csTriangle* Triangles;
00063
00064
00065 int NumVertices;
00066
00067 int NumTriangles;
00068
00069 bool ColorsValid;
00070
00071 public:
00076 csCurveTesselated (int NumVertices, int NumTriangles);
00078 ~csCurveTesselated ();
00079
00081 inline int GetVertexCount () const;
00083 inline int GetTriangleCount () const;
00085 inline csVector3* GetVertices ();
00087 inline csVector2* GetTxtCoords ();
00089 inline csVector2* GetControlPoints ();
00091 inline csColor* GetColors ();
00093 inline csTriangle* GetTriangles ();
00095 inline csTriangle& GetTriangle (int i);
00097 inline bool AreColorsValid () const;
00098
00104 void UpdateColors (csLightMap* lightmap);
00105 };
00106
00110 class csCurve : public csObject
00111 {
00113 friend class csRadCurve;
00114
00115 private:
00117 unsigned long CurveID;
00119 static unsigned long LastCurveID;
00120
00122 iMaterialWrapper* Material;
00123
00125 csCurveTemplate* CurveTemplate;
00126
00128 csLightPatch* LightPatches;
00129
00134 csReversibleTransform* O2W;
00135
00136
00137
00138
00139
00140
00141
00142
00143 csVector3* uv2World;
00144
00145
00146
00147
00148
00149
00150
00151 csVector3* uv2Normal;
00152
00154 iVertexBuffer* vbuf;
00155 iVertexBufferManager* vbufmgr;
00156
00158 void SetupVertexBuffer ();
00159
00161 struct eiVertexBufferManagerClient : public iVertexBufferManagerClient
00162 {
00163 SCF_DECLARE_EMBEDDED_IBASE (csCurve);
00164 virtual void ManagerClosing ();
00165 }scfiVertexBufferManagerClient;
00166 friend struct eiVertexBufferManagerClient;
00167
00168
00169 public:
00171 csThing* ParentThing;
00172
00174 csLightMap* LightMap;
00175
00177 bool LightmapUpToDate;
00178
00179 public:
00180
00182 csCurve (csCurveTemplate* parent_tmpl);
00184 virtual ~csCurve ();
00185
00187 inline unsigned long GetCurveID () const;
00188
00190 iVertexBuffer* GetVertexBuffer () const { return vbuf; }
00191
00193 inline iMaterialHandle* GetMaterialHandle () const;
00195 inline iMaterialWrapper* GetMaterial () const;
00197 void SetMaterial (iMaterialWrapper* h);
00198
00200 inline csCurveTemplate* GetParentTemplate () const;
00201
00203 void MakeDirtyDynamicLights ();
00205 void AddLightPatch (csLightPatch* lp);
00207 void UnlinkLightPatch (csLightPatch* lp);
00209 bool RecalculateDynamicLights ();
00211 void ShineDynLight (csLightPatch* lp);
00212
00214 void SetObject2World (const csReversibleTransform *o2w);
00216 inline const csReversibleTransform *GetObject2World () const;
00217
00219 inline void SetParentThing (csThing* p);
00221 inline csThing* GetParentThing () const;
00222
00224 inline csLightMap* GetLightMap () const;
00226 void CalculateLightingStatic (csFrustumView* lview, bool vis);
00228 void CalculateLightingDynamic (csFrustumView* lview);
00230 void InitializeDefaultLighting ();
00232 bool ReadFromCache (int id);
00234 bool WriteToCache (int id);
00236 void PrepareLighting ();
00237
00242 void GetCoverageMatrix (csFrustumView& lview, csCoverageMatrix &cm) const;
00243
00245 float GetArea();
00246
00248 void CalcUVBuffers();
00249
00255 virtual csCurveTesselated* Tesselate (int res) = 0;
00256
00261 virtual void SetControlPoint (int index, int control_id) = 0;
00262
00264 virtual void GetObjectBoundingBox (csBox3& bbox) = 0;
00265
00271 void GetCameraBoundingBox (const csTransform& obj2cam, csBox3& cbox);
00272
00282 float GetScreenBoundingBox (const csTransform& obj2cam,
00283 iCamera* camera, csBox3& cameraBox, csBox2& boundingBox);
00284
00292 virtual bool IsLightable ();
00294 virtual void PosInSpace (csVector3& vec, double u, double v);
00296 virtual void Normal (csVector3& vec, double u, double v);
00297
00299 virtual void HardTransform (const csReversibleTransform& trans);
00300
00301 SCF_DECLARE_IBASE_EXT (csObject);
00302
00303
00304 struct Curve : public iCurve
00305 {
00306 SCF_DECLARE_EMBEDDED_IBASE (csCurve);
00307
00308 virtual csCurve* GetOriginalObject ()
00309 { return scfParent; }
00310 virtual iObject *QueryObject()
00311 { return scfParent; }
00312 virtual iCurveTemplate* GetParentTemplate ();
00313 virtual void SetMaterial (iMaterialWrapper* mat)
00314 { scfParent->SetMaterial (mat); }
00315 virtual iMaterialWrapper* GetMaterial ()
00316 { return scfParent->GetMaterial (); }
00317 virtual void SetName (const char* name)
00318 { scfParent->SetName (name); }
00319 virtual const char* GetName () const
00320 { return scfParent->GetName (); }
00321 virtual void SetControlPoint (int idx, int control_id)
00322 { scfParent->SetControlPoint (idx, control_id); }
00323 } scfiCurve;
00324 friend struct Curve;
00325 };
00326
00327
00328 SCF_VERSION (csCurveTemplate, 0, 0, 1);
00329
00333 class csCurveTemplate : public csObject
00334 {
00335 protected:
00336 iMaterialWrapper* Material;
00337
00338 protected:
00340 virtual ~csCurveTemplate ();
00341
00342 public:
00344 csCurveTemplate();
00345
00347 virtual csCurve* MakeCurve () = 0;
00348
00350 virtual void SetVertex (int index, int ver_ind) = 0;
00352 virtual int GetVertex (int index) = 0;
00354 virtual int GetVertexCount () = 0;
00355
00357 iMaterialWrapper* GetMaterial () { return Material; }
00359 void SetMaterial (iMaterialWrapper* h);
00360
00361 SCF_DECLARE_IBASE_EXT (csObject);
00362
00363
00364 struct CurveTemplate : public iCurveTemplate
00365 {
00366 SCF_DECLARE_EMBEDDED_IBASE (csCurveTemplate);
00367 virtual iObject *QueryObject()
00368 { return scfParent; }
00369 virtual void SetMaterial (iMaterialWrapper* mat)
00370 { scfParent->SetMaterial (mat); }
00371 virtual iMaterialWrapper* GetMaterial ()
00372 { return scfParent->GetMaterial (); }
00373 virtual iCurve* MakeCurve ()
00374 { return &(scfParent->MakeCurve ()->scfiCurve); }
00375 virtual int GetVertexCount () const
00376 { return scfParent->GetVertexCount (); }
00377 virtual int GetVertex (int idx) const
00378 { return scfParent->GetVertex (idx); }
00379 virtual void SetVertex (int idx, int vt)
00380 { scfParent->SetVertex (idx, vt); }
00381 } scfiCurveTemplate;
00382 friend struct CurveTemplate;
00383 };
00384
00388 class csBezierTemplate : public csCurveTemplate
00389 {
00390 private:
00391 int ver_id[9];
00392
00393 public:
00394 csBezierTemplate();
00395
00396 virtual csCurve* MakeCurve();
00397
00399 virtual void SetVertex (int index, int ver_ind);
00401 virtual int GetVertex (int index);
00402 virtual int GetVertexCount ();
00403
00404
00405
00406
00407 SCF_DECLARE_IBASE_EXT(csCurveTemplate);
00408 };
00409
00413 class csBezierCurve : public csCurve
00414 {
00415 private:
00417 csVector3 points[3][3];
00419 csVector2 texture_coords[3][3];
00420
00421 double cpt[9][5];
00422
00423 csCurveTesselated* previous_tesselation;
00424 int previous_resolution;
00425
00427 csBox3 object_bbox;
00429 bool valid_bbox;
00430
00431 public:
00433 csBezierCurve (csBezierTemplate* parent_tmpl);
00435 ~csBezierCurve ();
00436
00438 virtual csCurveTesselated* Tesselate (int res);
00439
00441 virtual void GetObjectBoundingBox (csBox3& bbox);
00442
00444 void Load (char* buf);
00445
00446 virtual void SetControlPoint (int index, int control_id);
00447
00449 inline csVector3& GetControlPoint (int i) { return points[i/3][i-(i/3)*3]; }
00450
00452 inline csVector2& GetTextureCoord (int i) { return texture_coords[i/3][i-(i/3)*3]; }
00453
00454 virtual bool IsLightable ();
00455 virtual void PosInSpace (csVector3& vec, double u, double v);
00456 virtual void Normal (csVector3& vec, double u, double v);
00457
00459 virtual void HardTransform (const csReversibleTransform& trans);
00460 };
00461
00462
00463
00464
00465
00466 inline int csCurveTesselated::GetVertexCount () const
00467 { return NumVertices; }
00468 inline int csCurveTesselated::GetTriangleCount () const
00469 { return NumTriangles; }
00470 inline csVector3* csCurveTesselated::GetVertices ()
00471 { return ObjectCoords; }
00472 inline csVector2* csCurveTesselated::GetTxtCoords ()
00473 { return TextureCoords; }
00474 inline csVector2* csCurveTesselated::GetControlPoints ()
00475 { return ControlPoints; }
00476 inline csColor* csCurveTesselated::GetColors ()
00477 { return Colors; }
00478 inline csTriangle* csCurveTesselated::GetTriangles ()
00479 { return Triangles; }
00480 inline csTriangle& csCurveTesselated::GetTriangle (int i)
00481 { return Triangles[i]; }
00482 inline bool csCurveTesselated::AreColorsValid () const
00483 { return ColorsValid; }
00484
00485 inline unsigned long csCurve::GetCurveID () const
00486 { return CurveID; }
00487 inline iMaterialHandle* csCurve::GetMaterialHandle () const
00488 { return Material ? Material->GetMaterialHandle() : NULL; }
00489 inline iMaterialWrapper* csCurve::GetMaterial () const
00490 { return Material; }
00491 inline csCurveTemplate* csCurve::GetParentTemplate () const
00492 { return CurveTemplate; }
00493 inline csLightMap* csCurve::GetLightMap () const
00494 { return LightMap; }
00495 inline void csCurve::SetParentThing (csThing* p)
00496 { ParentThing = p; }
00497 inline csThing* csCurve::GetParentThing () const
00498 { return ParentThing; }
00499 inline const csReversibleTransform *csCurve::GetObject2World () const
00500 { return O2W; }
00501
00502 #endif // __CS_CURVE_H__