00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00025 #ifndef DISPLAYABLE_H
00026 #define DISPLAYABLE_H
00027
00028 #include "Matrix4.h"
00029 #include "ResizeArray.h"
00030 #include "Pickable.h"
00031 #include "utilities.h"
00032 #include "VMDDisplayList.h"
00033 #include "MaterialList.h"
00034
00035 class DisplayDevice;
00036 class Scene;
00037
00039 class Displayable : public Pickable {
00040 public:
00044 void *operator new(size_t);
00045 void operator delete(void *, size_t);
00046
00048 Matrix4 rotm;
00049 float globt[3];
00050 float centt[3];
00051 float scale;
00052 Matrix4 tm;
00053
00055 int needUpdate(void) { return _needUpdate; }
00056
00057 private:
00059 int _needUpdate;
00060
00062 int needMatrixRecalc;
00063
00065 void do_create();
00066
00067 protected:
00069 VMDDisplayList *cmdList;
00070
00072 Scene *scene;
00073
00075 void append(int d) { cmdList->append(d, 0); }
00076
00078 int doCent, doRot, doGlob, doScale;
00079
00081 int isFixed;
00082
00084 int isOn;
00085
00087 void recalc_mat(void);
00088
00090 Displayable *parent;
00091
00093 Displayable **children;
00094 int num_children;
00095 int max_children;
00096
00097 virtual void do_color_changed(int cat) {}
00098 virtual void do_color_rgb_changed(int color) {}
00099 virtual void do_color_scale_changed() {}
00100
00101 public:
00103 Displayable(Displayable *);
00104
00106 Displayable(Scene *);
00107
00109 virtual ~Displayable(void);
00110
00112 void reset_disp_list(void);
00113
00115 void need_matrix_recalc(void) { needMatrixRecalc = TRUE; }
00116
00117
00118
00119
00120
00122 virtual VMDDisplayList *pick_cmd_list(void);
00123
00125 virtual int pickable_on(void);
00126
00128 void color_changed(int cat);
00129
00131 void color_rgb_changed(int color);
00132
00134 void color_scale_changed();
00135
00136
00137
00138
00139
00141 Displayable *child(int N) const { return children[N]; }
00142
00144 int child_index(Displayable *d) {
00145 for (int i=0; i<num_children; i++)
00146 if (d == child(i)) return i;
00147 return -1;
00148 }
00149
00151 void add_child(Displayable *);
00152
00154 int remove_child(Displayable *);
00155
00157 int remove_child(int N) { return remove_child(child(N)); }
00158
00159 int displayed(void) const {
00160 return isOn;
00161 }
00162 void off(void);
00163 void on(void);
00164
00165
00166 int fixed(void) const { return isFixed; }
00167 void fix(void) { isFixed = TRUE; }
00168 void unfix(void) { isFixed = FALSE; }
00169
00170
00171
00172
00173
00175
00176 int draw_prepare();
00177
00179 virtual void prepare();
00180
00182 void draw(DisplayDevice *) const;
00183
00184
00185
00186
00187 void scale_on(void) { doScale = TRUE; }
00188 void scale_off(void) { doScale = FALSE; }
00189 int scaling(void) const { return doScale && !fixed(); }
00190
00191 void rot_on(void) { doRot = TRUE; }
00192 void rot_off(void) { doRot = FALSE; }
00193 int rotating(void) const { return doRot && !fixed(); }
00194
00195 void cent_trans_on(void) { doCent = TRUE; }
00196 void cent_trans_off(void) { doCent = FALSE; }
00197 int cent_translating(void) const { return doCent; }
00198
00199 void glob_trans_on(void) { doGlob = TRUE; }
00200 void glob_trans_off(void) { doGlob = FALSE; }
00201 int glob_translating(void) const { return doGlob && !fixed(); }
00202
00203
00204
00205
00206
00208 virtual void reset_transformation(void);
00209
00210 void set_scale(float s);
00211 void mult_scale(float s);
00212
00213 void add_rot(float x, char axis);
00214 void add_rot(const Matrix4 &);
00215 void set_rot(float x, char axis);
00216 void set_rot(const Matrix4 &);
00217
00218 void set_glob_trans(float, float, float);
00219 void add_glob_trans(float, float, float);
00220
00221 void set_cent_trans(float, float, float);
00222 void add_cent_trans(float, float, float);
00223
00226 void change_center(float x, float y, float z);
00227
00228 void cacheskip(int onoff);
00229
00230
00231
00232
00233 void change_material(const Material *);
00234 int curr_material() const;
00235 void update_material(const Material *mat);
00236 void delete_material(int n, const MaterialList *);
00237
00238
00239
00240
00241
00242 const VMDClipPlane *clipplane(int i) {
00243 return cmdList->clipplane(i);
00244 }
00245
00246
00247 int set_clip_center(int i, const float *center) {
00248 int rc = cmdList->set_clip_center(i, center);
00249 #if 1
00250
00251
00252 int clipmode = 0;
00253 rc = cmdList->get_clip_status(i, clipmode);
00254 if (rc && (clipmode != 0)) _needUpdate = 1;
00255 #else
00256 if (rc) _needUpdate = 1;
00257 #endif
00258 return rc;
00259 }
00260
00261
00262 int set_clip_normal(int i, const float *normal) {
00263 int rc = cmdList->set_clip_normal(i, normal);
00264 #if 1
00265
00266
00267 int clipmode = 0;
00268 rc = cmdList->get_clip_status(i, clipmode);
00269 if (rc && (clipmode != 0)) _needUpdate = 1;
00270 #else
00271 if (rc) _needUpdate = 1;
00272 #endif
00273 return rc;
00274 }
00275
00276
00277 int set_clip_color(int i, const float *color) {
00278 int rc = cmdList->set_clip_color(i, color);
00279 #if 1
00280
00281
00282 int clipmode = 0;
00283 rc = cmdList->get_clip_status(i, clipmode);
00284 if (rc && (clipmode != 0)) _needUpdate = 1;
00285 #else
00286 if (rc) _needUpdate = 1;
00287 #endif
00288 return rc;
00289 }
00290
00291
00292 int set_clip_status(int i, int mode) {
00293 #if 1
00294
00295
00296 int oldclipmode = 0;
00297 int rc = cmdList->get_clip_status(i, oldclipmode);
00298 if (rc && (oldclipmode != mode)) {
00299 rc = cmdList->set_clip_status(i, mode);
00300 if (rc) _needUpdate = 1;
00301 }
00302 #else
00303 int rc = cmdList->set_clip_status(i, mode);
00304 if (rc) _needUpdate = 1;
00305 #endif
00306 return rc;
00307 }
00308 };
00309
00310 #endif
00311