added PhyObj class files
git-svn-id: svn://anubis/misc/PhyObj@232 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
24aaa0e980
commit
11ba2db083
12
Makefile
Normal file
12
Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
TARGET := PhyObj.o
|
||||
SOURCES := $(wildcard *.cc)
|
||||
HEADERS := $(wildcard *.h)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SOURCES) $(HEADERS)
|
||||
$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCES)
|
||||
|
||||
clean:
|
||||
-rm -f *~ *.o
|
106
PhyObj.cc
Normal file
106
PhyObj.cc
Normal file
@ -0,0 +1,106 @@
|
||||
|
||||
#include "PhyObj.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
#define WHITESPACE " \t\r\n\f"
|
||||
|
||||
/********** static utility functions **********/
|
||||
static string trim(const string & orig)
|
||||
{
|
||||
string result = orig;
|
||||
size_t pos = result.find_first_not_of(WHITESPACE);
|
||||
if (pos == string::npos)
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pos > 0)
|
||||
result = result.substr(pos, result.length() - pos);
|
||||
pos = result.find_last_not_of(WHITESPACE);
|
||||
if (pos < result.length() - 1)
|
||||
result = result.substr(0, pos + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/********** PhyObj::Geom functions **********/
|
||||
PhyObj::Geom::Geom()
|
||||
{
|
||||
m_type = NONE;
|
||||
}
|
||||
|
||||
PhyObj::Geom::Geom(PhyObj::GeomType type, refptr< vector<float> > args)
|
||||
{
|
||||
m_type = type;
|
||||
m_args = args;
|
||||
}
|
||||
|
||||
|
||||
/********** PhyObj functions **********/
|
||||
void PhyObj::load(FileLoader * fileLoader, const FileLoader::Path & path)
|
||||
{
|
||||
FileLoader::Buffer buff = fileLoader->load(path);
|
||||
if (buff.size <= 0)
|
||||
return;
|
||||
string str(buff.data, buff.size);
|
||||
stringstream istr(str, ios_base::in);
|
||||
while (!istr.eof())
|
||||
{
|
||||
string line;
|
||||
getline(istr, line);
|
||||
line = trim(line);
|
||||
if (line == "" || line[0] == '#')
|
||||
continue;
|
||||
size_t pos = line.find_first_of(WHITESPACE);
|
||||
if (pos == string::npos)
|
||||
continue;
|
||||
string type = line.substr(0, pos);
|
||||
pos = line.find("\"", pos);
|
||||
if (pos == string::npos)
|
||||
continue;
|
||||
size_t pos2 = line.find("\"", pos + 1);
|
||||
if (pos2 == string::npos)
|
||||
continue;
|
||||
string name = line.substr(pos + 1, pos2 - pos - 1);
|
||||
pos = pos2 + 1;
|
||||
refptr< vector<float> > args = new vector<float>();
|
||||
for (;;)
|
||||
{
|
||||
pos = line.find_first_not_of(WHITESPACE, pos);
|
||||
if (pos == string::npos)
|
||||
break;
|
||||
pos2 = line.find_first_of(WHITESPACE, pos);
|
||||
string n = line.substr(pos, pos2 - pos);
|
||||
float f = atof(n.c_str());
|
||||
args->push_back(f);
|
||||
if (pos2 == string::npos)
|
||||
break;
|
||||
pos = pos2 + 1;
|
||||
}
|
||||
GeomType geom_type = NONE;
|
||||
if (type == "cube")
|
||||
{
|
||||
geom_type = BOX;
|
||||
}
|
||||
else if (type == "sphere")
|
||||
{
|
||||
geom_type = SPHERE;
|
||||
}
|
||||
else if (type == "capsule")
|
||||
{
|
||||
geom_type = CAPSULE;
|
||||
}
|
||||
else if (type == "plane")
|
||||
{
|
||||
geom_type = PLANE;
|
||||
}
|
||||
if (geom_type != NONE)
|
||||
{
|
||||
m_geoms.push_back(new Geom(geom_type, args));
|
||||
}
|
||||
}
|
||||
}
|
40
PhyObj.h
Normal file
40
PhyObj.h
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
#ifndef PHYOBJ_H
|
||||
#define PHYOBJ_H
|
||||
|
||||
#include "refptr/refptr.h"
|
||||
#include "FileLoader/FileLoader.h"
|
||||
#include <vector>
|
||||
|
||||
class PhyObj
|
||||
{
|
||||
public:
|
||||
/* Types */
|
||||
enum GeomType { NONE, BOX, SPHERE, PLANE, CAPSULE };
|
||||
|
||||
class Geom
|
||||
{
|
||||
public:
|
||||
/* Constructors */
|
||||
Geom();
|
||||
Geom(GeomType type, refptr< std::vector<float> > args);
|
||||
|
||||
/* Methods */
|
||||
GeomType getType() { return m_type; }
|
||||
refptr< std::vector<float> > getArgs() { return m_args; }
|
||||
|
||||
protected:
|
||||
GeomType m_type;
|
||||
refptr< std::vector<float> > m_args;
|
||||
};
|
||||
|
||||
/* Methods */
|
||||
void load(FileLoader * fileLoader, const FileLoader::Path & path);
|
||||
size_t getNumGeoms() { return m_geoms.size(); }
|
||||
refptr<Geom> getGeom(int i) { return m_geoms[i]; }
|
||||
|
||||
protected:
|
||||
std::vector< refptr<Geom> > m_geoms;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user