add commandline arguments to serialize demo for xml export and Bullet import file name
update AntTweakBar version in CDTestFramework add btCompoundShape support in BulletXmlWorldImporter (this importer is still premature/work-in-progress)
This commit is contained in:
112
Demos/OpenGL/CommandLineArguments.h
Normal file
112
Demos/OpenGL/CommandLineArguments.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2010 Duane Merrill
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* For more information, see our Google Code project site:
|
||||
* http://code.google.com/p/back40computing/
|
||||
*
|
||||
* Thanks!
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef COMMAND_LINE_ARGS_H
|
||||
#define COMMAND_LINE_ARGS_H
|
||||
|
||||
/******************************************************************************
|
||||
* Command-line parsing
|
||||
******************************************************************************/
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
class CommandLineArguments
|
||||
{
|
||||
protected:
|
||||
|
||||
std::map<std::string, std::string> pairs;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
CommandLineArguments(int argc, char **argv)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
string arg = argv[i];
|
||||
|
||||
if ((arg[0] != '-') || (arg[1] != '-')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string::size_type pos;
|
||||
string key, val;
|
||||
if ((pos = arg.find( '=')) == string::npos) {
|
||||
key = string(arg, 2, arg.length() - 2);
|
||||
val = "";
|
||||
} else {
|
||||
key = string(arg, 2, pos - 2);
|
||||
val = string(arg, pos + 1, arg.length() - 1);
|
||||
}
|
||||
pairs[key] = val;
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckCmdLineFlag(const char* arg_name)
|
||||
{
|
||||
using namespace std;
|
||||
map<string, string>::iterator itr;
|
||||
if ((itr = pairs.find(arg_name)) != pairs.end()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void GetCmdLineArgument(const char *arg_name, T &val);
|
||||
|
||||
int ParsedArgc()
|
||||
{
|
||||
return pairs.size();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void CommandLineArguments::GetCmdLineArgument(const char *arg_name, T &val)
|
||||
{
|
||||
using namespace std;
|
||||
map<string, string>::iterator itr;
|
||||
if ((itr = pairs.find(arg_name)) != pairs.end()) {
|
||||
istringstream strstream(itr->second);
|
||||
strstream >> val;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void CommandLineArguments::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
|
||||
{
|
||||
using namespace std;
|
||||
map<string, string>::iterator itr;
|
||||
if ((itr = pairs.find(arg_name)) != pairs.end()) {
|
||||
|
||||
string s = itr->second;
|
||||
val = (char*) malloc(sizeof(char) * (s.length() + 1));
|
||||
strcpy(val, s.c_str());
|
||||
|
||||
} else {
|
||||
val = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //COMMAND_LINE_ARGS_H
|
||||
@@ -732,7 +732,13 @@ public:
|
||||
};
|
||||
#endif //DESERIALIZE_SOFT_BODIES
|
||||
|
||||
SerializeDemo::SerializeDemo()
|
||||
:m_verboseMode(0),
|
||||
m_fileName("testFile.bullet")
|
||||
{
|
||||
m_idle=true;
|
||||
|
||||
}
|
||||
SerializeDemo::~SerializeDemo()
|
||||
{
|
||||
m_fileLoader->deleteAllData();
|
||||
@@ -743,7 +749,7 @@ SerializeDemo::~SerializeDemo()
|
||||
void SerializeDemo::initPhysics()
|
||||
{
|
||||
setTexturing(true);
|
||||
setShadows(true);
|
||||
setShadows(false);//true);
|
||||
|
||||
setCameraDistance(btScalar(SCALING*30.));
|
||||
|
||||
@@ -755,7 +761,7 @@ void SerializeDemo::initPhysics()
|
||||
m_fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
|
||||
#endif //DESERIALIZE_SOFT_BODIES
|
||||
|
||||
//m_fileLoader->setVerboseMode(bParse::FD_VERBOSE_EXPORT_XML);
|
||||
m_fileLoader->setVerboseMode(m_verboseMode);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -50,12 +50,12 @@ class SerializeDemo : public PlatformDemoApplication
|
||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||
|
||||
class btBulletWorldImporter* m_fileLoader;
|
||||
const char* m_fileName;
|
||||
int m_verboseMode;
|
||||
|
||||
public:
|
||||
|
||||
SerializeDemo()
|
||||
{
|
||||
}
|
||||
SerializeDemo();
|
||||
virtual ~SerializeDemo();
|
||||
|
||||
void initPhysics();
|
||||
@@ -70,6 +70,24 @@ class SerializeDemo : public PlatformDemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
void setFileName(const char* name)
|
||||
{
|
||||
m_fileName = name;
|
||||
}
|
||||
const char* getFileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
void setVerboseMode(int mode)
|
||||
{
|
||||
m_verboseMode = mode;
|
||||
}
|
||||
int getVerboseMode() const
|
||||
{
|
||||
return m_verboseMode;
|
||||
}
|
||||
|
||||
static DemoApplication* Create()
|
||||
{
|
||||
SerializeDemo* demo = new SerializeDemo;
|
||||
|
||||
@@ -18,7 +18,8 @@ subject to the following restrictions:
|
||||
#include "GLDebugDrawer.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btHashMap.h"
|
||||
|
||||
#include "btBulletFile.h"
|
||||
#include "CommandLineArguments.h"
|
||||
|
||||
|
||||
#ifdef USE_AMD_OPENCL
|
||||
@@ -84,6 +85,22 @@ bool initCL( void* glCtx, void* glDC )
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
CommandLineArguments arg(argc,argv);
|
||||
char* filename=0;
|
||||
arg.GetCmdLineArgument("filename", filename);
|
||||
bool dumpXml = arg.CheckCmdLineFlag("dump_xml");
|
||||
if (!dumpXml && !filename)
|
||||
{
|
||||
printf("There are some optional commandline arguments for this demo:\n");
|
||||
printf("Load another .bullet file instead of testFile.bullet:\n");
|
||||
printf("--filename=testfile.bullet\n");
|
||||
printf("Dump the imported .bullet file to XML\n");
|
||||
printf("--dump_xml\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLDebugDrawer gDebugDrawer;
|
||||
#ifdef USE_AMD_OPENCL
|
||||
|
||||
@@ -93,6 +110,14 @@ int main(int argc,char** argv)
|
||||
|
||||
|
||||
SerializeDemo serializeDemo;
|
||||
|
||||
int mode = 0;
|
||||
if (dumpXml)
|
||||
mode |=bParse::FD_VERBOSE_EXPORT_XML;
|
||||
if (filename)
|
||||
serializeDemo.setFileName(filename);
|
||||
serializeDemo.setVerboseMode(mode);
|
||||
|
||||
serializeDemo.initPhysics();
|
||||
serializeDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user