From 4551aa04a7705fdfd7c8af0f81bd32678556832c Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 2 Jul 2002 21:05:10 +0000 Subject: [PATCH] shift-C reveals collision solids --- panda/src/framework/pandaFramework.cxx | 74 ++++++++++++++++++++++++++ panda/src/framework/pandaFramework.h | 4 ++ 2 files changed, 78 insertions(+) diff --git a/panda/src/framework/pandaFramework.cxx b/panda/src/framework/pandaFramework.cxx index 8f289d2527..232ee4b672 100644 --- a/panda/src/framework/pandaFramework.cxx +++ b/panda/src/framework/pandaFramework.cxx @@ -22,6 +22,7 @@ #include "eventQueue.h" #include "dataGraphTraverser.h" #include "interactiveGraphicsPipe.h" +#include "collisionNode.h" #include "config_framework.h" //////////////////////////////////////////////////////////////////// @@ -356,6 +357,58 @@ set_lighting(bool enable) { _lighting_enabled = enable; } +//////////////////////////////////////////////////////////////////// +// Function: PandaFramework::hide_collision_solids +// Access: Public +// Description: Hides any collision solids which are visible in the +// indicated scene graph. Returns the number of +// collision solids hidden. +//////////////////////////////////////////////////////////////////// +int PandaFramework:: +hide_collision_solids(NodePath node) { + int num_changed = 0; + + if (node.node()->is_of_type(CollisionNode::get_class_type())) { + if (!node.is_hidden()) { + node.hide(); + num_changed++; + } + } + + int num_children = node.get_num_children(); + for (int i = 0; i < num_children; i++) { + num_changed += hide_collision_solids(node.get_child(i)); + } + + return num_changed; +} + +//////////////////////////////////////////////////////////////////// +// Function: PandaFramework::show_collision_solids +// Access: Public +// Description: Shows any collision solids which are directly hidden +// in the indicated scene graph. Returns the number of +// collision solids shown. +//////////////////////////////////////////////////////////////////// +int PandaFramework:: +show_collision_solids(NodePath node) { + int num_changed = 0; + + if (node.node()->is_of_type(CollisionNode::get_class_type())) { + if (node.get_hidden_ancestor() == node) { + node.show(); + num_changed++; + } + } + + int num_children = node.get_num_children(); + for (int i = 0; i < num_children; i++) { + num_changed += show_collision_solids(node.get_child(i)); + } + + return num_changed; +} + //////////////////////////////////////////////////////////////////// // Function: PandaFramework::set_highlight // Access: Public @@ -488,6 +541,7 @@ do_enable_default_keys() { _event_handler.add_hook("b", event_b, this); _event_handler.add_hook("l", event_l, this); _event_handler.add_hook("c", event_c, this); + _event_handler.add_hook("shift-c", event_C, this); _event_handler.add_hook("shift-l", event_L, this); _event_handler.add_hook("h", event_h, this); _event_handler.add_hook("arrow_up", event_arrow_up, this); @@ -589,6 +643,26 @@ event_c(CPT_Event, void *data) { } } +//////////////////////////////////////////////////////////////////// +// Function: PandaFramework::event_C +// Access: Protected, Static +// Description: Default handler for shift-C key: toggle the showing +// of collision solids. +//////////////////////////////////////////////////////////////////// +void PandaFramework:: +event_C(CPT_Event, void *data) { + PandaFramework *self = (PandaFramework *)data; + + NodePath node = self->get_highlight(); + if (node.is_empty()) { + node = self->get_models(); + } + + if (self->hide_collision_solids(node) == 0) { + self->show_collision_solids(node); + } +} + //////////////////////////////////////////////////////////////////// // Function: PandaFramework::event_L // Access: Protected, Static diff --git a/panda/src/framework/pandaFramework.h b/panda/src/framework/pandaFramework.h index dd0c1a20b5..218ee3dae2 100644 --- a/panda/src/framework/pandaFramework.h +++ b/panda/src/framework/pandaFramework.h @@ -78,6 +78,9 @@ public: INLINE bool get_two_sided() const; INLINE bool get_lighting() const; + static int hide_collision_solids(NodePath node); + static int show_collision_solids(NodePath node); + void set_highlight(const NodePath &node); void clear_highlight(); INLINE bool has_highlight() const; @@ -102,6 +105,7 @@ protected: static void event_b(CPT_Event, void *data); static void event_l(CPT_Event, void *data); static void event_c(CPT_Event, void *data); + static void event_C(CPT_Event, void *data); static void event_L(CPT_Event, void *data); static void event_h(CPT_Event, void *data); static void event_arrow_up(CPT_Event, void *data);