Home › Forums › GAMES在线课程(现代计算机图形学入门)讨论区 › 提高部分测试问题 › Reply To: 提高部分测试问题
我写了一个新的命令行parser部分,测起来就比较方便了。
while (parsePos < argc)
{
std::string arg = std::string(argv[parsePos]);
if (arg == "-r")
{
if (parsePos + 1 >= argc)
{
std::cerr << "-r option error" << std::endl;
std::cerr << "Usage: " << argv[0] << " -r angle [-a axisX axisy axisZ] [filename.png]" << std::endl;
exit(-1);
}
angle = std::stof(argv[parsePos + 1]);
parsePos += 2;
}
else if (arg == "-a")
{
if (parsePos + 3 >= argc)
{
std::cerr << "-a option error" << std::endl;
std::cerr << "Usage: " << argv[0] << " -r angle [-a axisX axisy axisZ] [filename.png]" << std::endl;
exit(-1);
}
raxis.x() = std::stof(argv[parsePos + 1]);
raxis.y() = std::stof(argv[parsePos + 2]);
raxis.z() = std::stof(argv[parsePos + 3]);
parsePos += 4;
}
else if (arg.rfind(".png") == arg.size() - 4)
{
command_line = true;
filename = arg;
parsePos += 1;
}
else
{
std::cerr << "Invalid option or filename: " << arg << std::endl;
std::cerr << "Usage: " << argv[0] << " -r angle [-a axisX axisy axisZ] [filename.png]" << std::endl;
exit(-1);
}
}