00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_VERTEX_ARRAY_HH
00020 #define OST_VERTEX_ARRAY_HH
00021
00022
00023
00024
00025
00026
00027
00028 #include <vector>
00029 #include <cassert>
00030 #include <iostream>
00031 #include <cmath>
00032
00033 #include <ost/log.hh>
00034 #include <ost/geom/geom.hh>
00035 #include <ost/geom/aligned_cuboid.hh>
00036
00037
00038 #include "color.hh"
00039 #include "material.hh"
00040 #include "gfx_prim.hh"
00041 #include "povray_fw.hh"
00042 #include "exporter_fw.hh"
00043
00044 namespace ost { namespace gfx {
00045
00046 typedef unsigned int VertexID;
00047 typedef unsigned int LineID;
00048 typedef unsigned int TriID;
00049 typedef unsigned int QuadID;
00050 class DLLEXPORT_OST_GFX IndexedVertexArray {
00051 public:
00052 struct DLLEXPORT Entry {
00053 Entry()
00054 {
00055 v[0]=0.0; v[1]=0.0; v[2]=0.0;
00056 n[0]=0.0; n[1]=0.0; n[2]=1.0;
00057 c[0]=0.0; c[1]=0.0; c[2]=0.0; c[3]=0.0;
00058 t[0]=0.0; t[1]=0.0;
00059 }
00060
00061 Entry(const geom::Vec3& vv, const geom::Vec3& nn, const Color& cc,
00062 const geom::Vec2& tt)
00063 {
00064 v[0]=vv[0]; v[1]=vv[1]; v[2]=vv[2];
00065 n[0]=nn[0]; n[1]=nn[1]; n[2]=nn[2];
00066 c[0]=cc[0]; c[1]=cc[1]; c[2]=cc[2]; c[3]=cc[3];
00067 t[0]=tt[0]; t[1]=tt[1];
00068 }
00069 float t[2];
00070 float c[4];
00071 float n[3];
00072 float v[3];
00073 };
00074
00075 struct NormalizerVertexEntry {
00076 geom::Vec3 pos;
00077 TriID tri_list[50];
00078 uint tri_count;
00079 float weight;
00080 };
00081
00082 struct NormalizerTriEntry {
00083 TriID tid;
00084 VertexID id0,id1,id2;
00085 geom::Vec3 norm;
00086 float weight;
00087 };
00088
00089 typedef std::vector<Entry> EntryList;
00090 typedef std::vector<VertexID> IndexList;
00091 typedef std::vector<NormalizerVertexEntry> NVEntryList;
00092 typedef std::vector<NormalizerTriEntry> NTEntryList;
00093
00094 IndexedVertexArray();
00095 ~IndexedVertexArray();
00096
00097 IndexedVertexArray(const IndexedVertexArray& va);
00098 IndexedVertexArray& operator=(const IndexedVertexArray& va);
00099
00100 static unsigned int GetFormat();
00101
00102 void Cleanup();
00103
00104
00105
00106
00107
00108
00109 void SetMode(int m);
00110 int GetMode() const;
00111
00112
00113 void SetPolyMode(int m);
00114
00115 void SetLighting(bool f);
00116 void SetTwoSided(bool f);
00117 void SetCullFace(bool f);
00118 void SetColorMaterial(bool f);
00119 void SetLineWidth(float lw);
00120 void SetAALines(bool f);
00121 void SetPointSize(float ps);
00122 void SetLineHalo(float lh);
00123
00124 void SetOutlineMode(int m);
00125 int GetOutlineMode() const {return outline_mode_;}
00126 void SetOutlineWidth(float f);
00127 float GetOutlineWidth() const {return outline_width_;}
00128 void SetOutlineMaterial(const Material& m);
00129 void SetOutlineExpandFactor(float f);
00130 float GetOutlineExpandFactor() const {return outline_exp_factor_;}
00131 void SetOutlineExpandColor(const Color& c);
00132 Color GetOutlineExpandColor() const {return outline_exp_color_;}
00133
00134 void SetSolid(bool f) {solid_=f;}
00135 bool GetSolid() const {return solid_;}
00136 void SetSolidColor(const Color& c) {solid_color_=c;}
00137 Color GetSolidcolor() const {return solid_color_;}
00138 void SetClipOffset(float f) {clip_offset_=f;}
00139 float GetClipOffset() const {return clip_offset_;}
00140
00141
00142 VertexID Add(const geom::Vec3& vert, const geom::Vec3& norm,
00143 const Color& col, const geom::Vec2& texc=geom::Vec2()) {
00144 dirty_=true;
00145 entry_list_.push_back(Entry(vert,norm,col,texc));
00146 entry_list_.back().c[3] = opacity_;
00147 return entry_list_.size()-1;
00148 }
00149
00150 unsigned int GetVertexCount() const;
00151 void DumpVertices() const;
00152
00153
00154 LineID AddLine(VertexID id0, VertexID id1);
00155
00156
00157 TriID AddTri(VertexID id0, VertexID id1, VertexID id2);
00158
00159
00160 TriID AddTriN(VertexID id0, VertexID id1, VertexID id2);
00161
00162
00163 QuadID AddQuad(VertexID id0, VertexID id1, VertexID id2, VertexID id3);
00164
00165
00166 void AddSphere(const SpherePrim& prim, unsigned int detail);
00167
00168
00169 void AddIcoSphere(const SpherePrim& prim, unsigned int detail);
00170
00171 void AddCylinder(const CylinderPrim& prim, unsigned int detail,bool cap=false);
00172
00173 void SetOpacity(float o);
00174
00175
00176 void RenderGL();
00177
00178
00179 void RenderPov(PovState& pov, const std::string& name);
00180
00181 void Export(Exporter* ex) const;
00182
00183
00184 void Clear();
00185
00186 void Reset();
00187
00188
00189 void FlagRefresh();
00190
00191
00192 void DrawNormals(bool f);
00193
00194
00195
00196
00197
00198 void CalcNormals(float smoothf);
00199
00200 void CalcFullNormals();
00201
00202 void SmoothNormals(float smoothf);
00203
00204 void NPatch();
00205
00206 void SmoothVertices(float smoothf);
00207
00209 void UseTex(bool b) {use_tex_=b;}
00211 uint& TexID() {return tex_id_;}
00212
00213 const EntryList& GetEntries() const {return entry_list_;}
00214 const IndexList& GetQuadIndices() const {return quad_index_list_;}
00215 const IndexList& GetTriIndices() const {return tri_index_list_;}
00216 const IndexList& GetLineIndices() const {return line_index_list_;}
00217
00219 geom::AlignedCuboid GetBoundingBox() const;
00220
00221 geom::Vec3 GetVert(VertexID id) const
00222 {
00223 geom::Vec3 nrvo;
00224 if(id>=entry_list_.size()) return nrvo;
00225 nrvo = geom::Vec3(entry_list_[id].v);
00226 return nrvo;
00227 }
00228
00229 void SetVert(VertexID id, const geom::Vec3& v)
00230 {
00231 if(id>=entry_list_.size()) return;
00232 entry_list_[id].v[0]=v[0];
00233 entry_list_[id].v[1]=v[1];
00234 entry_list_[id].v[2]=v[2];
00235 }
00236
00237 geom::Vec3 GetNormal(VertexID id) const
00238 {
00239 geom::Vec3 nrvo;
00240 if(id>=entry_list_.size()) return nrvo;
00241 nrvo = geom::Vec3(entry_list_[id].n);
00242 return nrvo;
00243 }
00244
00245 void SetNormal(VertexID id, const geom::Vec3& n)
00246 {
00247 if(id>=entry_list_.size()) return;
00248 entry_list_[id].n[0]=n[0];
00249 entry_list_[id].n[1]=n[1];
00250 entry_list_[id].n[2]=n[2];
00251 }
00252
00253 Color GetColor(VertexID id) const
00254 {
00255 Color nrvo;
00256 if(id>=entry_list_.size()) return nrvo;
00257 nrvo = Color(entry_list_[id].c[0],
00258 entry_list_[id].c[1],
00259 entry_list_[id].c[2],
00260 entry_list_[id].c[3]);
00261 return nrvo;
00262 }
00263
00264 void SetColor(VertexID id, const Color& c)
00265 {
00266 if(id>=entry_list_.size()) return;
00267 entry_list_[id].c[0]=c[0];
00268 entry_list_[id].c[1]=c[1];
00269 entry_list_[id].c[2]=c[2];
00270 entry_list_[id].c[3]=opacity_;
00271 }
00272
00273 geom::Vec2 GetTexCoord(VertexID id) const
00274 {
00275 geom::Vec2 nrvo;
00276 if(id>=entry_list_.size()) return nrvo;
00277 nrvo = geom::Vec2(entry_list_[id].t);
00278 return nrvo;
00279 }
00280
00281 void SetTexCoord(VertexID id, const geom::Vec2& t)
00282 {
00283 if(id>=entry_list_.size()) return;
00284 entry_list_[id].t[0]=t[0];
00285 entry_list_[id].t[1]=t[1];
00286 }
00287 private:
00288 bool initialized_;
00289
00290 EntryList entry_list_;
00291 IndexList quad_index_list_;
00292 IndexList tri_index_list_;
00293 IndexList line_index_list_;
00294 NTEntryList ntentry_list_;
00295
00296 bool dirty_;
00297
00298 int mode_;
00299 int poly_mode_;
00300 bool lighting_;
00301 bool cull_face_;
00302 bool two_sided_;
00303 bool color_mat_;
00304 float line_width_;
00305 bool aalines_flag_;
00306 float point_size_;
00307 float line_halo_;
00308 float opacity_;
00309
00310 int outline_mode_;
00311 float outline_width_;
00312 Material outline_mat_;
00313 bool outline_mat_update_;
00314 unsigned int outline_mat_dlist_;
00315 float outline_exp_factor_;
00316 Color outline_exp_color_;
00317 bool solid_;
00318 Color solid_color_;
00319 float clip_offset_;
00320 bool draw_normals_;
00321
00322 bool use_tex_;
00323 uint tex_id_;
00324
00325 unsigned int buffer_id_[7];
00326
00327 void copy(const IndexedVertexArray& va);
00328 bool prep_buff();
00329 void draw_ltq(bool use_buff);
00330 void draw_p(bool use_buff);
00331 void draw_aalines();
00332 void draw_line_halo(bool use_buff);
00333 void set_clip_offset(float);
00334 };
00335
00336 }}
00337
00338 #endif