Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-02 22:55:30 +0000
committerStijn Buys <ingar@osirion.org>2008-03-02 22:55:30 +0000
commite379b1bfeb231716e07f0e4ae9ef024be9bfd08f (patch)
tree6258754959e820a9a94726a4b1a119c301581111 /src/render
parent6e08b92bd4f3e32fdf550f0a3e950e3101a1b06f (diff)
added target_engine support
Diffstat (limited to 'src/render')
-rw-r--r--src/render/model.cc118
-rw-r--r--src/render/model.h32
2 files changed, 125 insertions, 25 deletions
diff --git a/src/render/model.cc b/src/render/model.cc
index e486d75..907958a 100644
--- a/src/render/model.cc
+++ b/src/render/model.cc
@@ -22,6 +22,15 @@ namespace render
const float MAX_BOUNDS = 8192;
const float delta = 10e-10;
+Engine::Engine(math::Vector3f const & location) :
+ engine_location(location)
+{
+}
+
+Engine::~Engine()
+{
+}
+
std::map<std::string, Model*> Model::registry;
Model::Model(std::string const & name) :
@@ -52,10 +61,13 @@ Model::Model(std::string const & name) :
using math::Vector3f;
using math::Plane3f;
- std::vector<Plane3f *> planes;
- std::string classname;
- unsigned int level = 0;
- char data[1024];
+ std::vector<Plane3f *> planes;
+ unsigned int level = 0;
+ char data[1024];
+
+ std::string class_name;
+ math::Vector3f class_origin;
+ float class_angle;
while (ifs) {
ifs.getline(data, 1023);
@@ -71,7 +83,7 @@ Model::Model(std::string const & name) :
//cout << " LEVEL +" << level << std::endl;
} else if (firstword == "}") {
//cout << " LEVEL -" << level << std::endl;
- if ((level == 2) && (classname == "worldspawn")) {
+ if ((level == 2) && (class_name == "worldspawn")) {
//cout << "brush with " << planes.size() << " faces" << std::endl;
// for every face
@@ -85,23 +97,57 @@ Model::Model(std::string const & name) :
delete (*it);
}
planes.clear();
+
+ } else if ((level == 1) && (class_name == "target_engine")) {
+ //con_debug << " engine at " << class_origin << "\n";
+ add_engine(new Engine(class_origin * model_scale));
+ }
+
+ if (level == 1) {
+ class_angle = 0;
+ class_name.clear();
+ class_origin = Vector3f(0,0,0);
}
+
level--;
+
} else if (firstword == "\"classname\"") {
- classname.clear();
- if (linestream >> classname) {
- if (classname.size() > 2) {
- classname.erase(0,1);
- classname.erase(classname.size()-1, 1);
- linestream >> classname;
- //cout << " CLASS '" << classname << "'" << std::endl;
- } else
- classname.clear();
+ class_name.clear();
+ if (linestream >> class_name) {
+ if (class_name.size() > 2) {
+ class_name.erase(0,1);
+ class_name.erase(class_name.size()-1, 1);
+ //linestream >> class_name;
+ //con_debug << " classname '" << class_name << "'" << std::endl;
+ } else {
+ class_name.clear();
+ }
} else {
//cout << " EMPTY CLASS" << std::endl;
}
+ } else if (firstword == "\"origin\"") {
+ std::string tmp;
+ char c;
+ while ( (linestream.get(c)) && (c != '"'));
+ while ( (linestream.get(c)) && (c != '"'))
+ tmp += c;
+ std::istringstream is(tmp);
+ is >> class_origin.x;
+ is >> class_origin.y;
+ is >> class_origin.z;
+ //con_debug << " origin '" << class_origin << "'" << std::endl;
+
+ } else if (firstword == "\"angle\"") {
+ std::string tmp;
+ char c;
+ while ( (linestream.get(c)) && (c != '"'));
+ while ( (linestream.get(c)) && (c != '"'))
+ tmp += c;
+ std::istringstream is(tmp);
+ is >> class_angle;
+ //con_debug << " angle '" << class_angle << "'" << std::endl;
} else if (firstword == "(") {
- if ((level == 2) && (classname == "worldspawn")) {
+ if ((level == 2) && (class_name == "worldspawn")) {
//cout << " BRUSH PLANE" << std::endl;
Vector3f p1;
Vector3f p2;
@@ -141,10 +187,15 @@ Model::~Model()
{
// delete all faces
for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
- delete(*fit);
+ delete (*fit);
}
-
model_face.clear();
+
+ // delete all engines
+ for(std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) {
+ delete (*eit);
+ }
+ model_engine.clear();
}
void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes)
@@ -345,7 +396,7 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
Face *mf = new Face(n);
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
- mf->add_vertex(*(*it));
+ mf->add_vertex(*(*it) * model_scale);
}
//con_debug << "adding face\n";
@@ -367,15 +418,42 @@ void Model::add_face(Face *face)
model_face.push_back(face);
}
-void Model::draw()
+void Model::add_engine(Engine *engine)
{
- gl::scale(model_scale, model_scale, model_scale);
+ model_engine.push_back(engine);
+}
+
+void Model::draw(core::Entity const * entity)
+{
+ //gl::scale(model_scale, model_scale, model_scale);
+ render::gl::color(entity->color());
// draw all faces
for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
(*fit)->draw();
}
+}
+void Model::draw(core::EntityControlable const * entity)
+{
+ // draw the model
+ draw((core::Entity *) entity);
+
+ // draw engines
+ // all engines are assumed to point to the rear
+ if(model_engine.size() && entity->thrust()) {
+
+ gl::color(1.0f,0 ,0 );
+ gl::begin(gl::Lines);
+
+ for(std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++)
+ {
+ math::Vector3f const & v = (*eit)->location();
+ gl::vertex(v);
+ gl::vertex(v.x - 0.0625f*entity->thrust(), v.y, v.z);
+ }
+ gl::end();
+ }
}
Model *Model::find(std::string const & name)
diff --git a/src/render/model.h b/src/render/model.h
index ab6207e..dfde809 100644
--- a/src/render/model.h
+++ b/src/render/model.h
@@ -10,11 +10,25 @@
#include <map>
#include <list>
-#include "render/face.h"
#include "math/plane3f.h"
+#include "core/entity.h"
+#include "render/face.h"
namespace render {
+/// a spacecraft engine
+class Engine
+{
+public:
+ Engine(math::Vector3f const & location);
+ ~Engine();
+
+ inline math::Vector3f const & location() const { return engine_location; }
+
+private:
+ math::Vector3f engine_location;
+};
+
/// a 3D model contains a list of faces
class Model
{
@@ -26,13 +40,18 @@ public:
/// the name of the model
inline std::string const & name() const { return model_name; }
- void add_face(Face *face);
-
/// the Model registry
static std::map<std::string, Model*> registry;
- /// draw the model
- void draw();
+ /// draw the model for an entity
+ /** This will not draw attached engines, turrents and cannons
+ */
+ void draw(core::Entity const * entity);
+
+ /// draw the model for a controlable enity
+ /** This will draw all attached engines, turrents and cannons
+ */
+ void draw(core::EntityControlable const * entity);
/* ---- static functions for the Model registry -------------------- */
@@ -47,8 +66,11 @@ public:
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
+ void add_engine(Engine *engine);
+ void add_face(Face *face);
std::list<Face *> model_face;
+ std::list<Engine *> model_engine;
std::string model_name;
float model_scale;