58#include "rock_floor.rgb_src.c"
63#include "shuttle_controls.bam_src.c"
65using std::istringstream;
66using std::ostringstream;
70static const int override_priority = 100;
72PT(
TextFont) WindowFramework::_shuttle_controls_font =
nullptr;
80 _panda_framework(panda_framework)
82 _got_keyboard =
false;
83 _got_trackball =
false;
85 _anim_controls_enabled =
false;
87 _wireframe_enabled =
false;
88 _wireframe_filled =
false;
89 _texture_enabled =
true;
90 _two_sided_enabled =
false;
91 _one_sided_reverse_enabled =
false;
92 _lighting_enabled =
false;
93 _perpixel_enabled =
false;
94 _background_type = BT_default;
102 _panda_framework(copy._panda_framework),
103 _window(copy._window),
104 _display_region_3d(display_region)
106 _got_keyboard =
false;
107 _got_trackball =
false;
109 _anim_controls_enabled =
false;
111 _wireframe_enabled =
false;
112 _texture_enabled =
true;
113 _two_sided_enabled =
false;
114 _one_sided_reverse_enabled =
false;
115 _lighting_enabled =
false;
116 _perpixel_enabled =
false;
117 _background_type = BT_default;
119 set_background_type(copy._background_type);
122 _display_region_3d->set_camera(camera_np);
141 nassertr(_window ==
nullptr, _window);
143 static int next_window_index = 1;
144 ostringstream stream;
145 stream <<
"window" << next_window_index;
147 string name = stream.str();
150 GraphicsOutput *winout =
152 props, flags, gsg,
nullptr);
153 if (winout !=
nullptr) {
163 _window->set_clear_depth_active(
false);
164 _window->set_clear_stencil_active(
false);
168 _display_region_3d->set_camera(camera_np);
172 if (show_frame_rate_meter) {
173 _frame_rate_meter =
new FrameRateMeter(
"frame_rate_meter");
174 _frame_rate_meter->setup_window(_window);
176 if (show_scene_graph_analyzer_meter) {
177 _scene_graph_analyzer_meter =
new SceneGraphAnalyzerMeter(
"scene_graph_analyzer_meter",
get_render().node());
178 _scene_graph_analyzer_meter->setup_window(_window);
189void WindowFramework::
192 _camera_group.remove_node();
193 _render.remove_node();
194 _render_2d.remove_node();
195 _mouse.remove_node();
199 _got_keyboard =
false;
200 _got_trackball =
false;
203 _wireframe_enabled =
false;
204 _texture_enabled =
true;
205 _two_sided_enabled =
false;
206 _one_sided_reverse_enabled =
false;
207 _lighting_enabled =
false;
208 _perpixel_enabled =
false;
210 if (_frame_rate_meter !=
nullptr) {
211 _frame_rate_meter->clear_window();
212 _frame_rate_meter =
nullptr;
214 if (_scene_graph_analyzer_meter !=
nullptr) {
215 _scene_graph_analyzer_meter->clear_window();
216 _scene_graph_analyzer_meter =
nullptr;
226 if (_camera_group.is_empty()) {
229 return _camera_group;
237 if (_render.is_empty()) {
240 _render.node()->set_attrib(RescaleNormalAttrib::make_default());
244 _render.set_two_sided(0);
254 if (_render_2d.is_empty()) {
259 _render_2d.set_depth_write(0);
260 _render_2d.set_depth_test(0);
261 _render_2d.set_material_off(1);
262 _render_2d.set_two_sided(1);
268 PN_stdfloat l, r, b, t;
269 _display_region_3d->get_dimensions(l, r, b, t);
270 _display_region_2d = _window->make_mono_display_region(l, r, b, t);
271 _display_region_2d->set_sort(10);
279 static const PN_stdfloat left = -1.0f;
280 static const PN_stdfloat right = 1.0f;
281 static const PN_stdfloat bottom = -1.0f;
282 static const PN_stdfloat top = 1.0f;
284 lens->set_film_offset((right + left) * 0.5, (top + bottom) * 0.5);
285 lens->set_near_far(-1000, 1000);
287 camera->set_lens(lens);
288 _display_region_2d->set_camera(camera_np);
300 if (_aspect_2d.is_empty()) {
307 if (mouse_node->
is_of_type(MouseWatcher::get_class_type())) {
311 PN_stdfloat this_aspect_ratio = aspect_ratio;
312 if (this_aspect_ratio == 0.0f) {
314 this_aspect_ratio = 1.0f;
316 if (_window->has_size()) {
317 int x_size = _window->get_sbs_left_x_size();
318 int y_size = _window->get_sbs_left_y_size();
320 this_aspect_ratio = (PN_stdfloat)x_size / (PN_stdfloat)y_size;
325 _aspect_2d.set_scale(1.0f / this_aspect_ratio, 1.0f, 1.0f);
338 if (_pixel_2d.is_empty()) {
341 _pixel_2d.set_pos(-1, 0, 1);
343 if (_window->has_size()) {
344 int x_size = _window->get_sbs_left_x_size();
345 int y_size = _window->get_sbs_left_y_size();
347 _pixel_2d.set_sx(2.0f / (
float)x_size);
349 _pixel_2d.set_sy(1.0f);
351 _pixel_2d.set_sz(2.0f / (
float)y_size);
365 if (_mouse.is_empty()) {
366 NodePath mouse = _panda_framework->get_mouse(_window);
378 if (_window->get_side_by_side_stereo()) {
383 mw->set_display_region(_window->get_overlay_display_region());
386 _mouse = mouse.attach_new_node(mw);
397 return _button_thrower;
410 if (_window->is_of_type(GraphicsWindow::get_class_type()) &&
423 bt->set_modifier_buttons(mods);
424 _button_thrower = mouse.attach_new_node(bt);
427 _got_keyboard =
true;
435 if (_got_trackball) {
439 if (_window->is_of_type(GraphicsWindow::get_class_type()) &&
445 _trackball->set_pos(LVector3::forward() * 50.0);
446 mouse.attach_new_node(_trackball);
449 tball2cam->set_node(camera.
node());
450 _trackball->add_child(tball2cam);
453 _got_trackball =
true;
462 if (_trackball ==
nullptr) {
468 nassertv(volume !=
nullptr);
469 nassertv(volume->is_of_type(GeometricBoundingVolume::get_class_type()));
472 if (
object.has_parent()) {
473 CPT(
TransformState) net_transform =
object.get_parent().get_net_transform();
475 new_gbv->xform(net_transform->get_mat());
480 if (gbv->is_infinite()) {
481 framework_cat.warning()
482 <<
"Infinite bounding volume for " <<
object <<
"\n";
486 if (gbv->is_empty()) {
487 framework_cat.warning()
488 <<
"Empty bounding volume for " <<
object <<
"\n";
495 if (!sphere->extend_by(gbv)) {
496 framework_cat.warning()
497 <<
"Cannot determine bounding volume of " <<
object <<
"\n";
501 LPoint3 center = sphere->get_center();
502 PN_stdfloat radius = sphere->get_radius();
504 PN_stdfloat distance = 50.0f;
509 Lens *lens =
nullptr;
510 if (!_cameras.empty()) {
511 Cameras::const_iterator ci;
512 for (ci = _cameras.begin();
513 ci != _cameras.end() && lens ==
nullptr;
515 lens = (*ci)->get_lens();
519 if (lens !=
nullptr) {
520 LVecBase2 fov = lens->
get_fov();
521 distance = radius / ctan(deg_2_rad(std::min(fov[0], fov[1]) / 2.0f));
524 PN_stdfloat ideal_far_plane = distance + radius * 1.5;
528 PN_stdfloat ideal_near_plane = distance - radius;
532 _trackball->set_origin(center);
533 _trackball->set_pos(LVector3::forward() * distance);
537 _trackball->set_forward_scale(distance * 0.006);
549 pvector<Filename> files;
551 for (
int i = first_arg; i < argc && argv[i] !=
nullptr; i++) {
552 files.push_back(Filename::from_os_specific(argv[i]));
568 pvector<Filename>::const_iterator fi;
569 for (fi = files.begin(); fi != files.end(); ++fi) {
586 framework_cat.info() <<
"Loading " << filename <<
"\n";
595 bool is_image =
false;
598 if (extension ==
"pz" || extension ==
"gz") {
605 if (!extension.empty()) {
609 if (model_type ==
nullptr) {
622 options.set_flags(options.get_flags() | LoaderOptions::LF_search);
624 options.set_flags(options.get_flags() & ~LoaderOptions::LF_search);
630 node = load_image_as_model(filename);
632 node = loader.load_sync(filename, options);
637 if (node ==
nullptr && !is_image && model_type ==
nullptr) {
642 if (node ==
nullptr) {
643 nout <<
"Unable to load " << filename <<
"\n";
657 CPT(
RenderState) state = RenderState::make_empty();
663 string rock_floor_string((
const char *)rock_floor, rock_floor_len);
664 istringstream rock_floor_strm(rock_floor_string);
666 if (rock_floor_pnm.
read(rock_floor_strm,
"rock-floor.rgb")) {
668 tex->set_name(
"rock-floor.rgb");
669 tex->load(rock_floor_pnm);
670 tex->set_minfilter(SamplerState::FT_linear);
671 tex->set_magfilter(SamplerState::FT_linear);
684 vertex.
add_data3(LVertex::rfu(0.0, 0.0, 0.0));
685 vertex.
add_data3(LVertex::rfu(1.0, 0.0, 0.0));
686 vertex.
add_data3(LVertex::rfu(0.0, 0.0, 1.0));
697 tri->add_consecutive_vertices(0, 3);
698 tri->close_primitive();
701 geom->add_primitive(tri);
718 _anim_controls.loop_all(
true);
728 for (
int i = 0; i < _anim_controls.get_num_anims(); ++i) {
730 double r = (double)rand() / (double)RAND_MAX;
744 if (_anim_controls_enabled) {
745 destroy_anim_controls();
747 if (_anim_controls.get_num_anims() == 0) {
756 if (_anim_index >= _anim_controls.get_num_anims()) {
758 _anim_controls.loop_all(
true);
760 create_anim_controls();
766 if (_anim_controls.get_num_anims() > 0) {
778 _anim_controls_enabled = enable;
779 if (_anim_controls_enabled) {
780 create_anim_controls();
783 destroy_anim_controls();
795 PN_stdfloat this_aspect_ratio = aspect_ratio;
797 int x_size = 0, y_size = 0;
798 if (_window->has_size()) {
799 x_size = _window->get_sbs_left_x_size();
800 y_size = _window->get_sbs_left_y_size();
803 if (this_aspect_ratio == 0.0f) {
805 this_aspect_ratio = 1.0f;
807 this_aspect_ratio = (float)x_size / (
float)y_size;
811 if (!_aspect_2d.is_empty()) {
812 _aspect_2d.set_scale(1.0f / this_aspect_ratio, 1.0f, 1.0f);
815 if (!_pixel_2d.is_empty()) {
818 _pixel_2d.set_sx(2.0f / (
float)x_size);
820 _pixel_2d.set_sy(1.0f);
822 _pixel_2d.set_sz(2.0f / (
float)y_size);
826 Cameras::iterator ci;
827 for (ci = _cameras.begin(); ci != _cameras.end(); ++ci) {
828 Lens *lens = (*ci)->get_lens();
829 if (lens !=
nullptr) {
849 if (split_type == ST_default) {
853 if (_display_region_3d->get_pixel_width() >
854 _display_region_3d->get_pixel_height()) {
855 split_type = ST_horizontal;
857 split_type = ST_vertical;
861 PN_stdfloat left, right, bottom, top;
863 new_region = _display_region_3d->
get_window()->make_display_region();
865 if (split_type == ST_vertical) {
866 _display_region_3d->set_dimensions(left, right, bottom, (top + bottom) / 2.0f);
867 if (_display_region_2d !=
nullptr) {
868 _display_region_2d->set_dimensions(left, right, bottom, (top + bottom) / 2.0f);
871 new_region->
set_dimensions(left, right, (top + bottom) / 2.0f, top);
874 _display_region_3d->set_dimensions(left, (left + right) / 2.0f, bottom, top);
875 if (_display_region_2d !=
nullptr) {
876 _display_region_2d->set_dimensions(left, (left + right) / 2.0f, bottom, top);
879 new_region->
set_dimensions((left + right) / 2.0f, right, bottom, top);
882 PT(WindowFramework) wf =
new WindowFramework(*
this, new_region);
883 _panda_framework->_windows.push_back(wf);
893 if (enable == _wireframe_enabled && filled == _wireframe_filled) {
899 if (!_two_sided_enabled) {
906 RenderModeAttrib::M_filled_wireframe,
907 1.4f,
false, LColor(1, 1, 1, .5f)),
911 render.
set_color_scale(LColor(0.7f, 0.7f, 0.7f, 1), override_priority);
919 if (_one_sided_reverse_enabled) {
926 _wireframe_enabled = enable;
927 _wireframe_filled = filled;
935 if (enable == _texture_enabled) {
947 _texture_enabled = enable;
955 if (enable == _two_sided_enabled) {
964 if (!_wireframe_enabled) {
969 _two_sided_enabled = enable;
970 _one_sided_reverse_enabled =
false;
979 if (enable == _one_sided_reverse_enabled) {
985 if (!_wireframe_enabled) {
994 _two_sided_enabled =
false;
995 _one_sided_reverse_enabled = enable;
1003 if (enable == _lighting_enabled) {
1019 _lighting_enabled = enable;
1027 if (enable == _perpixel_enabled) {
1034 render.set_shader_auto();
1036 render.set_shader_off();
1039 _perpixel_enabled = enable;
1049 _background_type = type;
1051 if (_display_region_3d ==
nullptr) {
1055 switch (_background_type) {
1060 _display_region_3d->set_clear_color_active(
true);
1061 _display_region_3d->set_clear_depth_active(
true);
1062 _display_region_3d->set_clear_stencil_active(
true);
1063 _display_region_3d->set_clear_color(_window->get_clear_color());
1064 _display_region_3d->set_clear_depth(_window->get_clear_depth());
1065 _display_region_3d->set_clear_stencil(_window->get_clear_stencil());
1069 _display_region_3d->set_clear_color_active(
true);
1070 _display_region_3d->set_clear_depth_active(
true);
1071 _display_region_3d->set_clear_stencil_active(
true);
1072 _display_region_3d->set_clear_color(LColor(0.0f, 0.0f, 0.0f, 0.0f));
1073 _display_region_3d->set_clear_depth(1.0f);
1074 _display_region_3d->set_clear_stencil(0);
1078 _display_region_3d->set_clear_color_active(
true);
1079 _display_region_3d->set_clear_depth_active(
true);
1080 _display_region_3d->set_clear_stencil_active(
true);
1081 _display_region_3d->set_clear_color(LColor(0.3, 0.3, 0.3, 0.0f));
1082 _display_region_3d->set_clear_depth(1.0f);
1083 _display_region_3d->set_clear_stencil(0);
1087 _display_region_3d->set_clear_color_active(
true);
1088 _display_region_3d->set_clear_depth_active(
true);
1089 _display_region_3d->set_clear_stencil_active(
true);
1090 _display_region_3d->set_clear_color(LColor(1.0f, 1.0f, 1.0f, 0.0f));
1091 _display_region_3d->set_clear_depth(1.0f);
1092 _display_region_3d->set_clear_stencil(0);
1096 _display_region_3d->set_clear_color_active(
false);
1097 _display_region_3d->set_clear_depth_active(
false);
1098 _display_region_3d->set_clear_stencil_active(
false);
1108 if (_shuttle_controls_font ==
nullptr) {
1111 string shuttle_controls_string((
const char *)shuttle_controls, shuttle_controls_len);
1112 istringstream in(shuttle_controls_string);
1114 if (bam_file.
open_read(in,
"shuttle_controls font stream")) {
1116 if (node !=
nullptr) {
1122 return _shuttle_controls_font;
1133 _cameras.push_back(camera);
1137 if (aspect_ratio != 0.0) {
1139 lens->set_aspect_ratio(aspect_ratio);
1144 if (_window->has_size()) {
1145 int x_size = _window->get_sbs_left_x_size();
1146 int y_size = _window->get_sbs_left_y_size();
1148 lens->set_film_size(x_size, y_size);
1153 camera->set_lens(lens);
1161void WindowFramework::
1170 AmbientLight *alight =
new AmbientLight(
"ambient");
1171 alight->
set_color(LColor(0.2, 0.2, 0.2, 1.0f));
1172 DirectionalLight *dlight =
new DirectionalLight(
"directional");
1173 dlight->
set_color(LColor(0.8f, 0.8f, 0.8f, 1.0f));
1187load_image_as_model(
const Filename &filename) {
1189 if (tex ==
nullptr) {
1194 tex->set_minfilter(SamplerState::FT_linear_mipmap_linear);
1195 tex->set_magfilter(SamplerState::FT_linear);
1196 tex->set_wrap_u(SamplerState::WM_clamp);
1197 tex->set_wrap_v(SamplerState::WM_clamp);
1198 tex->set_wrap_w(SamplerState::WM_clamp);
1201 bool has_alpha =
true;
1202 LVecBase2 tex_scale = tex->get_tex_scale();
1206 int x_size = tex->get_orig_file_x_size();
1207 int y_size = tex->get_orig_file_y_size();
1210 PN_stdfloat left,right,top,bottom;
1211 static const PN_stdfloat scale = 10.0;
1212 if (x_size > y_size) {
1215 top = (scale * y_size) / x_size;
1216 bottom = -(scale * y_size) / x_size;
1217 }
else if (y_size != 0) {
1218 left = -(scale * x_size) / y_size;
1219 right = (scale * x_size) / y_size;
1223 framework_cat.warning()
1224 <<
"Texture size is 0 0: " << *tex <<
"\n";
1232 PT(GeomNode) card_node =
new GeomNode(
"card");
1239 if (tex->get_texture_type() == Texture::TT_3d_texture ||
1240 tex->get_texture_type() == Texture::TT_cube_map) {
1245 CPT(GeomVertexFormat) vformat;
1252 vformat = GeomVertexFormat::register_format
1253 (
new GeomVertexArrayFormat
1254 (InternalName::get_vertex(), 3,
1255 GeomEnums::NT_stdfloat, GeomEnums::C_point,
1256 InternalName::get_texcoord(), 3,
1257 GeomEnums::NT_stdfloat, GeomEnums::C_texcoord));
1260 PT(GeomVertexData) vdata =
new GeomVertexData
1261 (
"card", vformat, Geom::UH_static);
1262 GeomVertexWriter vertex(vdata, InternalName::get_vertex());
1263 GeomVertexWriter texcoord(vdata, InternalName::get_texcoord());
1267 vertex.add_data3(LVertex::rfu(left, 0.02, top));
1268 vertex.add_data3(LVertex::rfu(left, 0.02, bottom));
1269 vertex.add_data3(LVertex::rfu(right, 0.02, top));
1270 vertex.add_data3(LVertex::rfu(right, 0.02, bottom));
1272 texcoord.add_data2(0.0f, tex_scale[1]);
1273 texcoord.add_data2(0.0f, 0.0f);
1274 texcoord.add_data2(tex_scale[0], tex_scale[1]);
1275 texcoord.add_data2(tex_scale[0], 0.0f);
1279 vertex.add_data3(-1.0f, -1.0f, 1.0f);
1280 vertex.add_data3(-1.0f, -1.0f, -1.0f);
1281 vertex.add_data3(1.0f, -1.0f, -1.0f);
1282 vertex.add_data3(1.0f, -1.0f, 1.0f);
1283 vertex.add_data3(1.0f, 1.0f, 1.0f);
1284 vertex.add_data3(1.0f, 1.0f, -1.0f);
1285 vertex.add_data3(-1.0f, 1.0f, -1.0f);
1286 vertex.add_data3(-1.0f, 1.0f, 1.0f);
1288 texcoord.add_data3(-1.0f, -1.0f, 1.0f);
1289 texcoord.add_data3(-1.0f, -1.0f, -1.0f);
1290 texcoord.add_data3(1.0f, -1.0f, -1.0f);
1291 texcoord.add_data3(1.0f, -1.0f, 1.0f);
1292 texcoord.add_data3(1.0f, 1.0f, 1.0f);
1293 texcoord.add_data3(1.0f, 1.0f, -1.0f);
1294 texcoord.add_data3(-1.0f, 1.0f, -1.0f);
1295 texcoord.add_data3(-1.0f, 1.0f, 1.0f);
1298 PT(GeomTristrips) strip =
new GeomTristrips(Geom::UH_static);
1302 strip->add_consecutive_vertices(0, 4);
1303 strip->close_primitive();
1307 strip->add_vertex(7);
1308 strip->add_vertex(0);
1309 strip->add_vertex(4);
1310 strip->add_vertex(3);
1311 strip->close_primitive();
1313 strip->add_vertex(1);
1314 strip->add_vertex(6);
1315 strip->add_vertex(2);
1316 strip->add_vertex(5);
1317 strip->close_primitive();
1319 strip->add_vertex(5);
1320 strip->add_vertex(4);
1321 strip->add_vertex(2);
1322 strip->add_vertex(3);
1323 strip->add_vertex(1);
1324 strip->add_vertex(0);
1325 strip->add_vertex(6);
1326 strip->add_vertex(7);
1327 strip->add_vertex(5);
1328 strip->add_vertex(4);
1329 strip->close_primitive();
1332 PT(Geom) geom =
new Geom(vdata);
1333 geom->add_primitive(strip);
1335 card_node->add_geom(geom);
1344void WindowFramework::
1345create_anim_controls() {
1346 destroy_anim_controls();
1348 PT(PGItem) group =
new PGItem(
"anim_controls_group");
1350 style.
set_type(PGFrameStyle::T_flat);
1352 group->set_frame(-1.0f, 1.0f, 0.0f, 0.2);
1353 group->set_frame_style(0, style);
1354 group->set_suppress_flags(MouseWatcherRegion::SF_mouse_button);
1355 group->set_active(
true);
1358 _anim_controls_group.set_pos(0.0f, 0.0f, -0.9f);
1360 if (_anim_index >= _anim_controls.get_num_anims()) {
1361 PT(TextNode) label =
new TextNode(
"label");
1362 label->set_align(TextNode::A_center);
1363 label->set_text(
"No animation.");
1364 NodePath tnp = _anim_controls_group.attach_new_node(label);
1365 tnp.set_pos(0.0f, 0.0f, 0.07f);
1371 AnimControl *control = _anim_controls.get_anim(_anim_index);
1372 nassertv(control !=
nullptr);
1377 text << _anim_controls.get_anim_name(_anim_index);
1381 PT(TextNode) label =
new TextNode(
"label");
1382 label->set_align(TextNode::A_center);
1383 label->set_text(text.str());
1385 tnp.set_pos(0.0f, 0.0f, 0.07f);
1391 PT(TextNode) label =
new TextNode(
"anim_name");
1392 label->set_align(TextNode::A_left);
1393 label->set_text(_anim_controls.get_anim_name(_anim_index));
1395 tnp.set_pos(-0.95f, 0.0f, 0.15f);
1398 _anim_slider =
new PGSliderBar(
"anim_slider");
1399 _anim_slider->setup_slider(
false, 1.9f, 0.1f, 0.005f);
1400 _anim_slider->set_suppress_flags(MouseWatcherRegion::SF_mouse_button);
1401 _anim_slider->get_thumb_button()->set_suppress_flags(MouseWatcherRegion::SF_mouse_button);
1403 _anim_slider->set_range(0.0f, (PN_stdfloat)(control->
get_num_frames() - 1));
1404 _anim_slider->set_scroll_size(0.0f);
1405 _anim_slider->set_page_size(1.0f);
1406 NodePath snp = _anim_controls_group.attach_new_node(_anim_slider);
1407 snp.set_pos(0.0f, 0.0f, 0.06f);
1409 _frame_number =
new TextNode(
"frame_number");
1410 _frame_number->set_text_color(0.0f, 0.0f, 0.0f, 1.0f);
1411 _frame_number->set_align(TextNode::A_center);
1412 _frame_number->set_text(format_string(control->
get_frame()));
1413 NodePath fnp = NodePath(_anim_slider->get_thumb_button()).attach_new_node(_frame_number);
1415 fnp.set_pos(0.0f, 0.0f, -0.01f);
1417 _play_rate_slider =
new PGSliderBar(
"play_rate_slider");
1418 _play_rate_slider->setup_slider(
false, 0.4, 0.05f, 0.005f);
1419 _play_rate_slider->set_suppress_flags(MouseWatcherRegion::SF_mouse_button);
1420 _play_rate_slider->get_thumb_button()->set_suppress_flags(MouseWatcherRegion::SF_mouse_button);
1422 NodePath pnp = _anim_controls_group.attach_new_node(_play_rate_slider);
1423 pnp.set_pos(0.75f, 0.0f, 0.15f);
1427 setup_shuttle_button(
"9", 0, st_back_button);
1428 setup_shuttle_button(
";", 1, st_pause_button);
1429 setup_shuttle_button(
"4", 2, st_play_button);
1430 setup_shuttle_button(
":", 3, st_forward_button);
1432 _update_anim_controls_task =
new GenericAsyncTask(
"controls", st_update_anim_controls, (
void *)
this);
1433 _panda_framework->get_task_mgr().add(_update_anim_controls_task);
1439void WindowFramework::
1440destroy_anim_controls() {
1441 if (!_anim_controls_group.is_empty()) {
1442 _anim_controls_group.remove_node();
1444 _panda_framework->get_event_handler().remove_hooks_with((
void *)
this);
1445 if (_update_anim_controls_task !=
nullptr) {
1446 _panda_framework->get_task_mgr().remove(_update_anim_controls_task);
1447 _update_anim_controls_task.clear();
1455void WindowFramework::
1456update_anim_controls() {
1457 AnimControl *control = _anim_controls.
get_anim(_anim_index);
1458 nassertv(control !=
nullptr);
1460 if (_anim_slider !=
nullptr) {
1461 if (_anim_slider->is_button_down()) {
1462 control->
pose((
int)(_anim_slider->get_value() + 0.5));
1464 _anim_slider->set_value((PN_stdfloat)control->
get_frame());
1468 if (_frame_number !=
nullptr) {
1469 _frame_number->set_text(format_string(control->
get_frame()));
1479void WindowFramework::
1480setup_shuttle_button(
const string &label,
int index,
1481 EventHandler::EventCallbackFunction *func) {
1482 PT(PGButton) button =
new PGButton(label);
1483 button->set_frame(-0.05f, 0.05f, 0.0f, 0.07f);
1485 PN_stdfloat bevel = 0.005f;
1488 style.
set_color(0.8f, 0.8f, 0.8f, 1.0f);
1491 style.
set_type(PGFrameStyle::T_bevel_out);
1492 button->set_frame_style(PGButton::S_ready, style);
1494 style.
set_type(PGFrameStyle::T_bevel_in);
1495 button->set_frame_style(PGButton::S_depressed, style);
1497 style.
set_color(0.9f, 0.9f, 0.9f, 1.0f);
1498 style.
set_type(PGFrameStyle::T_bevel_out);
1499 button->set_frame_style(PGButton::S_rollover, style);
1502 PT(TextNode) tn =
new TextNode(
"label");
1503 tn->set_align(TextNode::A_center);
1505 tn->set_text(label);
1506 tn->set_text_color(0.0f, 0.0f, 0.0f, 1.0f);
1507 LMatrix4 xform = LMatrix4::scale_mat(0.07f);
1508 xform.set_row(3, LVecBase3(0.0f, 0.0f, 0.016f));
1509 tn->set_transform(xform);
1511 button->get_state_def(PGButton::S_ready).attach_new_node(tn);
1512 button->get_state_def(PGButton::S_depressed).attach_new_node(tn);
1513 button->get_state_def(PGButton::S_rollover).attach_new_node(tn);
1516 NodePath np = _anim_controls_group.attach_new_node(button);
1517 np.set_pos(0.1f * index - 0.15f, 0.0f, 0.12);
1519 _panda_framework->get_event_handler().add_hook(button->get_click_event(
MouseButton::one()), func, (
void *)
this);
1525void WindowFramework::
1527 AnimControl *control = _anim_controls.
get_anim(_anim_index);
1528 nassertv(control !=
nullptr);
1535void WindowFramework::
1537 AnimControl *control = _anim_controls.
get_anim(_anim_index);
1538 nassertv(control !=
nullptr);
1545void WindowFramework::
1547 AnimControl *control = _anim_controls.
get_anim(_anim_index);
1548 nassertv(control !=
nullptr);
1549 control->
loop(
false);
1555void WindowFramework::
1557 AnimControl *control = _anim_controls.
get_anim(_anim_index);
1558 nassertv(control !=
nullptr);
1566AsyncTask::DoneStatus WindowFramework::
1568 WindowFramework *self = (WindowFramework *)data;
1569 self->update_anim_controls();
1570 return AsyncTask::DS_cont;
1577void WindowFramework::
1578st_back_button(
const Event *,
void *data) {
1579 WindowFramework *self = (WindowFramework *)data;
1580 self->back_button();
1586void WindowFramework::
1587st_pause_button(
const Event *,
void *data) {
1588 WindowFramework *self = (WindowFramework *)data;
1589 self->pause_button();
1595void WindowFramework::
1596st_play_button(
const Event *,
void *data) {
1597 WindowFramework *self = (WindowFramework *)data;
1598 self->play_button();
1604void WindowFramework::
1605st_forward_button(
const Event *,
void *data) {
1606 WindowFramework *self = (WindowFramework *)data;
1607 self->forward_button();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void auto_bind(PandaNode *root_node, AnimControlCollection &controls, int hierarchy_match_flags)
Walks the scene graph or subgraph beginning at the indicated node, and attempts to bind any AnimBundl...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Controls the timing of a character animation.
AnimBundle * get_anim() const
Returns the AnimBundle bound in with this AnimControl.
void pose(double frame)
Sets the animation to the indicated frame and holds it there.
set_play_rate
Changes the rate at which the animation plays.
get_frame
Returns the current integer frame number.
get_num_frames
Returns the number of frames in the animation.
get_play_rate
Returns the rate at which the animation plays.
void stop()
Stops a currently playing or looping animation right where it is.
void loop(bool restart)
Starts the entire animation looping.
The principle public interface to reading and writing Bam disk files.
PointerTo< PandaNode > read_node(bool report_errors=true)
Although the bam file format is general enough to store a list of objects of arbitrary type,...
bool open_read(const Filename &bam_filename, bool report_errors=true)
Attempts to open the indicated filename for reading.
This defines a bounding sphere, consisting of a center and a radius.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
static ConstPointerTo< RenderAttrib > make_flat(const LColor &color)
Constructs a new ColorAttrib object that indicates geometry should be rendered in the indicated color...
static ConstPointerTo< RenderAttrib > make_reverse()
Constructs a new CullFaceAttrib object that reverses the effects of any other CullFaceAttrib objects ...
A rectangular subregion within a window for rendering into.
get_dimensions
Retrieves the coordinates of the DisplayRegion's rectangle within its GraphicsOutput.
get_window
Returns the GraphicsOutput that this DisplayRegion is ultimately associated with, or NULL if no windo...
set_dimensions
Changes the portion of the framebuffer this DisplayRegion corresponds to.
void set_clear_color_active(bool clear_color_active)
Toggles the flag that indicates whether the color buffer should be cleared every frame.
An optional parameter associated with an event.
A named event, possibly with parameters.
The name of a file, such as a texture file or an Egg file.
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
std::string get_extension() const
Returns the file extension.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
Associates a generic C-style function pointer with an AsyncTask object.
A node that holds Geom objects, renderable pieces of geometry.
void add_geom(Geom *geom, const RenderState *state=RenderState::make_empty())
Adds a new Geom to the node.
Defines a series of disconnected triangles.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void add_data2(PN_stdfloat x, PN_stdfloat y)
Sets the write row to a particular 2-component value, and advances the write row.
void add_data3(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Sets the write row to a particular 3-component value, and advances the write row.
A container for geometry primitives.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
This class is the main interface to controlling the render process.
GraphicsOutput * make_output(GraphicsPipe *pipe, const std::string &name, int sort, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg=nullptr, GraphicsOutput *host=nullptr)
Creates a new window (or buffer) and returns it.
This is a base class for the various different classes that represent the result of a frame of render...
DisplayRegion * make_display_region()
Creates a new DisplayRegion that covers the entire window.
virtual void clear(Thread *current_thread)
Clears the entire framebuffer before rendering, according to the settings of get_color_clear_active()...
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
A base class for any number of different kinds of lenses, linear and otherwise.
set_aspect_ratio
Sets the aspect ratio of the lens.
static PN_stdfloat get_default_near()
Returns the default near plane distance that will be assigned to each newly-created lens.
static PN_stdfloat get_default_far()
Returns the default far plane distance that will be assigned to each newly- created lens.
set_near
Defines the position of the near plane (or cylinder, sphere, whatever).
get_fov
Returns the horizontal and vertical film size of the virtual film.
set_film_size
Sets the horizontal size of the film without changing its shape.
set_far
Defines the position of the far plane (or cylinder, sphere, whatever).
set_color
Sets the basic color of the light.
This class maintains the set of all known LoaderFileTypes in the universe.
static LoaderFileTypeRegistry * get_global_ptr()
Returns a pointer to the global LoaderFileTypeRegistry object.
LoaderFileType * get_type_from_extension(const std::string &extension)
Determines the type of the file based on the indicated extension (without a leading dot).
This is the base class for a family of scene-graph file types that the Loader supports.
Specifies parameters that may be passed to the loader.
A convenient class for loading models from disk, in bam or egg format (or any of a number of other fo...
This TFormer maintains a list of rectangular regions on the screen that are considered special mouse ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
void set_light(const NodePath &light, int priority=0)
Adds the indicated Light or PolylightNode to the list of lights that illuminate geometry at this node...
void clear_two_sided()
Completely removes any two-sided adjustment that may have been set on this node via set_two_sided().
static NodePath not_found()
Creates a NodePath with the ET_not_found error type set.
bool is_empty() const
Returns true if the NodePath contains no nodes.
void clear_light()
Completely removes any lighting operations that may have been set via set_light() or set_light_off() ...
PandaNode * node() const
Returns the referenced node of the path.
void clear_texture()
Completely removes any texture adjustment that may have been set via set_texture() or set_texture_off...
void clear_render_mode()
Completely removes any render mode adjustment that may have been set on this node via set_render_mode...
void set_texture_off(int priority=0)
Sets the geometry at this level and below to render using no texture, on any stage.
PointerTo< BoundingVolume > get_bounds(Thread *current_thread=Thread::get_current_thread()) const
Returns a newly-allocated bounding volume containing the bottom node and all of its descendants.
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
void set_scale(PN_stdfloat scale)
Sets the scale component of the transform, leaving translation and rotation untouched.
void set_two_sided(bool two_sided, int priority=0)
Specifically sets or disables two-sided rendering mode on this particular node.
void set_render_mode_wireframe(int priority=0)
Sets up the geometry at this level and below (unless overridden) to render in wireframe mode.
void clear_color_scale()
Completely removes any color scale from the referenced node.
void set_hpr(PN_stdfloat h, PN_stdfloat p, PN_stdfloat r)
Sets the rotation component of the transform, leaving translation and scale untouched.
void set_color_scale(const LVecBase4 &scale, int priority=0)
Sets the color scale component of the transform, leaving translation and rotation untouched.
void set_type(Type type)
Sets the basic type of frame.
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a)
Sets the dominant color of the frame.
void set_width(PN_stdfloat x, PN_stdfloat y)
Sets the width parameter, which has meaning only for certain frame types.
The "top" node of the new Panda GUI system.
void set_mouse_watcher(MouseWatcher *watcher)
Sets the MouseWatcher pointer that the PGTop object registers its PG items with.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
bool read(const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
Reads the indicated image filename.
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
A basic node of the scene graph or data graph.
void set_attrib(const RenderAttrib *attrib, int override=0)
Adds the indicated render attribute to the scene graph on this node.
A perspective-type lens: a normal camera.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
static ConstPointerTo< RenderAttrib > make(Mode mode, PN_stdfloat thickness=1.0f, bool perspective=false, const LColor &wireframe_color=LColor::zero())
Constructs a new RenderModeAttrib object that specifies whether to draw polygons in the normal,...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new ShadeModelAttrib object that specifies whether to draw polygons with flat shading or...
A StaticTextFont is loaded up from a model that was previously generated via egg-mkfont,...
An encapsulation of a font; i.e.
static ConstPointerTo< RenderAttrib > make(Texture *tex)
Constructs a new TextureAttrib object suitable for rendering the indicated texture onto geometry,...
static ConstPointerTo< RenderAttrib > make()
Constructs a new TextureAttrib object that does nothing.
This is the preferred interface for loading textures from image files.
static Texture * load_texture(const Filename &filename, int primary_file_num_channels=0, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions())
Loads the given filename up into a texture, if it has not already been loaded, and returns the new te...
static TexturePool * get_global_ptr()
Initializes and/or returns the global pointer to the one TexturePool object in the system.
void write_texture_types(std::ostream &out, int indent_level) const
Outputs a list of the available texture types to the indicated output stream.
MakeTextureFunc * get_texture_type(const std::string &extension) const
Returns the factory function to construct a new texture of the type appropriate for the indicated fil...
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Trackball acts like Performer in trackball mode.
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new TransparencyAttrib object.
TypeHandle is the identifier used to differentiate C++ class types.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
A hierarchy of directories and files that appears to be one continuous file system,...
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
This encapsulates the data that is normally associated with a single window, or with a single display...
void set_wireframe(bool enable, bool filled=false)
Forces wireframe state (true) or restores default rendering (false).
NodePath make_camera()
Makes a new 3-d camera for the window.
NodePath load_default_model(const NodePath &parent)
Loads our favorite blue triangle.
void setup_trackball()
Sets up the mouse to trackball around the camera.
NodePath get_aspect_2d()
Returns the node under the 2-d scene graph that is scaled to suit the window's aspect ratio.
WindowFramework * split_window(SplitType split_type=ST_default)
Divides the window into two display regions, each of which gets its own trackball and keyboard events...
void stagger_animations()
Walks through all the animations that were bound by loop_animations() and staggers their play rate sl...
NodePath get_button_thrower()
Returns the node in the data graph corresponding to the ButtonThrower object associated with this win...
void set_one_sided_reverse(bool enable)
Toggles one-sided reverse mode.
NodePath get_render_2d()
Returns the root of the 2-d scene graph.
void loop_animations(int hierarchy_match_flags=PartGroup::HMF_ok_part_extra|PartGroup::HMF_ok_anim_extra)
Looks for characters and their matching animation files in the scene graph; binds and loops any match...
void set_two_sided(bool enable)
Forces two-sided rendering (true) or restores default rendering (false).
void set_texture(bool enable)
Forces textures off (false) or restores default rendering (true).
void next_anim_control()
Rotates the animation controls through all of the available animations.
void enable_keyboard()
Creates a ButtonThrower to listen to button presses and throw them as events.
NodePath get_render()
Returns the root of the 3-d scene graph.
void center_trackball(const NodePath &object)
Centers the trackball on the indicated object, and scales the trackball motion suitably.
NodePath get_mouse()
Returns the node in the data graph corresponding to the mouse associated with this window.
void set_anim_controls(bool enable)
Creates an onscreen animation slider for frame-stepping through the animations.
void adjust_dimensions()
Reevaluates the dimensions of the window, presumably after the window has been resized by the user or...
bool load_models(const NodePath &parent, int argc, char *argv[], int first_arg=1)
Loads up all the model files listed in the indicated argument list.
NodePath get_camera_group()
Returns the node above the collection of 3-d cameras in the scene graph.
void set_background_type(BackgroundType type)
Sets the background of the window to one of the pre-canned background types (or to BT_other,...
NodePath get_pixel_2d()
Returns a special root that uses units in pixels that are relative to the window.
static TextFont * get_shuttle_controls_font()
Returns a font that contains the shuttle controls icons.
void set_lighting(bool enable)
Turns lighting on (true) or off (false).
void set_perpixel(bool enable)
Turns per-pixel lighting on (true) or off (false).
NodePath load_model(const NodePath &parent, Filename filename)
Loads up the indicated model and returns the new NodePath, or the empty NodePath if the model could n...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.