00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00039 #define STAGEEVENCOL REGGREY
00040 #define STAGEODDCOL REGSILVER
00041
00042
00043 #define STAGE_PANELS 8
00044
00045 Stage::Stage(Displayable *disp) : Displayable(disp) {
00046
00047 rot_off();
00048 scale_off();
00049 glob_trans_off();
00050 cent_trans_off();
00051
00052
00053 movedStage = FALSE;
00054 Size = 1.0f;
00055 Panels = 0;
00056 panels(STAGE_PANELS);
00057 stagePos = STAGEPOS_TOTAL;
00058 location(NO_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
00077 need_update = TRUE;
00078 }
00079 }
00080
00082
00083
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
00096 reset_disp_list();
00097
00098
00099 append(DMATERIALON);
00100
00101
00102 for (k=0; k < 2; k++) {
00103 odd = (k == 1);
00104
00105
00106 if (odd)
00107 cmdColor.putdata(usecolors[0],cmdList);
00108 else
00109 cmdColor.putdata(usecolors[1],cmdList);
00110
00111
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
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
00154 char *Stage::loc_description(int ap) {
00155 return stageloc[ap];
00156 }
00157
00158
00159
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
00167 if (need_update && stagePos != NO_STAGE) {
00168 switch (stagePos) {
00169 case STAGE_ORIGIN:
00170
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;
00199
00200 default:
00201 msgErr << "Stage: Illegal stage location " << stagePos << " specified."
00202 << sendmsg;
00203 stagePos = STAGE_ORIGIN;
00204 return;
00205 }
00206
00207
00208 need_update = FALSE;
00209
00210
00211 create_cmdlist();
00212
00213 if (stagePos == NO_STAGE || movedStage)
00214 return;
00215
00216
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
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
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
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
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