diff --git a/panda/src/collide/collisionHandlerQueue.cxx b/panda/src/collide/collisionHandlerQueue.cxx index b31b4ac7d6..85a0feb40c 100644 --- a/panda/src/collide/collisionHandlerQueue.cxx +++ b/panda/src/collide/collisionHandlerQueue.cxx @@ -18,6 +18,7 @@ #include "collisionHandlerQueue.h" #include "config_collide.h" +#include "indent.h" TypeHandle CollisionHandlerQueue::_type_handle; @@ -41,7 +42,7 @@ public: //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::Constructor -// Access: Public +// Access: Published // Description: //////////////////////////////////////////////////////////////////// CollisionHandlerQueue:: @@ -50,7 +51,7 @@ CollisionHandlerQueue() { //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::begin_group -// Access: Public, Virtual +// Access: Published, Virtual // Description: Will be called by the CollisionTraverser before a new // traversal is begun. It instructs the handler to // reset itself in preparation for a number of @@ -63,7 +64,7 @@ begin_group() { //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::add_entry -// Access: Public, Virtual +// Access: Published, Virtual // Description: Called between a begin_group() .. end_group() // sequence for each collision that is detected. //////////////////////////////////////////////////////////////////// @@ -75,7 +76,7 @@ add_entry(CollisionEntry *entry) { //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::sort_entries -// Access: Public +// Access: Published // Description: Sorts all the detected collisions front-to-back by // from_intersection_point() so that those intersection // points closest to the collider's origin (e.g., the @@ -113,7 +114,7 @@ sort_entries() { //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::clear_entries -// Access: Public +// Access: Published // Description: Removes all the entries from the queue. //////////////////////////////////////////////////////////////////// void CollisionHandlerQueue:: @@ -123,7 +124,7 @@ clear_entries() { //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::get_num_entries -// Access: Public +// Access: Published // Description: Returns the number of CollisionEntries detected last // pass. //////////////////////////////////////////////////////////////////// @@ -134,7 +135,7 @@ get_num_entries() const { //////////////////////////////////////////////////////////////////// // Function: CollisionHandlerQueue::get_entry -// Access: Public +// Access: Published // Description: Returns the nth CollisionEntry detected last pass. //////////////////////////////////////////////////////////////////// CollisionEntry *CollisionHandlerQueue:: @@ -142,3 +143,29 @@ get_entry(int n) const { nassertr(n >= 0 && n < (int)_entries.size(), NULL); return _entries[n]; } + +//////////////////////////////////////////////////////////////////// +// Function: CollisionHandlerQueue::output +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void CollisionHandlerQueue:: +output(ostream &out) const { + out << "CollisionHandlerQueue, " << _entries.size() << " entries"; +} + +//////////////////////////////////////////////////////////////////// +// Function: CollisionHandlerQueue::write +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void CollisionHandlerQueue:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << "CollisionHandlerQueue, " << _entries.size() << " entries:\n"; + + Entries::const_iterator ei; + for (ei = _entries.begin(); ei != _entries.end(); ++ei) { + (*ei)->write(out, indent_level + 2); + } +} diff --git a/panda/src/collide/collisionHandlerQueue.h b/panda/src/collide/collisionHandlerQueue.h index 22b328baca..949b427ecf 100644 --- a/panda/src/collide/collisionHandlerQueue.h +++ b/panda/src/collide/collisionHandlerQueue.h @@ -48,6 +48,9 @@ PUBLISHED: int get_num_entries() const; CollisionEntry *get_entry(int n) const; + void output(ostream &out) const; + void write(ostream &out, int indent_level = 0) const; + private: typedef pvector< PT(CollisionEntry) > Entries; Entries _entries; @@ -70,6 +73,11 @@ private: static TypeHandle _type_handle; }; +INLINE ostream &operator << (ostream &out, const CollisionHandlerQueue &chq) { + chq.output(out); + return out; +} + #endif diff --git a/panda/src/collide/collisionRecorder.I b/panda/src/collide/collisionRecorder.I index dc847fba17..dff35042ab 100644 --- a/panda/src/collide/collisionRecorder.I +++ b/panda/src/collide/collisionRecorder.I @@ -16,15 +16,3 @@ // //////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CollisionRecorder::get_type_index -// Access: Published -// Description: Duplicates the functionality of -// TypedObject::get_type_index(). -//////////////////////////////////////////////////////////////////// -INLINE int CollisionRecorder:: -get_type_index() const { - return get_type().get_index(); -} - diff --git a/panda/src/collide/collisionRecorder.h b/panda/src/collide/collisionRecorder.h index f465f95477..213749a5e1 100644 --- a/panda/src/collide/collisionRecorder.h +++ b/panda/src/collide/collisionRecorder.h @@ -35,7 +35,7 @@ class CollisionEntry; // class that just provides an interface for recording // collisions tested and detected each frame. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionRecorder { +class EXPCL_PANDA CollisionRecorder : public TypedObject { protected: CollisionRecorder(); public: @@ -58,18 +58,15 @@ public: static TypeHandle get_class_type() { return _type_handle; } - static void init_type() { - register_type(_type_handle, "CollisionRecorder"); + TypedObject::init_type(); + register_type(_type_handle, "CollisionRecorder", + TypedObject::get_class_type()); } - -PUBLISHED: - // We have to publish this explicitly because the CollisionRecorder - // object does not inherit from TypedObject. virtual TypeHandle get_type() const { return get_class_type(); } - INLINE int get_type_index() const; + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} private: static TypeHandle _type_handle; diff --git a/panda/src/collide/collisionVisualizer.I b/panda/src/collide/collisionVisualizer.I index 76e0def072..3ada09aeaa 100644 --- a/panda/src/collide/collisionVisualizer.I +++ b/panda/src/collide/collisionVisualizer.I @@ -30,27 +30,83 @@ SolidInfo() { //////////////////////////////////////////////////////////////////// -// Function: CollisionVisualizer::set_viz_scale +// Function: CollisionVisualizer::set_point_scale // Access: Published -// Description: Scales the objects that are drawn to represent the -// normals and points of the collisions. By default, -// these objects are drawn at an arbitrary scale which -// is appropriate if the scene units are measured in -// feet. Change this scale accordinatly if the scene -// units are measured on some other scale or if you need -// to observe these objects from farther away. +// Description: Scales the points that are drawn to represent the +// surface and interior intersection points of the +// collisions. By default, these objects are drawn at +// an arbitrary scale which is appropriate if the window +// units are the default range -1 .. 1. Change this +// scale accordinatly if the window units are measured +// on some other scale or if you need to observe these +// objects in a smaller window. //////////////////////////////////////////////////////////////////// INLINE void CollisionVisualizer:: -set_viz_scale(float viz_scale) { - _viz_scale = viz_scale; +set_point_scale(float point_scale) { + _point_scale = point_scale; } //////////////////////////////////////////////////////////////////// -// Function: CollisionVisualizer::get_viz_scale +// Function: CollisionVisualizer::get_point_scale // Access: Published -// Description: Returns the value last set by set_viz_scale(). +// Description: Returns the value last set by set_point_scale(). //////////////////////////////////////////////////////////////////// INLINE float CollisionVisualizer:: -get_viz_scale() const { - return _viz_scale; +get_point_scale() const { + return _point_scale; } + +//////////////////////////////////////////////////////////////////// +// Function: CollisionVisualizer::set_normal_scale +// Access: Published +// Description: Scales the line segments that are drawn to represent +// the normals of the collisions. By default, these +// objects are drawn at an arbitrary scale which is +// appropriate if the scene units are measured in feet. +// Change this scale accordinatly if the scene units are +// measured on some other scale or if you need to +// observe these normals from farther away. +//////////////////////////////////////////////////////////////////// +INLINE void CollisionVisualizer:: +set_normal_scale(float normal_scale) { + _normal_scale = normal_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: CollisionVisualizer::get_normal_scale +// Access: Published +// Description: Returns the value last set by set_normal_scale(). +//////////////////////////////////////////////////////////////////// +INLINE float CollisionVisualizer:: +get_normal_scale() const { + return _normal_scale; +} + +//////////////////////////////////////////////////////////////////// +// Function: CollisionVisualizer::as_typed_object +// Access: Public +// Description: This is provided to disambiguate the typecast to +// TypedObject, since we have two TypedObjects in our +// inheritance chain. +//////////////////////////////////////////////////////////////////// +INLINE TypedObject *CollisionVisualizer:: +as_typed_object() { + // In fact, it really doesn't matter which one we pick. Arbitrarily + // pick the one that goes through PandaNode. + return PandaNode::as_typed_object(); +} + +//////////////////////////////////////////////////////////////////// +// Function: CollisionVisualizer::as_typed_object +// Access: Public +// Description: This is provided to disambiguate the typecast to +// TypedObject, since we have two TypedObjects in our +// inheritance chain. +//////////////////////////////////////////////////////////////////// +INLINE const TypedObject * CollisionVisualizer:: +as_typed_object() const { + // In fact, it really doesn't matter which one we pick. Arbitrarily + // pick the one that goes through PandaNode. + return PandaNode::as_typed_object(); +} + diff --git a/panda/src/collide/collisionVisualizer.cxx b/panda/src/collide/collisionVisualizer.cxx index 0dda28d2d2..4fd16614ec 100644 --- a/panda/src/collide/collisionVisualizer.cxx +++ b/panda/src/collide/collisionVisualizer.cxx @@ -52,7 +52,8 @@ CollisionVisualizer(const string &name) : PandaNode(name) { // We always want to render the CollisionVisualizer node itself // (even if it doesn't appear to have any geometry within it). set_internal_bounds(new OmniBoundingVolume()); - _viz_scale = 1.0f; + _point_scale = 1.0f; + _normal_scale = 1.0f; } //////////////////////////////////////////////////////////////////// @@ -137,6 +138,8 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) { // always renders its objects according to their appropriate net // transform. xform_data._net_transform = TransformState::make_identity(); + xform_data._view_frustum = trav->get_view_frustum(); + xform_data._guard_band = trav->get_guard_band(); xform_data.apply_transform_and_state(trav, net_transform, RenderState::make_empty(), RenderEffects::make_empty(), @@ -167,7 +170,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) { // Now draw all of the detected points. if (!viz_info._points.empty()) { CPT(RenderState) empty_state = RenderState::make_empty(); - CPT(RenderState) point_state = RenderState::make(RenderModeAttrib::make(RenderModeAttrib::M_unchanged, 1.0f, true)); + CPT(RenderState) point_state = RenderState::make(RenderModeAttrib::make(RenderModeAttrib::M_unchanged, 1.0f, false)); PT(GeomVertexArrayFormat) point_array_format = new GeomVertexArrayFormat(InternalName::get_vertex(), 3, @@ -197,14 +200,14 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) { vertex.add_data3f(point._surface_point); color.add_data4f(1.0f, 0.0f, 0.0f, 1.0f); - size.add_data1f(0.1f * _viz_scale); + size.add_data1f(16.0f * _point_scale); points->add_next_vertices(1); points->close_primitive(); if (point._interior_point != point._surface_point) { vertex.add_data3f(point._interior_point); color.add_data4f(1.0f, 1.0f, 1.0f, 1.0f); - size.add_data1f(0.05f * _viz_scale); + size.add_data1f(8.0f * _point_scale); points->add_next_vertices(1); points->close_primitive(); } @@ -234,7 +237,7 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) { vertex.add_data3f(point._surface_point); vertex.add_data3f(point._surface_point + - point._surface_normal * _viz_scale); + point._surface_normal * _normal_scale); color.add_data4f(1.0f, 0.0f, 0.0f, 1.0f); color.add_data4f(1.0f, 1.0f, 1.0f, 1.0f); lines->add_next_vertices(2); diff --git a/panda/src/collide/collisionVisualizer.h b/panda/src/collide/collisionVisualizer.h index 3d4b1fb555..5ebe9b11c6 100644 --- a/panda/src/collide/collisionVisualizer.h +++ b/panda/src/collide/collisionVisualizer.h @@ -43,8 +43,11 @@ PUBLISHED: CollisionVisualizer(const string &name); virtual ~CollisionVisualizer(); - INLINE void set_viz_scale(float viz_scale); - INLINE float get_viz_scale() const; + INLINE void set_point_scale(float point_scale); + INLINE float get_point_scale() const; + + INLINE void set_normal_scale(float normal_scale); + INLINE float get_normal_scale() const; void clear(); @@ -59,6 +62,10 @@ public: virtual void begin_traversal(); virtual void collision_tested(const CollisionEntry &entry, bool detected); + // To disambiguate the multiple inheritance from TypedObject. + INLINE TypedObject *as_typed_object(); + INLINE const TypedObject *as_typed_object() const; + private: CPT(RenderState) get_viz_state(); @@ -88,7 +95,8 @@ private: typedef pmap Data; Data _data; - float _viz_scale; + float _point_scale; + float _normal_scale; public: static TypeHandle get_class_type() {