15 #include "collisionVisualizer.h"
16 #include "collisionEntry.h"
17 #include "cullTraverser.h"
18 #include "cullTraverserData.h"
19 #include "cullableObject.h"
20 #include "cullHandler.h"
21 #include "renderState.h"
22 #include "renderModeAttrib.h"
23 #include "geomVertexData.h"
24 #include "geomVertexFormat.h"
25 #include "geomVertexArrayFormat.h"
27 #include "geomPoints.h"
28 #include "geomLines.h"
29 #include "omniBoundingVolume.h"
30 #include "depthOffsetAttrib.h"
31 #include "colorScaleAttrib.h"
32 #include "transparencyAttrib.h"
33 #include "clipPlaneAttrib.h"
34 #include "geomVertexWriter.h"
37 #ifdef DO_COLLISION_RECORDING
47 CollisionVisualizer(
const string &name) :
PandaNode(name) {
63 ~CollisionVisualizer() {
72 void CollisionVisualizer::
87 return new CollisionVisualizer(*
this);
115 bool CollisionVisualizer::
119 Data::const_iterator di;
120 for (di = _data.begin(); di != _data.end(); ++di) {
121 const TransformState *net_transform = (*di).first;
122 const VizInfo &viz_info = (*di).second;
130 xform_data._net_transform = TransformState::make_identity();
132 xform_data.apply_transform_and_state(trav, net_transform,
133 RenderState::make_empty(),
134 RenderEffects::make_empty(),
135 ClipPlaneAttrib::make());
138 Solids::const_iterator si;
139 for (si = viz_info._solids.begin(); si != viz_info._solids.end(); ++si) {
146 const SolidInfo &solid_info = (*si).second;
147 bool was_detected = (solid_info._detected_count > 0);
148 PT(
PandaNode) node = solid->get_viz(trav, xform_data, !was_detected);
154 next_data._state = get_viz_state();
155 trav->traverse(next_data);
160 if (!viz_info._points.empty()) {
164 PT(GeomVertexArrayFormat) point_array_format =
165 new GeomVertexArrayFormat(InternalName::get_vertex(), 3,
167 InternalName::get_color(), 1,
168 Geom::NT_packed_dabc,
Geom::C_color,
169 InternalName::get_size(), 1,
171 CPT(GeomVertexFormat) point_format =
172 GeomVertexFormat::register_format(point_array_format);
174 Points::const_iterator pi;
175 for (pi = viz_info._points.begin(); pi != viz_info._points.end(); ++pi) {
176 const CollisionPoint &point = (*pi);
190 vertex.add_data3(point._surface_point);
191 color.add_data4(1.0f, 0.0f, 0.0f, 1.0f);
192 size.add_data1f(16.0f * _point_scale);
193 points->add_next_vertices(1);
194 points->close_primitive();
196 if (point._interior_point != point._surface_point) {
197 vertex.add_data3(point._interior_point);
198 color.add_data4(1.0f, 1.0f, 1.0f, 1.0f);
199 size.add_data1f(8.0f * _point_scale);
200 points->add_next_vertices(1);
201 points->close_primitive();
204 PT(
Geom) geom = new
Geom(point_vdata);
205 geom->add_primitive(points);
209 xform_data.get_internal_transform(trav));
211 trav->get_cull_handler()->record_object(
object, trav);
215 if (!point._surface_normal.almost_equal(
LVector3::zero())) {
225 vertex.add_data3(point._surface_point);
226 vertex.add_data3(point._surface_point +
227 point._surface_normal * _normal_scale);
228 color.add_data4(1.0f, 0.0f, 0.0f, 1.0f);
229 color.add_data4(1.0f, 1.0f, 1.0f, 1.0f);
230 lines->add_next_vertices(2);
231 lines->close_primitive();
233 PT(
Geom) geom = new
Geom(line_vdata);
234 geom->add_primitive(lines);
238 xform_data.get_internal_transform(trav));
240 trav->get_cull_handler()->record_object(
object, trav);
260 bool CollisionVisualizer::
261 is_renderable()
const {
274 void CollisionVisualizer::
275 output(ostream &out)
const {
276 PandaNode::output(out);
278 CollisionRecorder::output(out);
289 void CollisionVisualizer::
291 CollisionRecorder::begin_traversal();
303 void CollisionVisualizer::
305 CollisionRecorder::collision_tested(entry, detected);
308 CPT(TransformState) net_transform = node_path.get_net_transform();
312 VizInfo &viz_info = _data[net_transform];
314 viz_info._solids[solid]._detected_count++;
319 p._surface_point, p._surface_normal, p._interior_point);
320 viz_info._points.push_back(p);
324 viz_info._solids[solid]._missed_count++;
341 state = RenderState::make
342 (DepthOffsetAttrib::make());
348 #endif // DO_COLLISION_RECORDING
A basic node of the scene graph or data graph.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
Defines a series of disconnected points.
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
The smallest atom of cull.
Defines a single collision event.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
bool has_surface_point() const
Returns true if the surface point has been specified, false otherwise.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Defines a series of disconnected line segments.
NodePath get_into_node_path() const
Returns the NodePath that represents the specific CollisionNode or GeomNode instance that was collide...
GeometricBoundingVolume * get_view_frustum() const
Returns the bounding volume that corresponds to the view frustum, or NULL if the view frustum is not ...
Specifies how polygons are to be drawn.
This is a special kind of GeometricBoundingVolume that fills all of space.
TypeHandle is the identifier used to differentiate C++ class types.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
bool get_all(const NodePath &space, LPoint3 &surface_point, LVector3 &surface_normal, LPoint3 &interior_point) const
Simultaneously transforms the surface point, surface normal, and interior point of the collision into...