physxDebugHelper.cpp

00001 
00002 #include "main.h"
00003 #include "physxDebugHelper.h"
00004 
00005 
00006 
00007 // used by irrlichtUpdate()
00008 static bool isPhysxDebugRenderingEnabled = false;
00009 
00010 void switchPhysxDebugRenderingEnabled()
00011 {
00012         isPhysxDebugRenderingEnabled = !isPhysxDebugRenderingEnabled;
00013 }
00014 bool getPhysxDebugRenderingEnabled()
00015 {
00016         return isPhysxDebugRenderingEnabled;
00017 }
00018 
00019 
00020 
00021 
00022 
00023 // output physX errors, reported by the SDK
00024 void NxDebugOutput::reportError(NxErrorCode code, const char* message, const char* file, int line)
00025 {
00026         stringc error("*** physX error *** ");
00027         error += code;
00028         error += " ";
00029         error += message;
00030         error += " in ";
00031         error += file;
00032         error += " at ";
00033         error += line;
00034 
00035         logger->log( error.c_str() );
00036 }
00037 
00038 
00039 // output physX errors, reported by the SDK
00040 NxAssertResponse NxDebugOutput::reportAssertViolation(const char* message, const char* file, int line)
00041 {
00042         NxAssertResponse status = NX_AR_BREAKPOINT;
00043 
00044         stringc error("*** physX Assert failed *** ");
00045         error += message;
00046         error += " in ";
00047         error += file;
00048         error += " at ";
00049         error += line;
00050 
00051         logger->log( error.c_str() );
00052 
00053         return status;
00054 }
00055 
00056 
00057 // output physX errors, reported by the SDK
00058 void NxDebugOutput::print(const char* message)
00059 {
00060         stringc msg("physX debug: ");
00061         msg += message;
00062 
00063         logger->log( msg.c_str() );
00064 }
00065 
00066 
00067 
00068 
00069 
00070 
00071 // uses irrlicht to render debug data (triangles), given from physX debug visualization
00072 NxDebugRenderer::NxDebugRenderer()
00073 {
00074 }
00075 
00076 NxDebugRenderer::~NxDebugRenderer()
00077 {
00078 }
00079 
00080 
00081 
00082 // must be called from irrlicht update()
00083 // i.e. "within beginScene() and endScene()"
00084 // because irrlicht must be in proper render state to draw below lines
00085 ERR_TYPE NxDebugRenderer::update( f32 timeMS )
00086 {
00087         const NxDebugRenderable* nxDebugRenderable;
00088         u32 nLines = 0;
00089         u32 nTriangles = 0;
00090         u32 nPoints = 0;
00091 
00092         if ( nxScene )
00093         {
00094                 // the renderable from physX must be obtained every frame
00095                 nxDebugRenderable = nxScene->getDebugRenderable();
00096                 if ( NULL == nxDebugRenderable )
00097                 {
00098                         logger->log( "*** can not get NxDebugRenderable ***" );
00099                 }
00100                 else
00101                 {
00102                         nLines =                nxDebugRenderable->getNbLines();
00103                         nTriangles =    nxDebugRenderable->getNbTriangles();
00104                         nPoints =               nxDebugRenderable->getNbPoints();
00105                 }
00106         }
00107 
00108         // tell irrlicht to draw in world coordinates with center (0,0,0)
00109         // setup a identity matrix
00110         matrix4 identity;
00111         driver->setTransform( ETS_WORLD, identity );
00112 
00113         // tell irrlicht to use this material for drawing
00114         // setup a default material, but turn dynamic lighting OFF
00115         SMaterial defaultMaterial;
00116         defaultMaterial.Lighting = false;
00117         driver->setMaterial( defaultMaterial );
00118 
00119         // draw lines, retrieved by nxDebugRenderable
00120         if ( nLines )
00121         {
00122                 const NxDebugLine* nxDebugLines = nxDebugRenderable->getLines();
00123 
00124                 while ( nLines-- )
00125                 {
00126                         vector3df start( nxDebugLines->p0.x, nxDebugLines->p0.y, nxDebugLines->p0.z );
00127                         vector3df end( nxDebugLines->p1.x, nxDebugLines->p1.y, nxDebugLines->p1.z );
00128                         SColor color( nxDebugLines->color );    // a rgb
00129                         driver->draw3DLine( start, end, color );
00130                         nxDebugLines++;
00131                 }
00132         }
00133 
00134         // draw triangles, retrieved by nxDebugRenderable
00135         if ( nTriangles )
00136         {
00137                 const NxDebugTriangle* nxDebugTriangles = nxDebugRenderable->getTriangles();
00138 
00139                 while ( nTriangles-- )
00140                 {
00141                         vector3df v0( nxDebugTriangles->p0.x, nxDebugTriangles->p0.y, nxDebugTriangles->p0.z );
00142                         vector3df v1( nxDebugTriangles->p1.x, nxDebugTriangles->p1.y, nxDebugTriangles->p1.z );
00143                         vector3df v2( nxDebugTriangles->p2.x, nxDebugTriangles->p2.y, nxDebugTriangles->p2.z );
00144                         triangle3df triangle( v0, v1, v2 );
00145                         SColor color( nxDebugTriangles->color );        // a rgb
00146                         driver->draw3DTriangle( triangle, color );
00147                         nxDebugTriangles++;
00148                 }
00149         }
00150 
00151         // draw points, retrieved by nxDebugRenderable
00152         if ( nPoints )
00153         {
00154                 const NxDebugPoint* nxDebugPoints = nxDebugRenderable->getPoints();
00155 
00156                 while ( nPoints-- )
00157                 {
00158                         vector3df p( nxDebugPoints->p.x, nxDebugPoints->p.y, nxDebugPoints->p.z );
00159                         aabbox3df  aabbox( p - vector3df(1.0f, 1.0f, 1.0f), p + vector3df(1.0f, 1.0f, 1.0f) );
00160                         SColor color( nxDebugPoints->color );   // a rgb
00161                         driver->draw3DBox( aabbox, color );
00162                         nxDebugPoints++;
00163                 }
00164         }
00165 
00166         return ERR_OK;
00167 }
00168 
00169 
00170 
00171 
00172 
00173 
00174 // output physX errors, reported by the NXU_helper
00175 void NxuDebugOutput::NXU_errorMessage(bool isError, const char* str)
00176 {
00177         stringc msg("physX util error: ");
00178         msg += str;
00179 
00180         logger->log( msg.c_str() );
00181 }
00182 
00183 
00184 
00185 // Notifies the application that a new scene has been created.
00186 void NxuUserNotify::NXU_notifyScene(NxU32 sno, NxScene* scene,const char* userProperties)
00187 {
00188         stringc msg( "NXU_notifyScene() scene created" );
00189         logger->log( msg.c_str() );
00190 }
00191 
00192 //brief Notifies the application that a new actor has been created.
00193 void NxuUserNotify::NXU_notifyActor(NxActor* actor, const char* userProperties)
00194 {
00195         stringc msg( "NXU_notifyActor() actor created. name=" );
00196         msg += actor->getName();
00197         logger->log( msg.c_str() );
00198 }
00199 
00200 //brief Notifies the application that a new TriangleMesh that has been created.
00201 void NxuUserNotify:: NXU_notifyTriangleMesh(NxTriangleMesh* t,const char* userProperties)
00202 {
00203         NxReal mass = 0.0f;
00204         NxMat33 localInertia;
00205         NxVec3 localCenterOfMass;
00206         t->getMassInformation( mass, localInertia, localCenterOfMass );
00207         stringc msg( "NXU_notifyTriangleMesh() triangle mesh created. mass=" );
00208         msg += mass;
00209         logger->log( msg.c_str() );
00210 }
00211 
00212 // brief Pre-notification event before a new scene is about to be created.
00213 // return a NULL pointer to have the instantiator create the scene.  A non-null pointer is the NxScene the application wants the data to be loaded into.
00214 NxScene* NxuUserNotify::NXU_preNotifyScene(unsigned int sno, NxSceneDesc& scene, const char* userProperties)
00215 {
00216         stringc msg( "NXU_preNotifyScene() scene is about to be created" );
00217         logger->log( msg.c_str() );
00218         return NULL;
00219 }
00220 
00221 // brief Pre-notification event before an actor is created.
00222 // return true to create the actor or false to skip it.
00223 bool NxuUserNotify::NXU_preNotifyActor(NxActorDesc& actor, const char* userProperties)
00224 {
00225         stringc msg( "NXU_preNotifyActor() actor is about to be created" );
00226         logger->log( msg.c_str() );
00227         return true;
00228 }
00229 
00230 // brief Pre-notification event before a triangle mesh is created.
00231 // return true to create the triangle mesh or false to skip it.
00232 bool NxuUserNotify::NXU_preNotifyTriangleMesh(NxTriangleMeshDesc& t,const char* userProperties)
00233 {
00234         stringc msg( "NXU_preNotifyTriangleMesh() triangle mesh is about to be created" );
00235         logger->log( msg.c_str() );
00236         return true;
00237 }
00238 
00239 // brief Pre-notification event before a SceneInstance is executed.
00240 // return true to execute the scene instance.
00241 bool NxuUserNotify::NXU_preNotifySceneInstance(const char* name,const char* sceneName,const char* userProperties,NxMat34& rootNode,NxU32 depth)
00242 {
00243         stringc msg( "NXU_preNotifySceneInstance() scene is about to be instantiated" );
00244         logger->log( msg.c_str() );
00245         return true;
00246 }
00247 
00248 // brief Notification event because a scene failed to be created.
00249 void NxuUserNotify::NXU_notifySceneFailed(unsigned int sno, NxSceneDesc& scene, const char* userProperties)
00250 {
00251         stringc msg( "NXU_notifySceneFailed() scene create failed" );
00252         logger->log( msg.c_str() );
00253 }
00254 
00255 // brief Notification event that an actor failed to be created.
00256 void NxuUserNotify::NXU_notifyActorFailed(NxActorDesc& actor, const char* userProperties)
00257 {
00258         stringc msg( "NXU_notifyActorFailed() actor create failed. name=" );
00259         msg += actor.name;
00260         logger->log( msg.c_str() );
00261 }
00262 
00263 // brief Notification event that a triangle mesh failed to be created.
00264 void NxuUserNotify::NXU_notifyTriangleMeshFailed(NxTriangleMeshDesc& t,const char* userProperties)
00265 {
00266         stringc msg( "NXU_notifyTriangleMeshFailed() triangle mesh create failed" );
00267         logger->log( msg.c_str() );
00268 }

Generated on Sun Dec 2 03:10:23 2007 for TableTop by  doxygen 1.5.4