From 4630d0abb1ea42c42ec5988ffe2d2ee9ec9a4052 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Fri, 3 Jul 2015 18:54:41 -0700 Subject: [PATCH] fix windows build for b3ResourcePath replace print -> b3Printf in URDF2Bullet.cpp --- .../ImportURDFDemo/ImportURDFSetup.cpp | 2 +- .../Importers/ImportURDFDemo/URDF2Bullet.cpp | 47 ++++++++++--------- examples/Utils/b3ResourcePath.cpp | 25 +++++++--- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp b/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp index ac4eadd84..66f9a3bba 100644 --- a/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp +++ b/examples/Importers/ImportURDFDemo/ImportURDFSetup.cpp @@ -234,7 +234,7 @@ void ImportUrdfSetup::initPhysics() //todo: move these internal API called inside the 'ConvertURDF2Bullet' call, hidden from the user int rootLinkIndex = u2b.getRootLinkIndex(); - printf("urdf root link index = %d\n",rootLinkIndex); + b3Printf("urdf root link index = %d\n",rootLinkIndex); MyMultiBodyCreator creation(m_guiHelper); ConvertURDF2Bullet(u2b,creation, identityTrans,m_dynamicsWorld,m_useMultiBody,u2b.getPathPrefix()); diff --git a/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp b/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp index 2c1a2c0d0..a1e234434 100644 --- a/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp +++ b/examples/Importers/ImportURDFDemo/URDF2Bullet.cpp @@ -10,6 +10,8 @@ #include "URDFImporterInterface.h" #include "MultiBodyCreationInterface.h" #include +#include "Bullet3Common/b3Logging.h" + static int bodyCollisionFilterGroup=btBroadphaseProxy::CharacterFilter; static int bodyCollisionFilterMask=btBroadphaseProxy::AllFilter&(~btBroadphaseProxy::CharacterFilter); static bool enableConstraints = true; @@ -41,11 +43,11 @@ void printTree(const URDFImporterInterface& u2b, int linkIndex, int indentationL u2b.getMassAndInertia(linkIndex,mass,localInertia,inertialFrame); std::string name = u2b.getLinkName(linkIndex); for(int j=0;j childIndices; u2b.getLinkChildIndices(linkIndex,childIndices); - printf("link %s has %d children\n", u2b.getLinkName(linkIndex).c_str(),childIndices.size()); - for (int i=0;isetupFixed(mbLinkIndex, mass, localInertiaDiagonal, mbParentIndex, rot*offsetInB.getRotation(), offsetInA.getOrigin(),-offsetInB.getOrigin(),disableParentCollision); @@ -311,7 +314,7 @@ void ConvertURDF2BulletInternal(const URDFImporterInterface& u2b, MultiBodyCreat } else { - printf("Fixed joint\n"); + b3Printf("Fixed joint\n"); btGeneric6DofSpring2Constraint* dof6 = creation.createFixedJoint(urdfLinkIndex,*parentRigidBody, *linkRigidBody, offsetInA, offsetInB); @@ -340,7 +343,7 @@ void ConvertURDF2BulletInternal(const URDFImporterInterface& u2b, MultiBodyCreat if (enableConstraints) world1->addConstraint(dof6,true); - printf("Revolute/Continuous joint\n"); + b3Printf("Revolute/Continuous joint\n"); } break; } @@ -368,13 +371,13 @@ void ConvertURDF2BulletInternal(const URDFImporterInterface& u2b, MultiBodyCreat if (enableConstraints) world1->addConstraint(dof6,true); - printf("Prismatic\n"); + b3Printf("Prismatic\n"); } break; } default: { - printf("Error: unsupported joint type in URDF (%d)\n", jointType); + b3Printf("Error: unsupported joint type in URDF (%d)\n", jointType); btAssert(0); } } diff --git a/examples/Utils/b3ResourcePath.cpp b/examples/Utils/b3ResourcePath.cpp index 75ca52415..d27b61e99 100644 --- a/examples/Utils/b3ResourcePath.cpp +++ b/examples/Utils/b3ResourcePath.cpp @@ -4,6 +4,7 @@ #include /* _NSGetExecutablePath */ #else #ifdef _WIN32 +#include #else //not Mac, not Windows, let's cross the fingers it is Linux :-) #include @@ -31,8 +32,11 @@ int b3ResourcePath::getExePath(char* path, int maxPathLenInBytes) } #else #ifdef _WIN32 -#error not yet + //https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197(v=vs.85).aspx + HMODULE hModule = GetModuleHandle(NULL); + numBytes = GetModuleFileName(hModule, path, maxPathLenInBytes); #else + ///http://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c numBytes = (int)readlink("/proc/self/exe", path, maxPathLenInBytes-1); if (numBytes > 0) { @@ -60,12 +64,19 @@ int b3ResourcePath::findResourcePath(const char* resourceName, char* resourcePat int exeNamePos = b3FileUtils::extractPath(exePath,pathToExe,B3_MAX_EXE_PATH_LEN); if (exeNamePos) { - sprintf(resourcePath,"%s../resources/%s/%s",pathToExe,&exePath[exeNamePos],resourceName); - //printf("try resource at %s\n", resourcePath); - if (b3FileUtils::findFile(resourcePath, resourcePath, resourcePathMaxNumBytes)) - { - return strlen(resourcePath); - } + sprintf(resourcePath,"%s../data/%s",pathToExe,resourceName); + //printf("try resource at %s\n", resourcePath); + if (b3FileUtils::findFile(resourcePath, resourcePath, resourcePathMaxNumBytes)) + { + return strlen(resourcePath); + } + + sprintf(resourcePath,"%s../resources/%s/%s",pathToExe,&exePath[exeNamePos],resourceName); + //printf("try resource at %s\n", resourcePath); + if (b3FileUtils::findFile(resourcePath, resourcePath, resourcePathMaxNumBytes)) + { + return strlen(resourcePath); + } } }