00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pgFrameStyle.h"
00020 #include "geomTristrip.h"
00021 #include "geomTrifan.h"
00022 #include "geomNode.h"
00023 #include "pandaNode.h"
00024 #include "transparencyAttrib.h"
00025 #include "pointerTo.h"
00026 #include "nodePath.h"
00027
00028 ostream &
00029 operator << (ostream &out, PGFrameStyle::Type type) {
00030 switch (type) {
00031 case PGFrameStyle::T_none:
00032 return out << "none";
00033
00034 case PGFrameStyle::T_flat:
00035 return out << "flat";
00036
00037 case PGFrameStyle::T_bevel_out:
00038 return out << "bevel_out";
00039
00040 case PGFrameStyle::T_bevel_in:
00041 return out << "bevel_in";
00042
00043 case PGFrameStyle::T_groove:
00044 return out << "groove";
00045
00046 case PGFrameStyle::T_ridge:
00047 return out << "ridge";
00048 }
00049
00050 return out << "**unknown(" << (int)type << ")**";
00051 }
00052
00053
00054
00055
00056
00057
00058 void PGFrameStyle::
00059 output(ostream &out) const {
00060 out << _type << " color = " << _color << " width = " << _width;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 bool PGFrameStyle::
00072 xform(const LMatrix4f &mat) {
00073
00074
00075
00076 LVector3f x, z;
00077 mat.get_row3(x, 0);
00078 float x_scale = x.length();
00079
00080 mat.get_row3(z, 2);
00081 float z_scale = z.length();
00082
00083 _width[0] *= x_scale;
00084 _width[1] *= z_scale;
00085
00086 switch (_type) {
00087 case T_none:
00088 case T_flat:
00089 return false;
00090
00091 case T_bevel_out:
00092 case T_bevel_in:
00093 case T_groove:
00094 case T_ridge:
00095 return true;
00096 }
00097
00098
00099 return true;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 NodePath PGFrameStyle::
00113 generate_into(const NodePath &parent, const LVecBase4f &frame) {
00114 PT(PandaNode) new_node;
00115
00116 switch (_type) {
00117 case T_none:
00118 return NodePath();
00119
00120 case T_flat:
00121 new_node = generate_flat_geom(frame);
00122 break;
00123
00124 case T_bevel_out:
00125 new_node = generate_bevel_geom(frame, false);
00126 break;
00127
00128 case T_bevel_in:
00129 new_node = generate_bevel_geom(frame, true);
00130 break;
00131
00132 case T_groove:
00133 new_node = generate_groove_geom(frame, true);
00134 break;
00135
00136 case T_ridge:
00137 new_node = generate_groove_geom(frame, false);
00138 break;
00139
00140 default:
00141 break;
00142 }
00143
00144 if (new_node != (PandaNode *)NULL && _color[3] != 1.0f) {
00145
00146 new_node->set_attrib(TransparencyAttrib::make(TransparencyAttrib::M_alpha));
00147 }
00148
00149
00150 return parent.attach_new_node(new_node);
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 PT(PandaNode) PGFrameStyle::
00160 generate_flat_geom(const LVecBase4f &frame) {
00161 PT(GeomNode) gnode = new GeomNode("flat");
00162 Geom *geom = new GeomTristrip;
00163 gnode->add_geom(geom);
00164
00165 float left = frame[0];
00166 float right = frame[1];
00167 float bottom = frame[2];
00168 float top = frame[3];
00169
00170 PTA_int lengths=PTA_int::empty_array(0);
00171 lengths.push_back(4);
00172
00173 PTA_Vertexf verts;
00174 verts.push_back(Vertexf(left, 0.0f, top));
00175 verts.push_back(Vertexf(left, 0.0f, bottom));
00176 verts.push_back(Vertexf(right, 0.0f, top));
00177 verts.push_back(Vertexf(right, 0.0f, bottom));
00178
00179 geom->set_num_prims(1);
00180 geom->set_lengths(lengths);
00181
00182 geom->set_coords(verts);
00183
00184 PTA_Colorf colors;
00185 colors.push_back(_color);
00186 geom->set_colors(colors, G_OVERALL);
00187
00188 return gnode.p();
00189 }
00190
00191
00192
00193
00194
00195
00196
00197 PT(PandaNode) PGFrameStyle::
00198 generate_bevel_geom(const LVecBase4f &frame, bool in) {
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 PT(GeomNode) gnode = new GeomNode("bevel");
00257
00258 float left = frame[0];
00259 float right = frame[1];
00260 float bottom = frame[2];
00261 float top = frame[3];
00262
00263 float inner_left = left + _width[0];
00264 float inner_right = right - _width[0];
00265 float inner_bottom = bottom + _width[1];
00266 float inner_top = top - _width[1];
00267
00268 float left_color_scale = 1.2;
00269 float right_color_scale = 0.8;
00270 float bottom_color_scale = 0.7;
00271 float top_color_scale = 1.3;
00272
00273 if (in) {
00274 right_color_scale = 1.2;
00275 left_color_scale = 0.8;
00276 top_color_scale = 0.7;
00277 bottom_color_scale = 1.3;
00278 }
00279
00280
00281 Colorf cleft(min(_color[0] * left_color_scale, 1.0f),
00282 min(_color[1] * left_color_scale, 1.0f),
00283 min(_color[2] * left_color_scale, 1.0f),
00284 _color[3]);
00285
00286 Colorf cright(min(_color[0] * right_color_scale, 1.0f),
00287 min(_color[1] * right_color_scale, 1.0f),
00288 min(_color[2] * right_color_scale, 1.0f),
00289 _color[3]);
00290
00291 Colorf cbottom(min(_color[0] * bottom_color_scale, 1.0f),
00292 min(_color[1] * bottom_color_scale, 1.0f),
00293 min(_color[2] * bottom_color_scale, 1.0f),
00294 _color[3]);
00295
00296 Colorf ctop(min(_color[0] * top_color_scale, 1.0f),
00297 min(_color[1] * top_color_scale, 1.0f),
00298 min(_color[2] * top_color_scale, 1.0f),
00299 _color[3]);
00300
00301
00302 Geom *geom = new GeomTristrip;
00303 gnode->add_geom(geom);
00304
00305 PTA_int lengths;
00306 PTA_Vertexf verts;
00307 PTA_Colorf colors;
00308
00309
00310 lengths.push_back(8);
00311
00312 verts.push_back(Vertexf(right, 0.0f, bottom));
00313 verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom));
00314 verts.push_back(Vertexf(left, 0.0f, bottom));
00315 verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom));
00316 verts.push_back(Vertexf(left, 0.0f, top));
00317 verts.push_back(Vertexf(inner_left, 0.0f, inner_top));
00318 verts.push_back(Vertexf(right, 0.0f, top));
00319 verts.push_back(Vertexf(inner_right, 0.0f, inner_top));
00320
00321 colors.push_back(cbottom);
00322 colors.push_back(cbottom);
00323 colors.push_back(cleft);
00324 colors.push_back(cleft);
00325 colors.push_back(ctop);
00326 colors.push_back(ctop);
00327
00328
00329 lengths.push_back(6);
00330
00331 verts.push_back(Vertexf(right, 0.0f, bottom));
00332 verts.push_back(Vertexf(right, 0.0f, top));
00333 verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom));
00334 verts.push_back(Vertexf(inner_right, 0.0f, inner_top));
00335 verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom));
00336 verts.push_back(Vertexf(inner_left, 0.0f, inner_top));
00337
00338 colors.push_back(cright);
00339 colors.push_back(cright);
00340 colors.push_back(_color);
00341 colors.push_back(_color);
00342
00343 geom->set_num_prims(2);
00344 geom->set_lengths(lengths);
00345 geom->set_coords(verts);
00346 geom->set_colors(colors, G_PER_COMPONENT);
00347
00348 return gnode.p();
00349 }
00350
00351
00352
00353
00354
00355
00356
00357 PT(PandaNode) PGFrameStyle::
00358 generate_groove_geom(const LVecBase4f &frame, bool in) {
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 PT(GeomNode) gnode = new GeomNode("groove");
00458
00459 float left = frame[0];
00460 float right = frame[1];
00461 float bottom = frame[2];
00462 float top = frame[3];
00463
00464 float mid_left = left + 0.5f * _width[0];
00465 float mid_right = right - 0.5f * _width[0];
00466 float mid_bottom = bottom + 0.5f * _width[1];
00467 float mid_top = top - 0.5f * _width[1];
00468
00469 float inner_left = left + _width[0];
00470 float inner_right = right - _width[0];
00471 float inner_bottom = bottom + _width[1];
00472 float inner_top = top - _width[1];
00473
00474 float left_color_scale = 1.2f;
00475 float right_color_scale = 0.8f;
00476 float bottom_color_scale = 0.7f;
00477 float top_color_scale = 1.3f;
00478
00479 if (in) {
00480 right_color_scale = 1.2f;
00481 left_color_scale = 0.8f;
00482 top_color_scale = 0.7f;
00483 bottom_color_scale = 1.3f;
00484 }
00485
00486
00487 Colorf cleft(min(_color[0] * left_color_scale, 1.0f),
00488 min(_color[1] * left_color_scale, 1.0f),
00489 min(_color[2] * left_color_scale, 1.0f),
00490 _color[3]);
00491
00492 Colorf cright(min(_color[0] * right_color_scale, 1.0f),
00493 min(_color[1] * right_color_scale, 1.0f),
00494 min(_color[2] * right_color_scale, 1.0f),
00495 _color[3]);
00496
00497 Colorf cbottom(min(_color[0] * bottom_color_scale, 1.0f),
00498 min(_color[1] * bottom_color_scale, 1.0f),
00499 min(_color[2] * bottom_color_scale, 1.0f),
00500 _color[3]);
00501
00502 Colorf ctop(min(_color[0] * top_color_scale, 1.0f),
00503 min(_color[1] * top_color_scale, 1.0f),
00504 min(_color[2] * top_color_scale, 1.0f),
00505 _color[3]);
00506
00507
00508 Geom *geom = new GeomTristrip;
00509 gnode->add_geom(geom);
00510
00511 PTA_int lengths;
00512 PTA_Vertexf verts;
00513 PTA_Colorf colors;
00514
00515
00516 lengths.push_back(8);
00517
00518 verts.push_back(Vertexf(right, 0.0f, bottom));
00519 verts.push_back(Vertexf(mid_right, 0.0f, mid_bottom));
00520 verts.push_back(Vertexf(left, 0.0f, bottom));
00521 verts.push_back(Vertexf(mid_left, 0.0f, mid_bottom));
00522 verts.push_back(Vertexf(left, 0.0f, top));
00523 verts.push_back(Vertexf(mid_left, 0.0f, mid_top));
00524 verts.push_back(Vertexf(right, 0.0f, top));
00525 verts.push_back(Vertexf(mid_right, 0.0f, mid_top));
00526
00527 colors.push_back(cbottom);
00528 colors.push_back(cbottom);
00529 colors.push_back(cleft);
00530 colors.push_back(cleft);
00531 colors.push_back(ctop);
00532 colors.push_back(ctop);
00533
00534
00535 lengths.push_back(8);
00536
00537 verts.push_back(Vertexf(mid_right, 0.0f, mid_bottom));
00538 verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom));
00539 verts.push_back(Vertexf(mid_left, 0.0f, mid_bottom));
00540 verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom));
00541 verts.push_back(Vertexf(mid_left, 0.0f, mid_top));
00542 verts.push_back(Vertexf(inner_left, 0.0f, inner_top));
00543 verts.push_back(Vertexf(mid_right, 0.0f, mid_top));
00544 verts.push_back(Vertexf(inner_right, 0.0f, inner_top));
00545
00546 colors.push_back(ctop);
00547 colors.push_back(ctop);
00548 colors.push_back(cright);
00549 colors.push_back(cright);
00550 colors.push_back(cbottom);
00551 colors.push_back(cbottom);
00552
00553
00554 lengths.push_back(8);
00555
00556 verts.push_back(Vertexf(right, 0.0f, bottom));
00557 verts.push_back(Vertexf(right, 0.0f, top));
00558 verts.push_back(Vertexf(mid_right, 0.0f, mid_bottom));
00559 verts.push_back(Vertexf(mid_right, 0.0f, mid_top));
00560 verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom));
00561 verts.push_back(Vertexf(inner_right, 0.0f, inner_top));
00562 verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom));
00563 verts.push_back(Vertexf(inner_left, 0.0f, inner_top));
00564
00565 colors.push_back(cright);
00566 colors.push_back(cright);
00567 colors.push_back(cleft);
00568 colors.push_back(cleft);
00569 colors.push_back(_color);
00570 colors.push_back(_color);
00571
00572 geom->set_num_prims(3);
00573 geom->set_lengths(lengths);
00574 geom->set_coords(verts);
00575 geom->set_colors(colors, G_PER_COMPONENT);
00576
00577 return gnode.p();
00578 }