converted Engine to use PhyObj for loading PHY files
git-svn-id: svn://anubis/anaglym/trunk@240 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
cfa0ac5822
commit
9d9c16f3ad
88
Engine.cc
88
Engine.cc
@ -3,6 +3,7 @@
|
||||
#include "anaglym.h"
|
||||
#include "Engine.h"
|
||||
#include "Video.h"
|
||||
#include "PhyObj/PhyObj.h"
|
||||
#include "sdl_keymap.h"
|
||||
#include <lua.hpp>
|
||||
#include <stdlib.h> /* exit() */
|
||||
@ -30,7 +31,6 @@ using namespace std;
|
||||
#define doClearHandler(event) \
|
||||
do { EVENT_PRESENT_FLAG(event) = false; } while(0)
|
||||
|
||||
#define WHITESPACE " \t\r\n\f"
|
||||
#define HOOK_TIMEOUT 10000u
|
||||
#define HOOK_STEPS 250000000
|
||||
#define FONT_NAME "FreeSans.ttf"
|
||||
@ -41,25 +41,6 @@ using namespace std;
|
||||
Engine * g_engine;
|
||||
|
||||
/* static helper 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;
|
||||
}
|
||||
|
||||
static void cross_product(dVector3 result, dVector3 first, dVector3 second)
|
||||
{
|
||||
result[0] = first[1] * second[2] - first[2] * second[1];
|
||||
@ -549,7 +530,7 @@ int Engine::loadModel(const string & name, bool static_data, float scale)
|
||||
Engine::Object * engine_obj = getObject(id);
|
||||
if (engine_obj != NULL)
|
||||
{
|
||||
engine_obj->loadPhy(phys_path);
|
||||
engine_obj->loadPhy(m_fileLoader, phys_path);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
@ -1427,61 +1408,30 @@ void Engine::Object::render()
|
||||
checkGLError();
|
||||
}
|
||||
|
||||
void Engine::Object::loadPhy(const FileLoader::Path & path)
|
||||
void Engine::Object::loadPhy(FileLoader * fl, const FileLoader::Path & path)
|
||||
{
|
||||
FileLoader::Buffer buff = g_engine->m_fileLoader->load(path);
|
||||
if (buff.size <= 0)
|
||||
return;
|
||||
string str(buff.data, buff.size);
|
||||
stringstream istr(str, ios_base::in);
|
||||
while (!istr.eof())
|
||||
PhyObj po;
|
||||
po.load(fl, path);
|
||||
for (int i = 0, sz = po.getNumGeoms(); i < sz; i++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (type == "cube")
|
||||
refptr<PhyObj::Geom> geom = po.getGeom(i);
|
||||
refptr< vector<float> > args = geom->getArgs();
|
||||
switch (geom->getType())
|
||||
{
|
||||
case PhyObj::BOX:
|
||||
m_ode_object->addBox(args);
|
||||
}
|
||||
else if (type == "sphere")
|
||||
{
|
||||
break;
|
||||
case PhyObj::SPHERE:
|
||||
m_ode_object->addSphere(args);
|
||||
}
|
||||
else if (type == "capsule")
|
||||
{
|
||||
break;
|
||||
case PhyObj::CAPSULE:
|
||||
m_ode_object->addCapsule(args);
|
||||
}
|
||||
else if (type == "plane")
|
||||
{
|
||||
break;
|
||||
case PhyObj::PLANE:
|
||||
m_ode_object->addPlane(args);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_ode_object->finalize();
|
||||
|
2
Engine.h
2
Engine.h
@ -36,7 +36,7 @@ class Engine
|
||||
{
|
||||
m_ode_object->getPosition(x, y, z);
|
||||
}
|
||||
void loadPhy(const FileLoader::Path & path);
|
||||
void loadPhy(FileLoader * fl, const FileLoader::Path & path);
|
||||
void setVisible(bool visible) { m_is_visible = visible; }
|
||||
bool getVisible() { return m_is_visible; }
|
||||
void addForce(dReal fx, dReal fy, dReal fz)
|
||||
|
6
Makefile
6
Makefile
@ -55,7 +55,7 @@ endif
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS) wfobj/WFObj.o OdeWorld/OdeWorld.o TextureCache/TextureCache.o
|
||||
$(TARGET): $(OBJS) wfobj/WFObj.o OdeWorld/OdeWorld.o PhyObj/PhyObj.o TextureCache/TextureCache.o
|
||||
$(CXX) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
ag_lua.c: ag.lua
|
||||
@ -69,6 +69,10 @@ wfobj/WFObj.o:
|
||||
OdeWorld/OdeWorld.o:
|
||||
$(MAKE) -C OdeWorld
|
||||
|
||||
.PHONY: PhyObj/PhyObj.o
|
||||
PhyObj/PhyObj.o:
|
||||
$(MAKE) -C PhyObj
|
||||
|
||||
.PHONY: TextureCache/TextureCache.o
|
||||
TextureCache/TextureCache.o:
|
||||
$(MAKE) -C TextureCache
|
||||
|
Loading…
x
Reference in New Issue
Block a user