Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Displayable.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2011 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: Displayable.h,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.86 $       $Date: 2010/12/16 04:08:12 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * Base class for all objects which are drawn in the DisplayDevice.
00020  * Each Displayable is also a linked list of other Displayables, which act
00021  * as 'children' to the parent, i.e. they get the parent's tranformation as
00022  * well as their own.
00023  *
00024  ***************************************************************************/
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   // routines for working as a Pickable
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   // deal with child Displayable's
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   // make the object fixed (not responsive to scale/rot/trans commands
00166   int fixed(void) const { return isFixed; }
00167   void fix(void)   { isFixed = TRUE;  }
00168   void unfix(void) { isFixed = FALSE; }
00169 
00170   //
00171   // preparation/update routines
00172   //
00173   
00175   // Return 0 if we do not require a redraw, or 1 if we do. 
00176   int draw_prepare();
00177 
00179   virtual void prepare();
00180 
00182   void draw(DisplayDevice *) const;
00183 
00184   //
00185   // command to set whether to be affected by particular trans routines
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   // command to change transformation
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   // Material functions 
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   // Clipping plane functions; these are just wrappers for the VMDDisplayList
00240   // methods
00241   //
00242   const VMDClipPlane *clipplane(int i) {
00243     return cmdList->clipplane(i);
00244   }
00245   int set_clip_center(int i, const float *center) {
00246     int rc = cmdList->set_clip_center(i, center);
00247     if (rc) _needUpdate = 1;
00248     return rc;
00249   }
00250   int set_clip_normal(int i, const float *normal) {
00251     int rc = cmdList->set_clip_normal(i, normal);
00252     if (rc) _needUpdate = 1;
00253     return rc;
00254   }
00255   int set_clip_color(int i, const float *color) {
00256     int rc = cmdList->set_clip_color(i, color);
00257     if (rc) _needUpdate = 1;
00258     return rc;
00259   }
00260   int set_clip_status(int i, int mode) {
00261     int rc = cmdList->set_clip_status(i, mode);
00262     if (rc) _needUpdate = 1;
00263     return rc;
00264   } 
00265 };
00266 
00267 #endif
00268 

Generated on Thu May 23 01:47:22 2013 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002