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
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
00100 reset_disp_list();
00101
00102
00103 append(DMATERIALON);
00104
00105
00106 for (k=0; k < 2; k++) {
00107 odd = (k == 1);
00108
00109
00110 if (odd)
00111 cmdColor.putdata(usecolors[0],cmdList);
00112 else
00113 cmdColor.putdata(usecolors[1],cmdList);
00114
00115
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
00139 if (pickpointindices.num() > 0) {
00140 DispCmdPickPointArray pickPointArray;
00141 pickPointArray.putdata(pickpointindices.num(), &pickpointindices[0],
00142 &pickpointcoords[0], cmdList);
00143 }
00144 }
00145
00146
00147
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
00166 char *Stage::loc_description(int ap) {
00167 return stageloc[ap];
00168 }
00169
00170
00171
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
00179 if (need_update && stagePos != NO_STAGE) {
00180 switch (stagePos) {
00181 case STAGE_ORIGIN:
00182
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;
00211
00212 default:
00213 msgErr << "Stage: Illegal stage location " << stagePos << " specified."
00214 << sendmsg;
00215 stagePos = STAGE_ORIGIN;
00216 return;
00217 }
00218
00219
00220 need_update = FALSE;
00221
00222
00223 create_cmdlist();
00224
00225 if (stagePos == NO_STAGE || movedStage)
00226 return;
00227
00228
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
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
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
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
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