Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef WAVE_GLUT_GLUT_MODEL_H__
00034 #define WAVE_GLUT_GLUT_MODEL_H__
00035
00036
00037 #include "common/common.h"
00038
00039 #include "geometry/geometry_3d.h"
00040 #include "threadsafe/smart_ptr.h"
00041 #include "wave-glut/camera.h"
00042 #include "wave-glut/renderable.h"
00043
00044
00045 namespace glut {
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 struct material_t {
00069
00070 material_t(void) throw() : texture_id(0) { this->clear(); }
00071 ~material_t(void) throw() { this->clear(); }
00072 void clear(void) throw() {
00073 isTransparent = false;
00074 if (texture_id) {
00075 glDeleteTextures(1, (GLuint *) &texture_id);
00076 texture_id = 0;
00077 }
00078 }
00079
00080
00081 int texture_id;
00082 bool isTransparent;
00083 glut_color_t color;
00084 };
00085
00086
00087
00088
00089
00090
00091 class MaterialRegistry {
00092 public:
00093
00094 virtual ~MaterialRegistry(void) throw();
00095
00096
00097 virtual smart_ptr<material_t> getMaterial(IN const char * id) = 0;
00098 };
00099
00100
00101
00102
00103
00104 struct polygon_t {
00105
00106 polygon_t(void) throw() {
00107 nVertices = 0;
00108 indices = NULL;
00109 u = v = NULL;
00110 }
00111 ~polygon_t(void) throw() { this->clear(); }
00112 void clear(void) throw() {
00113 nVertices = 0;
00114 if (indices) {
00115 delete[] indices;
00116 indices = NULL;
00117 }
00118 if (u) {
00119 delete[] u;
00120 u = NULL;
00121 }
00122 if (v) {
00123 delete[] v;
00124 v = NULL;
00125 }
00126 material = NULL;
00127 }
00128
00129
00130 int nVertices;
00131 int * indices;
00132 float * u;
00133 float * v;
00134 smart_ptr<material_t> material;
00135 point3d_t normal;
00136 };
00137
00138
00139
00140
00141
00142 class model_t : public Renderable {
00143 public:
00144
00145 model_t(void) throw() : nVertices(0), vertices(NULL),
00146 nPolygons(0), polygons(NULL) { }
00147 ~model_t(void) throw() { this->clear(); }
00148 void clear(void) throw() {
00149 nVertices = nPolygons = 0;
00150 if (vertices) {
00151 delete[] vertices;
00152 vertices = NULL;
00153 }
00154 if (polygons) {
00155 delete[] polygons;
00156 polygons = NULL;
00157 }
00158 boundingBox.clear();
00159 }
00160
00161
00162 void render(IN const render_context_t& rc,
00163 IN RenderQueue * rq);
00164 rect3d_t getBoundingBox(void) const throw() { return boundingBox; }
00165
00166
00167 int nVertices;
00168 point3d_t * vertices;
00169 int nPolygons;
00170 polygon_t * polygons;
00171 rect3d_t boundingBox;
00172 };
00173
00174
00175
00176
00177 struct lod_entry_t {
00178 void clear(void) throw() {
00179 distance = 0.0;
00180 model.clear();
00181 }
00182
00183
00184 model_t model;
00185 float distance;
00186 };
00187
00188
00189
00190
00191 struct lod_model_t : public Renderable {
00192 public:
00193
00194 lod_model_t(void) throw() : nEntries(0), entries(NULL) { }
00195 ~lod_model_t(void) throw() { this->clear(); }
00196 void clear(void) throw() {
00197 nEntries = 0;
00198 if (entries) {
00199 delete[] entries;
00200 entries = NULL;
00201 }
00202 boundingBox.clear();
00203 }
00204
00205
00206 void render(IN const render_context_t& rc,
00207 IN RenderQueue * rq);
00208 rect3d_t getBoundingBox(void) const throw() { return boundingBox; }
00209
00210
00211 int nEntries;
00212 lod_entry_t * entries;
00213 rect3d_t boundingBox;
00214 };
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 void parseColor(IO std::istream& stream,
00225 OUT img_color_t& color);
00226
00227 void parseMaterial(IO std::istream& stream,
00228 IN const char * parentDir,
00229 OUT material_t& material);
00230
00231 void parsePolygon(IN MaterialRegistry * mreg,
00232 IO std::istream& stream,
00233 OUT polygon_t& polygon);
00234
00235 void parseModel(IN MaterialRegistry * mreg,
00236 IO std::istream& stream,
00237 OUT model_t& model);
00238
00239 void parseLodEntry(IN MaterialRegistry * mreg,
00240 IO std::istream& stream,
00241 OUT lod_entry_t& entry);
00242
00243 void parseLodModel(IN MaterialRegistry * mreg,
00244 IO std::istream& stream,
00245 OUT lod_model_t& lod_model);
00246
00247
00248
00249
00250 smart_ptr<MaterialRegistry> getSimpleRegistry(IN const char * materialDir);
00251
00252
00253
00254 smart_ptr<Renderable> loadModel(IN const char * filename,
00255 IN MaterialRegistry * reg);
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 void writeModelToStream(IO std::ostream& stream,
00267 IN const model_t& model);
00268
00269
00270
00271 };
00272
00273
00274 #endif // WAVE_GLUT_GLUT_MODEL_H__
00275