Panda3D
 All Classes Functions Variables Enumerations
physxDebugGeomNode.cxx
1 // Filename: physxDebugGeomNode.cxx
2 // Created by: enn0x (15Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "physxDebugGeomNode.h"
16 
17 #include "geomVertexFormat.h"
18 #include "geomVertexWriter.h"
19 
20 TypeHandle PhysxDebugGeomNode::_type_handle;
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: PhysxDebugGeomNode::update
24 // Access: Published
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 void PhysxDebugGeomNode::
28 update(NxScene *scenePtr) {
29 
30  if (get_num_parents() == 0) {
31  return;
32  }
33 
34  const NxDebugRenderable *renderable = scenePtr->getDebugRenderable();
35  if (!renderable) {
37  physx_cat.warning() << "Could no get debug renderable." << endl;
38  return;
39  }
40 
41  GeomVertexWriter vwriter = GeomVertexWriter(_vdata, InternalName::get_vertex());
42  GeomVertexWriter cwriter = GeomVertexWriter(_vdata, InternalName::get_color());
43 
44  int v = 0;
45 
46  _prim_lines->clear_vertices();
47  _prim_triangles->clear_vertices();
48 
49  // Lines
50  {
51  NxU32 n = renderable->getNbLines();
52  const NxDebugLine *lines = renderable->getLines();
53 
54  for (NxU32 i=0; i<n; i++)
55  {
56  NxF32 b = NxF32((lines[i].color)&0xff) / 255.0f;
57  NxF32 g = NxF32((lines[i].color>>8)&0xff) / 255.0f;
58  NxF32 r = NxF32((lines[i].color>>16)&0xff) / 255.0f;
59 
60  NxVec3 p0 = lines[i].p0;
61  NxVec3 p1 = lines[i].p1;
62 
63  cwriter.add_data4f(r, g, b, 1.0f);
64  vwriter.add_data3f(p0.x, p0.y, p0.z);
65  _prim_lines->add_vertex(v++);
66 
67  cwriter.add_data4f(r, g, b, 1.0f);
68  vwriter.add_data3f(p1.x, p1.y, p1.z);
69  _prim_lines->add_vertex(v++);
70  }
71 
72  }
73 
74  // Triangles
75  {
76  NxU32 n = renderable->getNbTriangles();
77  const NxDebugTriangle *triangles = renderable->getTriangles();
78 
79  for (NxU32 i=0; i<n; i++)
80  {
81  NxF32 b = NxF32((triangles[i].color)&0xff) / 255.0f;
82  NxF32 g = NxF32((triangles[i].color>>8)&0xff) / 255.0f;
83  NxF32 r = NxF32((triangles[i].color>>16)&0xff) / 255.0f;
84 
85  NxVec3 p0 = triangles[i].p0;
86  NxVec3 p1 = triangles[i].p1;
87  NxVec3 p2 = triangles[i].p2;
88 
89  cwriter.add_data4f(r, g, b, 1.0f);
90  vwriter.add_data3f(p0.x, p0.y, p0.z);
91  _prim_triangles->add_vertex(v++);
92 
93  cwriter.add_data4f(r, g, b, 1.0f);
94  vwriter.add_data3f(p1.x, p1.y, p1.z);
95  _prim_triangles->add_vertex(v++);
96 
97  cwriter.add_data4f(r, g, b, 1.0f);
98  vwriter.add_data3f(p2.x, p2.y, p2.z);
99  _prim_triangles->add_vertex(v++);
100  }
101  }
102 
103  _prim_lines->close_primitive();
104  _prim_triangles->close_primitive();
105 
106  physx_cat.spam() << "Updated PhysxDebugGeomNode geometry\n";
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: PhysxDebugGeomNode::on
111 // Access: Published
112 // Description:
113 ////////////////////////////////////////////////////////////////////
114 void PhysxDebugGeomNode::
115 on() {
116 
117  NxGetPhysicsSDK()->setParameter(NX_VISUALIZATION_SCALE, _scale);
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: PhysxDebugGeomNode::off
122 // Access: Published
123 // Description:
124 ////////////////////////////////////////////////////////////////////
125 void PhysxDebugGeomNode::
126 off() {
127 
128  NxGetPhysicsSDK()->setParameter(NX_VISUALIZATION_SCALE, 0.0f);
129 }
130 
131 ////////////////////////////////////////////////////////////////////
132 // Function: PhysxDebugGeomNode::toggle
133 // Access: Published
134 // Description:
135 ////////////////////////////////////////////////////////////////////
136 void PhysxDebugGeomNode::
137 toggle() {
138 
139  if (NxGetPhysicsSDK()->getParameter(NX_VISUALIZATION_SCALE) == 0.0f) {
140  on();
141  }
142  else {
143  off();
144  }
145 }
146 
void add_data4f(float x, float y, float z, float w)
Sets the write row to a particular 4-component value, and advances the write row. ...
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void add_data3f(float x, float y, float z)
Sets the write row to a particular 3-component value, and advances the write row. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
int get_num_parents(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of parent nodes this node has.
Definition: pandaNode.I:26
void remove_all_geoms()
Removes all the geoms from the node at once.
Definition: geomNode.I:159