00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_WIREFRM_H__
00020 #define __CS_WIREFRM_H__
00021
00022 #include "csutil/scf.h"
00023 #include "csgeom/math3d.h"
00024 #include "csgeom/math2d.h"
00025
00026 struct iGraphics3D;
00027 struct iTextureManager;
00028 class csCamera;
00029
00030 #define PLANE_VERTEX_RADIUS .1
00031
00032 #define WF_ORTHO_PERSP -1
00033 #define WF_ORTHO_X 0
00034 #define WF_ORTHO_Y 1
00035 #define WF_ORTHO_Z 2
00036
00042 class csWfColor
00043 {
00044 public:
00045 csWfColor* next;
00046 int r, g, b;
00047 int col_idx[16];
00048
00049 public:
00051 csWfColor (iTextureManager* txtmgr, int r, int g, int b);
00053 int GetColor (float z);
00054 };
00055
00059 class csWfObject
00060 {
00061 private:
00062 csWfObject* next, * prev;
00063
00064 protected:
00065 csWfColor* color;
00066
00067 public:
00069 csWfObject ();
00071 virtual ~csWfObject ();
00072
00074 void SetColor (csWfColor* col) { color = col; }
00076 csWfColor* GetColor () { return color; }
00077
00079 csWfObject* GetNext () { return next; }
00081 csWfObject* GetPrev () { return prev; }
00083 void SetNext (csWfObject* ob) { next = ob; }
00085 void SetPrev (csWfObject* ob) { prev = ob; }
00086
00088 virtual void Draw (iGraphics3D* g, csCamera* c, int ortho = WF_ORTHO_PERSP) = 0;
00089
00091 bool Perspective (csCamera* c, csVector3& v, csVector2& persp, float radius, float& pradius);
00092
00094
00095 };
00096
00100 class csWfVertex : public csWfObject
00101 {
00102 private:
00103 csVector3 loc;
00104
00105 public:
00107 csVector3& GetLocation () { return loc; }
00108
00110 void SetLocation (const csVector3& v) { loc = v; }
00112 void SetLocation (float x, float y, float z) { loc.x = x; loc.y = y; loc.z = z; }
00113
00115 virtual void Draw (iGraphics3D* g, csCamera* c, int ortho = WF_ORTHO_PERSP);
00116 };
00117
00121 class csWfLine : public csWfObject
00122 {
00123 private:
00124 csVector3 v1, v2;
00125
00126 public:
00128 csVector3& GetVertex1 () { return v1; }
00130 csVector3& GetVertex2 () { return v2; }
00132 void SetLine (csVector3& vv1, csVector3& vv2) { v1 = vv1; v2 = vv2; }
00133
00135 virtual void Draw (iGraphics3D* g, csCamera* c, int ortho = WF_ORTHO_PERSP);
00136 };
00137
00141 class csWfPolygon : public csWfObject
00142 {
00143 private:
00144 int num_vertices;
00145 csVector3* vertices;
00146 csVector3 center;
00147 float A, B, C, D;
00148 csWfColor* vcolor;
00149
00150 public:
00152 csWfPolygon ();
00154 virtual ~csWfPolygon ();
00155
00157 void SetVertexCount (int n);
00159 int GetVertexCount () { return num_vertices; }
00161 void SetVertex (int i, csVector3& v);
00162
00164 void SetVisColor (csWfColor* vcol) { vcolor = vcol; }
00165
00167 void Prepare ();
00168
00170 bool IsVisible (csCamera* camera);
00171
00173 virtual void Draw (iGraphics3D* g, csCamera* c, int ortho = WF_ORTHO_PERSP);
00174 };
00175
00180 class csWireFrame
00181 {
00182 private:
00183 csWfObject* objects;
00184 iTextureManager* txtmgr;
00185 csWfColor* colors;
00186 csWfColor* white;
00187 csWfColor* red;
00188 csWfColor* green;
00189 csWfColor* blue;
00190 csWfColor* yellow;
00191
00192 size_t numObjects;
00193
00194 public:
00196 csWireFrame (iTextureManager* txtmgr);
00198 virtual ~csWireFrame ();
00199
00201 void Clear ();
00202
00204 size_t Entries () { return numObjects; }
00205
00207 csWfColor* GetWhite () { return white; }
00208
00210 csWfColor* GetRed () { return red; }
00211
00213 csWfColor* GetBlue () { return blue; }
00214
00216 csWfColor* GetGreen () { return green; }
00217
00219 csWfColor* GetYellow () { return yellow; }
00220
00224 csWfColor* FindColor (int r, int g, int b);
00225
00234 csWfColor* RegisterColor (int r, int g, int b);
00235
00237 csWfVertex* AddVertex (const csVector3& v);
00239 csWfLine* AddLine (csVector3& v1, csVector3& v2);
00241 csWfPolygon* AddPolygon ();
00242
00244 void Draw (iGraphics3D* g, csCamera* c, int ortho = WF_ORTHO_PERSP);
00245
00247 void Apply (void (*func)( csWfObject*, void*), void*);
00248 };
00249
00253 class csWireFrameCam
00254 {
00255 private:
00256 csWireFrame* wf;
00257 csCamera* c;
00258
00259 public:
00261 csWireFrameCam (iTextureManager* txtmgr);
00263 virtual ~csWireFrameCam ();
00264
00266 csWireFrame* GetWireframe () { return wf; }
00268 csCamera* GetCamera () { return c; }
00269
00271 void KeyUp (float speed, bool slow, bool fast);
00273 void KeyDown (float speed, bool slow, bool fast);
00275 void KeyLeft (float speed, bool slow, bool fast);
00277 void KeyRight (float speed, bool slow, bool fast);
00279 void KeyLeftStrafe (float speed, bool slow, bool fast);
00281 void KeyRightStrafe (float speed, bool slow, bool fast);
00283 void KeyPgDn (float speed, bool slow, bool fast);
00285 void KeyPgUp (float speed, bool slow, bool fast);
00286 };
00287
00288 #endif // __CS_WIREFRM_H__
00289