Panda3D
|
00001 // Filename: physxDebugGeomNode.cxx 00002 // Created by: enn0x (15Sep09) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "physxDebugGeomNode.h" 00016 00017 #include "geomVertexFormat.h" 00018 #include "geomVertexWriter.h" 00019 00020 TypeHandle PhysxDebugGeomNode::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: PhysxDebugGeomNode::update 00024 // Access: Published 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 void PhysxDebugGeomNode:: 00028 update(NxScene *scenePtr) { 00029 00030 if (get_num_parents() == 0) { 00031 return; 00032 } 00033 00034 const NxDebugRenderable *renderable = scenePtr->getDebugRenderable(); 00035 if (!renderable) { 00036 remove_all_geoms(); 00037 physx_cat.warning() << "Could no get debug renderable." << endl; 00038 return; 00039 } 00040 00041 GeomVertexWriter vwriter = GeomVertexWriter(_vdata, InternalName::get_vertex()); 00042 GeomVertexWriter cwriter = GeomVertexWriter(_vdata, InternalName::get_color()); 00043 00044 int v = 0; 00045 00046 _prim_lines->clear_vertices(); 00047 _prim_triangles->clear_vertices(); 00048 00049 // Lines 00050 { 00051 NxU32 n = renderable->getNbLines(); 00052 const NxDebugLine *lines = renderable->getLines(); 00053 00054 for (NxU32 i=0; i<n; i++) 00055 { 00056 NxF32 b = NxF32((lines[i].color)&0xff) / 255.0f; 00057 NxF32 g = NxF32((lines[i].color>>8)&0xff) / 255.0f; 00058 NxF32 r = NxF32((lines[i].color>>16)&0xff) / 255.0f; 00059 00060 NxVec3 p0 = lines[i].p0; 00061 NxVec3 p1 = lines[i].p1; 00062 00063 cwriter.add_data4f(r, g, b, 1.0f); 00064 vwriter.add_data3f(p0.x, p0.y, p0.z); 00065 _prim_lines->add_vertex(v++); 00066 00067 cwriter.add_data4f(r, g, b, 1.0f); 00068 vwriter.add_data3f(p1.x, p1.y, p1.z); 00069 _prim_lines->add_vertex(v++); 00070 } 00071 00072 } 00073 00074 // Triangles 00075 { 00076 NxU32 n = renderable->getNbTriangles(); 00077 const NxDebugTriangle *triangles = renderable->getTriangles(); 00078 00079 for (NxU32 i=0; i<n; i++) 00080 { 00081 NxF32 b = NxF32((triangles[i].color)&0xff) / 255.0f; 00082 NxF32 g = NxF32((triangles[i].color>>8)&0xff) / 255.0f; 00083 NxF32 r = NxF32((triangles[i].color>>16)&0xff) / 255.0f; 00084 00085 NxVec3 p0 = triangles[i].p0; 00086 NxVec3 p1 = triangles[i].p1; 00087 NxVec3 p2 = triangles[i].p2; 00088 00089 cwriter.add_data4f(r, g, b, 1.0f); 00090 vwriter.add_data3f(p0.x, p0.y, p0.z); 00091 _prim_triangles->add_vertex(v++); 00092 00093 cwriter.add_data4f(r, g, b, 1.0f); 00094 vwriter.add_data3f(p1.x, p1.y, p1.z); 00095 _prim_triangles->add_vertex(v++); 00096 00097 cwriter.add_data4f(r, g, b, 1.0f); 00098 vwriter.add_data3f(p2.x, p2.y, p2.z); 00099 _prim_triangles->add_vertex(v++); 00100 } 00101 } 00102 00103 _prim_lines->close_primitive(); 00104 _prim_triangles->close_primitive(); 00105 00106 physx_cat.spam() << "Updated PhysxDebugGeomNode geometry\n"; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: PhysxDebugGeomNode::on 00111 // Access: Published 00112 // Description: 00113 //////////////////////////////////////////////////////////////////// 00114 void PhysxDebugGeomNode:: 00115 on() { 00116 00117 NxGetPhysicsSDK()->setParameter(NX_VISUALIZATION_SCALE, _scale); 00118 } 00119 00120 //////////////////////////////////////////////////////////////////// 00121 // Function: PhysxDebugGeomNode::off 00122 // Access: Published 00123 // Description: 00124 //////////////////////////////////////////////////////////////////// 00125 void PhysxDebugGeomNode:: 00126 off() { 00127 00128 NxGetPhysicsSDK()->setParameter(NX_VISUALIZATION_SCALE, 0.0f); 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: PhysxDebugGeomNode::toggle 00133 // Access: Published 00134 // Description: 00135 //////////////////////////////////////////////////////////////////// 00136 void PhysxDebugGeomNode:: 00137 toggle() { 00138 00139 if (NxGetPhysicsSDK()->getParameter(NX_VISUALIZATION_SCALE) == 0.0f) { 00140 on(); 00141 } 00142 else { 00143 off(); 00144 } 00145 } 00146