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

Stage.C

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: Stage.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.51 $       $Date: 2011/02/17 23:17:19 $
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   float mycorner1[3] = { -1.0, 0.0, -1.0 };
00088   mycorner1[0] *= Size;
00089   mycorner1[1] *= Size;
00090   mycorner1[2] *= Size;
00091 
00092   memset(c, 0, sizeof(c));
00093   c[0][1] = c[1][1] = c[2][1] = c[3][1] = 0.0;
00094 
00095   // do reset first
00096   reset_disp_list();
00097 
00098   // turn on material characteristics
00099   append(DMATERIALON);
00100 
00101   // draw odd/even squares separately
00102   for (k=0; k < 2; k++) {
00103     odd = (k == 1);
00104     
00105     // set color in checkerboard
00106     if (odd)
00107       cmdColor.putdata(usecolors[0],cmdList);
00108     else
00109       cmdColor.putdata(usecolors[1],cmdList);
00110     
00111     // start in lower-left corner
00112     c[0][0] = c[3][0] = mycorner1[0];
00113     c[1][0] = c[2][0] = mycorner1[0] + inc;
00114 
00115     for (i=0; i < Panels; i++) {
00116       c[0][2] = c[1][2] = mycorner1[2];
00117       c[2][2] = c[3][2] = mycorner1[2] + inc;
00118       for (j=0; j < Panels; j++) {
00119         if (!odd) {
00120           cmdSquare.putdata(c[2], c[1], c[0], cmdList);
00121           pickPoint.putdata(c[2], 0, cmdList);
00122         }
00123 
00124         odd = !odd;
00125         c[0][2] += inc;  c[1][2] += inc;  c[2][2] += inc;  c[3][2] += inc;
00126       }
00127       c[0][0] += inc;  c[1][0] += inc;  c[2][0] += inc;  c[3][0] += inc;
00128       if (Panels % 2 == 0)
00129         odd = !odd;
00130     }
00131   }
00132 }
00133 
00134 
00135 // set stage display mode; return success
00136 int Stage::location(int ap) {
00137   movedStage = FALSE;
00138 
00139   if (ap != stagePos) {
00140     stagePos = ap;
00141     if (ap == NO_STAGE) {
00142       off();
00143     } else {
00144       on();
00145       need_update = TRUE;
00146     }
00147   }
00148 
00149   return TRUE;
00150 }
00151 
00152 
00153 // return descripton of location
00154 char *Stage::loc_description(int ap) {
00155   return stageloc[ap];
00156 }
00157 
00158 
00159 // routine to prepare the displayable object; must set the origin properly
00160 void Stage::prepare() {
00161   float rot_amount = 0.0, strans[3];
00162   char rot_axis = 'z';
00163   
00164   strans[0] = strans[1] = strans[2] = 0.0;
00165 
00166   // move the stage to its proper position
00167   if (need_update && stagePos != NO_STAGE) {
00168     switch (stagePos) {
00169       case STAGE_ORIGIN:
00170         // no offset/rotate, draw as-is
00171         break;
00172 
00173       case STAGE_LOWER:
00174         strans[1] = -1.0;
00175         break;
00176 
00177       case STAGE_UPPER:
00178         strans[1] = 1.0;
00179         break;
00180 
00181       case STAGE_LEFT:
00182         strans[0] = -1.0;
00183         rot_amount = -90.0;
00184         break;
00185 
00186       case STAGE_RIGHT:
00187         strans[0] = 1.0;
00188         rot_amount = 90.0;
00189         break;
00190 
00191       case STAGE_BEHIND:
00192         strans[2] = -1.0;
00193         rot_axis = 'x';
00194         rot_amount = 90.0;
00195         break;
00196 
00197       case NO_STAGE:
00198         return; // exit without drawing
00199 
00200       default:
00201         msgErr << "Stage: Illegal stage location " << stagePos << " specified."
00202                << sendmsg;
00203         stagePos = STAGE_ORIGIN;
00204         return; // exit without drawing
00205     }
00206 
00207     // update the current transformation
00208     need_update = FALSE;
00209     
00210     // (re)create the command list
00211     create_cmdlist();
00212 
00213     if (stagePos == NO_STAGE || movedStage)
00214       return; // don't update/modify Stage position
00215 
00216     // reset tranformation
00217     glob_trans_on();
00218     rot_on();
00219     reset_transformation();
00220     set_glob_trans(strans[0], strans[1], strans[2]);
00221     add_rot(rot_amount, rot_axis);
00222     rot_off();
00223     glob_trans_off();
00224   }
00225 }
00226 
00227 
00228 //
00229 // When the Stage is picked and moved with a pointer, this is used to move
00230 // the Stage to a new position.  The initial pointer position is remembered,
00231 // and subsequent motions add a global translation to the Stage.
00232 // This is done for any pick mode, and any button.  This is only done if the
00233 // item selected is actually the specific Stage object.
00234 //
00235 
00236 // called when a pick moves:
00237 //   args = display to use, obj picked, button, mode, tag, dim, pos
00238 // For 2D version: x & y are 0 ... 1, represent 'relative, scaled' coords.
00239 // For 3D version: x,y,z are transformed position of pointer
00240 // For the Stage, when it is selected and the pointer moves, we wish
00241 // to move the Stage as well.
00242 void Stage::pick_move(PickMode *, DisplayDevice *d,
00243                       int, int dim, const float *pos) {
00244   float moveStageOrigPos[3], newStageOrigPos[3];
00245   const float *newpos;
00246 
00247   // calculate amount to translate stage
00248   if (dim == 2) {
00249     float origin[3] = { 0.0, 0.0, 0.0 };
00250     tm.multpoint3d(origin, moveStageOrigPos);
00251     d->find_3D_from_2D(moveStageOrigPos, pos, newStageOrigPos);
00252     newpos = newStageOrigPos;
00253   } else {
00254     newpos = pos;
00255   }
00256 
00257   // apply transformation
00258   glob_trans_on();
00259   set_glob_trans(newpos[0], newpos[1], newpos[2]);
00260   glob_trans_off();
00261 
00262   movedStage = TRUE;
00263 }
00264 
00265 

Generated on Tue May 22 01:48:12 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002