Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/model/Makefile.am8
-rw-r--r--src/model/flare.cc19
-rw-r--r--src/model/flare.h27
-rw-r--r--src/model/light.cc14
-rw-r--r--src/model/map.cc46
-rw-r--r--src/model/model.cc13
-rw-r--r--src/model/model.h7
-rw-r--r--src/render/draw.cc69
8 files changed, 180 insertions, 23 deletions
diff --git a/src/model/Makefile.am b/src/model/Makefile.am
index 25985bb..ba8c38b 100644
--- a/src/model/Makefile.am
+++ b/src/model/Makefile.am
@@ -1,11 +1,11 @@
METASOURCES = AUTO
-libmodel_la_SOURCES = engine.cc light.cc map.cc mapfile.cc model.cc plane.cc \
- tirangle.cc vertexarray.cc
+libmodel_la_SOURCES = engine.cc flare.cc light.cc map.cc mapfile.cc model.cc \
+ plane.cc tirangle.cc vertexarray.cc
libmodel_la_LDFLAGS = -avoid-version -no-undefined -lm
noinst_LTLIBRARIES = libmodel.la
-noinst_HEADERS = engine.h light.h map.h mapfile.h model.h plane.h triangle.h \
- vertexarray.h
+noinst_HEADERS = engine.h flare.h light.h map.h mapfile.h model.h plane.h \
+ triangle.h vertexarray.h
INCLUDES = -I$(top_srcdir)/src
diff --git a/src/model/flare.cc b/src/model/flare.cc
new file mode 100644
index 0000000..fcd36f1
--- /dev/null
+++ b/src/model/flare.cc
@@ -0,0 +1,19 @@
+/*
+ model/flare.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "model/flare.h"
+
+namespace model {
+
+Flare::Flare() : Light() {
+ flare_angle = 0;
+}
+
+Flare::~Flare()
+{
+}
+
+}
diff --git a/src/model/flare.h b/src/model/flare.h
new file mode 100644
index 0000000..3cd192c
--- /dev/null
+++ b/src/model/flare.h
@@ -0,0 +1,27 @@
+/*
+ model/flare.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_MODEL_FLARE_H__
+#define __INCLUDED_MODEL_FLARE_H__
+
+#include "model/light.h"
+
+namespace model {
+
+/// a flare is a directional light
+class Flare : public Light {
+public:
+ Flare();
+ ~Flare();
+
+ inline float angle() const { return flare_angle; }
+
+ float flare_angle;
+};
+
+}
+
+#endif // __INCLUDED_MODEL_FLARE_H__
diff --git a/src/model/light.cc b/src/model/light.cc
index f391a44..426e7fd 100644
--- a/src/model/light.cc
+++ b/src/model/light.cc
@@ -22,20 +22,6 @@ Light::Light() :
render_texture = 0;
}
-/*
-Light::Light(math::Vector3f const & location, math::Color const & color, bool strobe) :
- light_location(location),
- light_color(color)
-{
- light_strobe = strobe;
- light_radius = 1.0f;
- light_frequency = 1.0f;
- light_offset = 0.0f;
- light_time = 0.5f;
- light_flare = 0;
- render_texture = 0;
-}
-*/
Light::~Light()
{}
diff --git a/src/model/map.cc b/src/model/map.cc
index 4b78f762..6769ba8 100644
--- a/src/model/map.cc
+++ b/src/model/map.cc
@@ -30,6 +30,7 @@ Model * Map::load(std::string const &name)
Model *model = new Model(name);
Light *light = 0;
+ Flare *flare = 0;
Engine *engine = 0;
unsigned int u;
@@ -73,7 +74,48 @@ Model * Map::load(std::string const &name)
continue;
}
+
+ } else if (mapfile.got_classname("target_flare")) {
+
+ // new flare
+ flare = new Flare();
+ model->add_flare(flare);
+
+ } else if (mapfile.classname().compare("target_flare") == 0 ) {
+
+ // flare attributes
+ if (mapfile.got_key_vector3f("origin", flare->light_location)) {
+ flare->light_location *= SCALE;
+ continue;
+
+ } else if (mapfile.got_key_color("_color", flare->light_color)) {
+ continue;
+
+ } else if (mapfile.got_key_int("spawnflags", u)) {
+ flare->light_strobe = spawnflag_isset(u, 1);
+ flare->light_entity = spawnflag_isset(u, 2);
+
+ } else if (mapfile.got_key_float("radius", flare->light_radius)) {
+ flare->light_radius /= 100.0f;
+
+ } else if (mapfile.got_key_float("frequency", flare->light_frequency)) {
+ continue;
+ } else if (mapfile.got_key_float("offset", flare->light_offset)) {
+ continue;
+
+ } else if (mapfile.got_key_float("time", flare->light_time)) {
+ continue;
+
+ } else if (mapfile.got_key_int("flare", flare->light_flare)) {
+ continue;
+
+ } else if (mapfile.got_key_float("angle", flare->flare_angle)) {
+ flare->flare_angle = math::degrees360f(flare->flare_angle);
+ continue;
+
+ }
+
} else if (mapfile.got_classname("target_engine")) {
// new engine
engine = new Engine();
@@ -195,6 +237,10 @@ Model * Map::load(std::string const &name)
(*lit)->light_location -= center;
}
+ for (std::list<Flare *>::iterator flit = model->model_flare.begin(); flit != model->model_flare.end(); flit++) {
+ (*flit)->light_location -= center;
+ }
+
}
con_print << " maps/" << model->name() << ".map " << mapfile.brushes << " brushes " << model->tris()
diff --git a/src/model/model.cc b/src/model/model.cc
index cf03986..6508fdf 100644
--- a/src/model/model.cc
+++ b/src/model/model.cc
@@ -44,6 +44,12 @@ Model::~Model()
delete (*lit);
}
model_light.clear();
+
+ // delete all flares
+ for (std::list<Flare *>::iterator flit = model_flare.begin(); flit != model_flare.end(); flit++) {
+ delete (*flit);
+ }
+ model_flare.clear();
}
size_t Model::tris() const
@@ -68,6 +74,10 @@ void Model::add_light(Light *light)
model_light.push_back(light);
}
+void Model::add_flare(Flare *flare)
+{
+ model_flare.push_back(flare);
+}
Model *Model::find(std::string const & name)
{
@@ -110,7 +120,8 @@ void Model::list()
<< (*mit).second->tris() << " triangles ("
<< (*mit).second->details() << " detail) "
<< (*mit).second->model_engine.size() << " engines "
- << (*mit).second->model_light.size() << " lights\n";
+ << (*mit).second->model_light.size() << " lights "
+ << (*mit).second->model_flare.size() << " flares ";
}
con_print << registry.size() << " registered models" << std::endl;
if (VertexArray::instance())
diff --git a/src/model/model.h b/src/model/model.h
index ce288df..cb1352f 100644
--- a/src/model/model.h
+++ b/src/model/model.h
@@ -14,6 +14,7 @@
#include "math/mathlib.h"
#include "model/engine.h"
#include "model/light.h"
+#include "model/flare.h"
/// classes representing 3D geometry
namespace model
@@ -89,6 +90,12 @@ public:
/// add a light to the model
void add_light(Light *light);
+
+ /// list of flares
+ std::list<Flare *> model_flare;
+
+ /// add a flare to the model
+ void add_flare(Flare *flare);
std::string model_name;
float model_radius;
diff --git a/src/render/draw.cc b/src/render/draw.cc
index f84abe7..351b1a6 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -239,6 +239,16 @@ void pass_prepare(float seconds)
flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare();
light->render_texture = Textures::load(flarename.str());
}
+
+ for (std::list<model::Flare *>::iterator flit = entity->model()->model_flare.begin(); flit != entity->model()->model_flare.end(); flit++) {
+ model::Flare *flare = (*flit);
+
+ // load flare texture
+ // FIXME optimize
+ std::stringstream flarename;
+ flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << flare->flare();
+ flare->render_texture = Textures::load(flarename.str());
+ }
}
}
@@ -487,6 +497,57 @@ void draw_pass_model_fx()
}
}
+ // draw flares
+ for (std::list<model::Flare *>::iterator flit = entity->model()->model_flare.begin(); flit != entity->model()->model_flare.end(); flit++) {
+
+ model::Flare *flare = (*flit);
+
+ // strobe frequency
+ t = 1.0f;
+ if (flare->strobe())
+ t = (core::application()->time() + entity->state()->fuzz() - flare->offset()) * flare->frequency();
+
+ if (!flare->strobe() || (( t - floorf(t)) <= flare->time())) {
+ math::Axis flare_axis(entity->state()->axis());
+ if (flare->angle())
+ flare_axis.change_direction(flare->angle());
+
+ math::Vector3f location = entity->state()->location() + (entity->state()->axis() * flare->location());
+ float light_size = 0.0625 * flare->radius();
+
+ if (flare->render_texture != flare_texture) {
+ gl::end();
+ flare_texture = Textures::bind(flare->render_texture);
+ gl::begin(gl::Quads);
+ }
+
+ math::Color color;
+ if (flare->entity()) {
+ color.assign(entity->color());
+ } else {
+ color.assign(flare->color());
+ }
+
+ float a = dotproduct(flare_axis.forward(), camera_axis.forward());
+ if (a < -0.1f) {
+ color.a = -a - 0.1f;
+ gl::color(color);
+
+ glTexCoord2f(0,1);
+ gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size);
+ glTexCoord2f(0,0);
+ gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size);
+ glTexCoord2f(1,0);
+ gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size);
+ glTexCoord2f(1,1);
+ gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size);
+
+ Stats::quads++;
+ }
+
+ }
+ }
+
// draw model engines for Controlable entities
if (entity->type() == core::Entity::Controlable && entity->model()->model_engine.size()) {
@@ -513,13 +574,13 @@ void draw_pass_model_fx()
gl::color(color);
glTexCoord2f(0,1);
- gl::vertex(location + (camera_axis.up() - camera_axis.left()) * engine_size);
+ gl::vertex(location + (entity->state()->axis().up() - entity->state()->axis().left()) * engine_size);
glTexCoord2f(0,0);
- gl::vertex(location + (camera_axis.up() + camera_axis.left()) * engine_size);
+ gl::vertex(location + (entity->state()->axis().up() + entity->state()->axis().left()) * engine_size);
glTexCoord2f(1,0);
- gl::vertex(location + (camera_axis.up() * -1 + camera_axis.left()) * engine_size);
+ gl::vertex(location + (entity->state()->axis().up() * -1 + entity->state()->axis().left()) * engine_size);
glTexCoord2f(1,1);
- gl::vertex(location + (camera_axis.up() * -1 - camera_axis.left()) * engine_size);
+ gl::vertex(location + (entity->state()->axis().up() * -1 - entity->state()->axis().left()) * engine_size);
Stats::quads++;
}