Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-09 18:40:31 +0000
committerStijn Buys <ingar@osirion.org>2008-03-09 18:40:31 +0000
commit517d35b2bbaeb3ee4b7e29301cd41bb58628bf3e (patch)
tree5473c128e64029b35ecfe22c9e48628c02af5407 /src/core
parent289bf4b622b95b794e438ac257d75ea437e3e023 (diff)
parse of light entities in models
Diffstat (limited to 'src/core')
-rw-r--r--src/core/model.cc48
-rw-r--r--src/core/model.h22
2 files changed, 67 insertions, 3 deletions
diff --git a/src/core/model.cc b/src/core/model.cc
index 52f0dde..da179e5 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -21,6 +21,16 @@ namespace core
const float MAX_BOUNDS = 8192;
const float delta = 10e-10;
+/* ---------- core::Light ------------------------------------------ */
+
+Light::Light(math::Vector3f const & location, math::Color const & color) :
+ light_location(location),
+ light_color(color)
+{}
+
+Light::~Light()
+{}
+
/* ---------- core::Engine ------------------------------------------ */
Engine::Engine(math::Vector3f const & location) :
@@ -102,6 +112,7 @@ Model::Model(std::string const & name) :
std::string class_name;
math::Vector3f class_origin;
float class_angle;
+ math::Color class_color;
while (ifs) {
ifs.getline(data, 1023);
@@ -113,6 +124,12 @@ Model::Model(std::string const & name) :
//cout << " COMMENT!" << std::endl;
continue;
} else if (firstword == "{") {
+ if (!level) {
+ class_angle = 0;
+ class_name.clear();
+ class_origin = math::Vector3f(0,0,0);
+ class_color = math::Color(1, 1, 1);
+ }
level ++;
//cout << " LEVEL +" << level << std::endl;
} else if (firstword == "}") {
@@ -135,6 +152,8 @@ Model::Model(std::string const & name) :
} else if ((level == 1) && (class_name == "target_engine")) {
//con_debug << " engine at " << class_origin << "\n";
add_engine(new Engine(class_origin * model_scale));
+ } else if ((level == 1) && (class_name == "light")) {
+ add_light(new Light(class_origin * model_scale, class_color));
}
if (level == 1) {
@@ -170,7 +189,18 @@ Model::Model(std::string const & name) :
is >> class_origin.y;
is >> class_origin.z;
//con_debug << " origin '" << class_origin << "'" << std::endl;
-
+
+ } else if (firstword == "\"_color\"") {
+ std::string tmp;
+ char c;
+ while ((linestream.get(c)) && (c != '"'));
+ while ((linestream.get(c)) && (c != '"'))
+ tmp += c;
+ std::istringstream is(tmp);
+ is >> class_color.r;
+ is >> class_color.g;
+ is >> class_color.b;
+
} else if (firstword == "\"angle\"") {
std::string tmp;
char c;
@@ -180,6 +210,7 @@ Model::Model(std::string const & name) :
std::istringstream is(tmp);
is >> class_angle;
//con_debug << " angle '" << class_angle << "'" << std::endl;
+
} else if (firstword == "(") {
if ((level == 2) && (class_name == "worldspawn")) {
//cout << " BRUSH PLANE" << std::endl;
@@ -234,6 +265,12 @@ Model::~Model()
delete(*eit);
}
model_engine.clear();
+
+ // delete all lights
+ for (std::list<Light *>::iterator lit = model_light.begin(); lit != model_light.end(); lit++) {
+ delete (*lit);
+ }
+ model_light.clear();
}
void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes)
@@ -500,6 +537,11 @@ void Model::add_engine(Engine *engine)
model_engine.push_back(engine);
}
+void Model::add_light(Light *light)
+{
+ model_light.push_back(light);
+}
+
Model *Model::find(std::string const & name)
{
std::map<std::string, Model*>::iterator it = registry.find(name);
@@ -531,7 +573,9 @@ void Model::clear()
void Model::list()
{
for (std::map<std::string, Model*>::iterator mit = registry.begin(); mit != registry.end(); mit++) {
- con_print << " " << (*mit).second->model_name << " " << (*mit).second->model_face.size() << " polys\n";
+ con_print << " " << (*mit).second->model_name << " " << (*mit).second->model_face.size() << " polys "
+ << (*mit).second->model_engine.size() << " engines "
+ << (*mit).second->model_light.size() << " lights\n";
}
con_print << registry.size() << " registered models" << std::endl;
}
diff --git a/src/core/model.h b/src/core/model.h
index b273c46..013edcc 100644
--- a/src/core/model.h
+++ b/src/core/model.h
@@ -58,6 +58,23 @@ private:
math::Vector3f engine_location;
};
+/// an exterior light
+class Light
+{
+public:
+ Light(math::Vector3f const & location, math::Color const & color);
+ ~Light();
+
+ inline math::Vector3f const & location() const { return light_location; }
+
+ inline math::Color const & color() const { return light_color; };
+
+private:
+ math::Vector3f light_location;
+ math::Color light_color;
+};
+
+
/// a 3D model contains a list of faces
class Model
{
@@ -94,17 +111,20 @@ public:
/// list of Engines
std::list<Engine *> model_engine;
+
+ /// list of Lights
+ std::list<Light *> model_light;
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
void add_engine(Engine *engine);
void add_face(Face *face);
+ void add_light(Light *light);
std::string model_name;
float model_scale;
bool model_valid;
-
};
}