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