15 #include "bulletDebugNode.h"
17 #include "geomLines.h"
18 #include "geomVertexData.h"
19 #include "geomTriangles.h"
20 #include "geomVertexFormat.h"
21 #include "geomVertexWriter.h"
22 #include "omniBoundingVolume.h"
32 BulletDebugNode(
const char *name) :
GeomNode(name) {
37 _drawer._normals =
true;
42 set_overall_hidden(true);
53 prim->set_shade_model(
Geom::SM_uniform);
55 geom = new
Geom(vdata);
56 geom->add_primitive(prim);
63 PT(GeomVertexData) vdata;
67 vdata = new GeomVertexData("", GeomVertexFormat::get_v3c4(),
Geom::UH_stream);
70 prim->set_shade_model(
Geom::SM_uniform);
72 geom = new
Geom(vdata);
73 geom->add_primitive(prim);
89 safe_to_flatten()
const {
178 if (is_overall_hidden()) {
179 _drawer.setDebugMode(DebugDraw::DBG_NoDebug);
182 int mode = DebugDraw::DBG_DrawText |
183 DebugDraw::DBG_DrawFeaturesText |
184 DebugDraw::DBG_DrawContactPoints;
187 mode |= DebugDraw::DBG_DrawWireframe;
191 mode |= DebugDraw::DBG_DrawConstraints;
192 mode |= DebugDraw::DBG_DrawConstraintLimits;
196 mode |= DebugDraw::DBG_DrawAabb;
199 _drawer.setDebugMode(mode);
208 void BulletDebugNode::
209 sync_b2p(btDynamicsWorld *world) {
211 if (is_overall_hidden())
return;
213 nassertv(get_num_geoms() == 2);
216 _drawer._lines.clear();
217 _drawer._triangles.clear();
219 world->debugDrawWorld();
228 PT(GeomVertexData) vdata;
232 vdata = new GeomVertexData("", GeomVertexFormat::get_v3c4(),
Geom::UH_stream);
235 prim->set_shade_model(
Geom::SM_uniform);
242 pvector<Line>::const_iterator lit;
243 for (lit = _drawer._lines.begin(); lit != _drawer._lines.end(); lit++) {
248 cwriter.add_data4(
LVecBase4(line._color));
249 cwriter.add_data4(
LVecBase4(line._color));
251 prim->add_vertex(v++);
252 prim->add_vertex(v++);
253 prim->close_primitive();
256 geom =
new Geom(vdata);
257 geom->add_primitive(prim);
264 PT(GeomVertexData) vdata;
268 vdata = new GeomVertexData("", GeomVertexFormat::get_v3c4(),
Geom::UH_stream);
271 prim->set_shade_model(
Geom::SM_uniform);
278 pvector<Triangle>::const_iterator tit;
279 for (tit = _drawer._triangles.begin(); tit != _drawer._triangles.end(); tit++) {
285 cwriter.add_data4(
LVecBase4(tri._color));
286 cwriter.add_data4(
LVecBase4(tri._color));
287 cwriter.add_data4(
LVecBase4(tri._color));
289 prim->add_vertex(v++);
290 prim->add_vertex(v++);
291 prim->add_vertex(v++);
292 prim->close_primitive();
295 geom =
new Geom(vdata);
296 geom->add_primitive(prim);
307 void BulletDebugNode::DebugDraw::
308 setDebugMode(
int mode) {
318 int BulletDebugNode::DebugDraw::
319 getDebugMode()
const {
329 void BulletDebugNode::DebugDraw::
330 reportErrorWarning(
const char *warning) {
332 bullet_cat.error() << warning << endl;
340 void BulletDebugNode::DebugDraw::
341 drawLine(
const btVector3 &from,
const btVector3 &to,
const btVector3 &
color) {
343 PN_stdfloat r = color.getX();
344 PN_stdfloat g = color.getY();
345 PN_stdfloat b = color.getZ();
349 if (_normals==
false && r==1.0f && g==1.0f && b==0.0f)
return;
353 line._p0 =
LVecBase3((PN_stdfloat)from.getX(),
354 (PN_stdfloat)from.getY(),
355 (PN_stdfloat)from.getZ());
356 line._p1 =
LVecBase3((PN_stdfloat)to.getX(),
357 (PN_stdfloat)to.getY(),
358 (PN_stdfloat)to.getZ());
361 (PN_stdfloat)b, 1.0f);
363 _lines.push_back(line);
371 void BulletDebugNode::DebugDraw::
372 drawTriangle(
const btVector3 &v0,
const btVector3 &v1,
const btVector3 &v2,
const btVector3 &color, btScalar) {
374 btScalar r = color.getX();
375 btScalar g = color.getY();
376 btScalar b = color.getZ();
380 tri._p0 =
LVecBase3((PN_stdfloat)v0.getX(),
381 (PN_stdfloat)v0.getY(),
382 (PN_stdfloat)v0.getZ());
384 tri._p1 =
LVecBase3((PN_stdfloat)v1.getX(),
385 (PN_stdfloat)v1.getY(),
386 (PN_stdfloat)v1.getZ());
388 tri._p2 =
LVecBase3((PN_stdfloat)v2.getX(),
389 (PN_stdfloat)v2.getY(),
390 (PN_stdfloat)v2.getZ());
394 (PN_stdfloat)b, 1.0f);
396 _triangles.push_back(tri);
416 void BulletDebugNode::DebugDraw::
417 drawTriangle(
const btVector3 &v0,
const btVector3 &v1,
const btVector3 &v2,
const btVector3 &n0,
const btVector3 &n1,
const btVector3 &n2,
const btVector3 &color, btScalar alpha) {
419 bullet_cat.debug() <<
"drawTriangle(2) - not yet implemented!" << endl;
427 void BulletDebugNode::DebugDraw::
428 drawContactPoint(
const btVector3 &point,
const btVector3 &normal, btScalar distance,
int lifetime,
const btVector3 &color) {
430 const btVector3 to = point + normal * distance;
431 const btVector3 &from = point;
433 drawLine(from, to, color);
441 void BulletDebugNode::DebugDraw::
442 draw3dText(
const btVector3 &location,
const char *text) {
444 bullet_cat.debug() <<
"draw3dText - not yet implemented!" << endl;
452 void BulletDebugNode::DebugDraw::
453 drawSphere(btScalar radius,
const btTransform &transform,
const btVector3 &color) {
455 btVector3 center = transform.getOrigin();
457 const btVector3 xoffs = transform.getBasis() * btVector3(1, 0, 0);
458 const btVector3 yoffs = transform.getBasis() * btVector3(0, 1, 0);
459 const btVector3 zoffs = transform.getBasis() * btVector3(0, 0, 1);
461 drawArc(center, xoffs, yoffs, radius, radius, 0, SIMD_2_PI, color,
false, 10.0);
462 drawArc(center, yoffs, zoffs, radius, radius, 0, SIMD_2_PI, color,
false, 10.0);
463 drawArc(center, zoffs, xoffs, radius, radius, 0, SIMD_2_PI, color,
false, 10.0);
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...
This is the base class for all three-component vectors and points.
virtual void draw_mask_changed()
Called after the node's DrawMask has been changed for any reason, this just provides a hook so derive...
This is an "unaligned" LVecBase4.
virtual bool safe_to_flatten_below() const
Returns true if a flatten operation may safely continue past this node, or false if nodes below this ...
static NodePath any_path(PandaNode *node, Thread *current_thread=Thread::get_current_thread())
Returns a new NodePath that represents any arbitrary path from the root to the indicated node...
This is our own Panda specialization on the default STL vector.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is a 4-by-4 transform matrix.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
virtual bool safe_to_combine_children() const
Returns true if it is generally safe to combine the children of this PandaNode with each other...
Defines a series of disconnected line segments.
This is the base class for all three-component vectors and points.
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of Node by calling the xform()...
bool invert_in_place()
Inverts the current matrix.
Defines a series of disconnected triangles.
This is a special kind of GeometricBoundingVolume that fills all of space.
TypeHandle is the identifier used to differentiate C++ class types.
const LMatrix4 & get_mat() const
Returns the transform matrix that has been applied to the referenced node, or the identity matrix if ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
virtual bool safe_to_modify_transform() const
Returns true if it is safe to automatically adjust the transform on this kind of node.
A node that holds Geom objects, renderable pieces of geometry.
LVecBase3f xform_point(const LVecBase3f &v) const
The matrix transforms a 3-component point (including translation component) and returns the result...
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...