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

Stage.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 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: Stage.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.54 $       $Date: 2019/09/26 03:19:41 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * A Displayable3D object which consists of a set of Stage, which may be
00020  * drawn anywhere on the screen, at any size.
00021  *
00022  ***************************************************************************/
00023 
00024 #include "Stage.h"
00025 #include "DisplayDevice.h"
00026 #include "Scene.h"
00027 #include "DispCmds.h"
00028 #include "Inform.h"
00029 #include "utilities.h"
00030 
00031 
00032 // string descriptions of stage locations
00033 static char *stageloc[Stage::STAGEPOS_TOTAL] = {
00034   (char *) "Off", (char *) "Origin", (char *) "Bottom", 
00035   (char *) "Top", (char *) "Left", (char *) "Right", (char *) "Behind" };
00036 
00037 
00038 // default colors
00039 #define STAGEEVENCOL    REGGREY
00040 #define STAGEODDCOL     REGSILVER
00041 
00042 // number of square tiles to draw in each direction
00043 #define STAGE_PANELS    8
00044 
00045 Stage::Stage(Displayable *disp) : Displayable(disp) {
00046   // Displayable characteristics
00047   rot_off();
00048   scale_off();
00049   glob_trans_off();
00050   cent_trans_off();
00051   
00052   // put stage in lower part of image by default
00053   movedStage = FALSE;           // stage has not been moved yet
00054   Size = 1.0f;                  // initial size of wall, half of total length
00055   Panels = 0;
00056   panels(STAGE_PANELS);         // really sets the panels, and panel size
00057   stagePos = STAGEPOS_TOTAL;    // (inits value so purify doesn't complain)
00058   location(NO_STAGE);           // position the stage
00059 
00060   colorCat = scene->add_color_category("Stage");
00061   scene->add_color_item(colorCat, "Even", STAGEEVENCOL);
00062   scene->add_color_item(colorCat, "Odd", STAGEODDCOL);
00063 
00064   do_color_changed(colorCat);
00065 }
00066 
00067 
00069 
00070 void Stage::do_color_changed(int clr) {
00071   if (clr == colorCat) {
00072     usecolors[0] = scene->category_item_value(colorCat, 
00073         scene->category_item_index(colorCat, "Even"));
00074     usecolors[1] = scene->category_item_value(colorCat, 
00075         scene->category_item_index(colorCat, "Odd"));
00076     // color changed for us, recreate command list
00077     need_update = TRUE;
00078   }
00079 }
00080 
00082 
00083 // create the drawing command list
00084 void Stage::create_cmdlist(void) {
00085   int i, j, k, odd;
00086   float c[4][3];
00087 
00088   ResizeArray<float> pickpointcoords;
00089   ResizeArray<int> pickpointindices;
00090 
00091   float mycorner1[3] = { -1.0, 0.0, -1.0 };
00092   mycorner1[0] *= Size;
00093   mycorner1[1] *= Size;
00094   mycorner1[2] *= Size;
00095 
00096   memset(c, 0, sizeof(c));
00097   c[0][1] = c[1][1] = c[2][1] = c[3][1] = 0.0;
00098 
00099   // do reset first
00100   reset_disp_list();
00101 
00102   // turn on material characteristics
00103   append(DMATERIALON);
00104 
00105   // draw odd/even squares separately
00106   for (k=0; k < 2; k++) {
00107     odd = (k == 1);
00108     
00109     // set color in checkerboard
00110     if (odd)
00111       cmdColor.putdata(usecolors[0],cmdList);
00112     else
00113       cmdColor.putdata(usecolors[1],cmdList);
00114     
00115     // start in lower-left corner
00116     c[0][0] = c[3][0] = mycorner1[0];
00117     c[1][0] = c[2][0] = mycorner1[0] + inc;
00118 
00119     for (i=0; i < Panels; i++) {
00120       c[0][2] = c[1][2] = mycorner1[2];
00121       c[2][2] = c[3][2] = mycorner1[2] + inc;
00122       for (j=0; j < Panels; j++) {
00123         if (!odd) {
00124           cmdSquare.putdata(c[2], c[1], c[0], cmdList);
00125           pickpointcoords.append3(c[2]);
00126           pickpointindices.append(0);
00127         }
00128 
00129         odd = !odd;
00130         c[0][2] += inc;  c[1][2] += inc;  c[2][2] += inc;  c[3][2] += inc;
00131       }
00132       c[0][0] += inc;  c[1][0] += inc;  c[2][0] += inc;  c[3][0] += inc;
00133       if (Panels % 2 == 0)
00134         odd = !odd;
00135     }
00136   }
00137 
00138   // draw the pickpoints if we have any
00139   if (pickpointindices.num() > 0) {
00140     DispCmdPickPointArray pickPointArray;
00141     pickPointArray.putdata(pickpointindices.num(), &pickpointindices[0],
00142                            &pickpointcoords[0], cmdList);
00143   }
00144 }
00145 
00146 
00147 // set stage display mode; return success
00148 int Stage::location(int ap) {
00149   movedStage = FALSE;
00150 
00151   if (ap != stagePos) {
00152     stagePos = ap;
00153     if (ap == NO_STAGE) {
00154       off();
00155     } else {
00156       on();
00157       need_update = TRUE;
00158     }
00159   }
00160 
00161   return TRUE;
00162 }
00163 
00164 
00165 // return descripton of location
00166 char *Stage::loc_description(int ap) {
00167   return stageloc[ap];
00168 }
00169 
00170 
00171 // routine to prepare the displayable object; must set the origin properly
00172 void Stage::prepare() {
00173   float rot_amount = 0.0, strans[3];
00174   char rot_axis = 'z';
00175   
00176   strans[0] = strans[1] = strans[2] = 0.0;
00177 
00178   // move the stage to its proper position
00179   if (need_update && stagePos != NO_STAGE) {
00180     switch (stagePos) {
00181       case STAGE_ORIGIN:
00182         // no offset/rotate, draw as-is
00183         break;
00184 
00185       case STAGE_LOWER:
00186         strans[1] = -1.0;
00187         break;
00188 
00189       case STAGE_UPPER:
00190         strans[1] = 1.0;
00191         break;
00192 
00193       case STAGE_LEFT:
00194         strans[0] = -1.0;
00195         rot_amount = -90.0;
00196         break;
00197 
00198       case STAGE_RIGHT:
00199         strans[0] = 1.0;
00200         rot_amount = 90.0;
00201         break;
00202 
00203       case STAGE_BEHIND:
00204         strans[2] = -1.0;
00205         rot_axis = 'x';
00206         rot_amount = 90.0;
00207         break;
00208 
00209       case NO_STAGE:
00210         return; // exit without drawing
00211 
00212       default:
00213         msgErr << "Stage: Illegal stage location " << stagePos << " specified."
00214                << sendmsg;
00215         stagePos = STAGE_ORIGIN;
00216         return; // exit without drawing
00217     }
00218 
00219     // update the current transformation
00220     need_update = FALSE;
00221     
00222     // (re)create the command list
00223     create_cmdlist();
00224 
00225     if (stagePos == NO_STAGE || movedStage)
00226       return; // don't update/modify Stage position
00227 
00228     // reset tranformation
00229     glob_trans_on();
00230     rot_on();
00231     reset_transformation();
00232     set_glob_trans(strans[0], strans[1], strans[2]);
00233     add_rot(rot_amount, rot_axis);
00234     rot_off();
00235     glob_trans_off();
00236   }
00237 }
00238 
00239 
00240 //
00241 // When the Stage is picked and moved with a pointer, this is used to move
00242 // the Stage to a new position.  The initial pointer position is remembered,
00243 // and subsequent motions add a global translation to the Stage.
00244 // This is done for any pick mode, and any button.  This is only done if the
00245 // item selected is actually the specific Stage object.
00246 //
00247 
00248 // called when a pick moves:
00249 //   args = display to use, obj picked, button, mode, tag, dim, pos
00250 // For 2D version: x & y are 0 ... 1, represent 'relative, scaled' coords.
00251 // For 3D version: x,y,z are transformed position of pointer
00252 // For the Stage, when it is selected and the pointer moves, we wish
00253 // to move the Stage as well.
00254 void Stage::pick_move(PickMode *, DisplayDevice *d,
00255                       int, int dim, const float *pos) {
00256   float moveStageOrigPos[3], newStageOrigPos[3];
00257   const float *newpos;
00258 
00259   // calculate amount to translate stage
00260   if (dim == 2) {
00261     float origin[3] = { 0.0, 0.0, 0.0 };
00262     tm.multpoint3d(origin, moveStageOrigPos);
00263     d->find_3D_from_2D(moveStageOrigPos, pos, newStageOrigPos);
00264     newpos = newStageOrigPos;
00265   } else {
00266     newpos = pos;
00267   }
00268 
00269   // apply transformation
00270   glob_trans_on();
00271   set_glob_trans(newpos[0], newpos[1], newpos[2]);
00272   glob_trans_off();
00273 
00274   movedStage = TRUE;
00275 }
00276 
00277 

Generated on Sat Apr 20 02:43:43 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002