Main Page   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-2008 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.44 $       $Date: 2008/03/27 19:36:46 $
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 
00043 Stage::Stage(Displayable *disp) : Displayable(disp) {
00044 
00045   // Displayable characteristics
00046   rot_off();
00047   scale_off();
00048   glob_trans_off();
00049   cent_trans_off();
00050   
00051   // put stage in lower part of image by default
00052   Panels = 0;
00053   panels(STAGE_PANELS);         // really sets the panels, and panel size
00054   stagePos = STAGEPOS_TOTAL;    // (inits value so purify doesn't complain)
00055   location(NO_STAGE);           // position the stage
00056 
00057   colorCat = scene->add_color_category("Stage");
00058   scene->add_color_item(colorCat, "Even", STAGEEVENCOL);
00059   scene->add_color_item(colorCat, "Odd", STAGEODDCOL);
00060 
00061   do_color_changed(colorCat);
00062 }
00063 
00064 
00066 
00067 void Stage::do_color_changed(int clr) {
00068   if (clr == colorCat) {
00069     usecolors[0] = scene->category_item_value(colorCat, 
00070         scene->category_item_index(colorCat, "Even"));
00071     usecolors[1] = scene->category_item_value(colorCat, 
00072         scene->category_item_index(colorCat, "Odd"));
00073     // color changed for us, recreate command list
00074     need_update = TRUE;
00075   }
00076 }
00077 
00079 
00080 // create the drawing command list
00081 void Stage::create_cmdlist(void) {
00082   int i, j, k, odd;
00083   float c[4][3], mycorner1[3];
00084 
00085   mycorner1[0] = mycorner1[2] = -1.0;  mycorner1[1] = 0.0;
00086   c[0][1] = c[1][1] = c[2][1] = c[3][1] = 0.0;
00087 
00088   // do reset first
00089   reset_disp_list();
00090 
00091   // turn off material characteristics
00092   append(DMATERIALOFF);
00093 
00094   // draw odd/even squares separately
00095   for(k=0; k < 2; k++) {
00096     odd = (k == 1);
00097     
00098     // set color in checkerboard
00099     if (odd)
00100       cmdColor.putdata(usecolors[0],cmdList);
00101     else
00102       cmdColor.putdata(usecolors[1],cmdList);
00103     
00104     // start in lower-left corner
00105     c[0][0] = c[3][0] = mycorner1[0];
00106     c[1][0] = c[2][0] = mycorner1[0] + inc;
00107 
00108     for(i=0; i < Panels; i++) {
00109       c[0][2] = c[1][2] = mycorner1[2];
00110       c[2][2] = c[3][2] = mycorner1[2] + inc;
00111       for(j=0; j < Panels; j++) {
00112         if(!odd)
00113           cmdSquare.putdata(c[2], c[1], c[0], cmdList);
00114         odd = !odd;
00115         c[0][2] += inc;  c[1][2] += inc;  c[2][2] += inc;  c[3][2] += inc;
00116       }
00117       c[0][0] += inc;  c[1][0] += inc;  c[2][0] += inc;  c[3][0] += inc;
00118       if(Panels % 2 == 0)
00119         odd = !odd;
00120     }
00121   }
00122 }
00123 
00124 
00125 // set stage display mode; return success
00126 int Stage::location(int ap) {
00127   if (ap != stagePos) {
00128     stagePos = ap;
00129     if (ap == NO_STAGE) {
00130       off();
00131     } else {
00132       on();
00133       need_update = TRUE;
00134     }
00135   }
00136 
00137   return TRUE;
00138 }
00139 
00140 
00141 // return descripton of location
00142 char *Stage::loc_description(int ap) {
00143   return stageloc[ap];
00144 }
00145 
00146 
00147 // routine to prepare the displayable object; must set the origin properly
00148 void Stage::prepare() {
00149   float rot_amount = 0.0, strans[3];
00150   char rot_axes = 'z';
00151   
00152   strans[0] = strans[1] = strans[2] = 0.0;
00153   
00154   // move the stage to its proper position
00155   if (need_update && stagePos != NO_STAGE) {
00156     if (stagePos == STAGE_ORIGIN) {
00157       ;
00158     } else if(stagePos == STAGE_LOWER) {
00159       strans[1] = -1.0;
00160     } else if(stagePos == STAGE_UPPER) {
00161       strans[1] = 1.0;
00162     } else if(stagePos == STAGE_LEFT) {
00163       strans[0] = -1.0;
00164       rot_amount = -90.0;
00165     } else if(stagePos == STAGE_RIGHT) {
00166       strans[0] = 1.0;
00167       rot_amount = 90.0;
00168     } else if(stagePos == STAGE_BEHIND) {
00169       strans[2] = -1.0;
00170       rot_axes = 'x';
00171       rot_amount = 90.0;
00172     } else {
00173       msgErr << "Stage: Illegal stage location " << stagePos << " specified."
00174              << sendmsg;
00175       stagePos = STAGE_ORIGIN;
00176       return;
00177     }
00178 
00179     // update the current transformation
00180     need_update = FALSE;
00181     
00182     // (re)create the command list
00183     create_cmdlist();
00184 
00185     // reset tranformation
00186     glob_trans_on();
00187     rot_on();
00188     reset_transformation();
00189     set_glob_trans(strans[0], strans[1], strans[2]);
00190     add_rot(rot_amount, rot_axes);
00191     rot_off();
00192     glob_trans_off();
00193   }
00194 }
00195 

Generated on Mon Sep 8 01:26:22 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002