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-11-15 19:24:55 +0000
committerStijn Buys <ingar@osirion.org>2008-11-15 19:24:55 +0000
commit28ba97bdd8fb6ca352dc49dba01a66bd155ad523 (patch)
treeeb4abd0505eb842e15201783529814bda1ae6e76 /src/render
parent1f0dbeeabdffff096908473168898c5fa63bcff0 (diff)
entity extensions
Diffstat (limited to 'src/render')
-rw-r--r--src/render/Makefile.am7
-rw-r--r--src/render/camera.cc23
-rw-r--r--src/render/draw.cc225
-rw-r--r--src/render/dust.cc4
-rw-r--r--src/render/render.cc8
-rw-r--r--src/render/render.h7
-rw-r--r--src/render/renderext.cc114
-rw-r--r--src/render/renderext.h45
8 files changed, 269 insertions, 164 deletions
diff --git a/src/render/Makefile.am b/src/render/Makefile.am
index 7919ee2..4054490 100644
--- a/src/render/Makefile.am
+++ b/src/render/Makefile.am
@@ -10,6 +10,7 @@ endif
librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@
librender_la_LIBADD = $(top_builddir)/src/math/libmath.la
librender_la_SOURCES = camera.cc draw.cc dust.cc gl.cc image.cc jpgfile.cc \
- pngfile.cc render.cc screenshot.cc state.cc text.cc textures.cc tgafile.cc
-noinst_HEADERS = camera.h draw.h dust.h gl.h image.h render.h text.h textures.h \
- tgafile.h pngfile.h jpgfile.h screenshot.h state.h
+ pngfile.cc render.cc renderext.cc screenshot.cc state.cc text.cc textures.cc \
+ tgafile.cc
+noinst_HEADERS = camera.h draw.h dust.h gl.h image.h jpgfile.h pngfile.h \
+ render.h renderext.h screenshot.h state.h text.h textures.h tgafile.h
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 875b147..c136375 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -98,10 +98,7 @@ void Camera::set_mode(Mode newmode) {
// switch camera to Track mode
camera_mode = Track;
if (core::localcontrol()) {
- if (core::localcontrol()->state())
- camera_axis.assign(core::localcontrol()->state()->axis());
- else
- camera_axis.assign(core::localcontrol()->axis());
+ camera_axis.assign(core::localcontrol()->axis());
}
break;
@@ -242,8 +239,8 @@ void Camera::frame(float seconds)
}
} else {
- camera_target.assign(core::localcontrol()->state()->location());
- target_axis.assign(core::localcontrol()->state()->axis());
+ camera_target.assign(core::localcontrol()->location());
+ target_axis.assign(core::localcontrol()->axis());
distance = core::localcontrol()->radius();
if (mode() == Track) {
@@ -306,14 +303,12 @@ void Camera::frame(float seconds)
camera_axis.assign(target_axis);
- if (core::localcontrol()->state()) {
- if (core::localcontrol()->model()) {
- camera_target += (core::localcontrol()->model()->maxbbox().x+0.05) *
- core::localcontrol()->state()->axis().forward();
- } else {
- camera_target += (core::localcontrol()->radius() + 0.05) *
- core::localcontrol()->state()->axis().forward();
- }
+ if (core::localcontrol()->model()) {
+ camera_target += (core::localcontrol()->model()->maxbbox().x+0.05) *
+ core::localcontrol()->axis().forward();
+ } else {
+ camera_target += (core::localcontrol()->radius() + 0.05) *
+ core::localcontrol()->axis().forward();
}
distance = 0.0f;
}
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 2975ecb..4f58f3d 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -41,10 +41,6 @@ math::Vector3f v5(1, 1, -1);
math::Vector3f v6(-1, 1, -1);
math::Vector3f v7(-1, -1, -1);
-const float drawdistance = 256.0f;
-const float drawfxdistance = 64.0f;
-const float farplane = 1016.0f;
-
core::Zone *zone = 0;
float zone_light[4]; // locaton of the zone light
math::Color zone_color; // color of the zone light
@@ -75,115 +71,45 @@ void pass_prepare(float seconds)
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
- // load entity models and light flare textures
- if (!entity->model() && entity->modelname().c_str()[0]) {
- entity->set_modelname(entity->modelname());
+ if (!ext_render(entity)) {
+ new RenderExt(entity);
}
-
- if (entity->model()) {
- model::Model *model = entity->model();
+ entity->extension((size_t) core::Extension::Render)->frame(seconds);
- for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) {
- Light *light = (*lit);
+ // globes
+ if (entity->type() == core::Entity::Globe) {
+ core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
- // load light texture
- std::stringstream flarename;
- flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare();
- light->render_texture = Textures::load(flarename.str());
+ // add the globe to the globes list
+ if (globe->visible()) {
+ globes_list[ext_render(globe)->distance()] = globe;
}
- for(Model::Engines::iterator eit = model->engines().begin(); eit != model->engines().end(); eit++) {
- Engine *engine = (*eit);
-
- if (!engine->flare()) engine->engine_flare = 1;
-
- // load engine texture
- std::stringstream flarename;
- flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << engine->flare();
- engine->render_texture = Textures::load(flarename.str());
- }
-
- for (Model::Flares::iterator flit = model->flares().begin(); flit != model->flares().end(); flit++) {
- Flare *flare = (*flit);
-
- // load flare texture
- std::stringstream flarename;
- flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << flare->flare();
- flare->render_texture = Textures::load(flarename.str());
- }
- }
-
- entity->state()->state_visible = entity->visible();
+ // add level lights
+ if (flag_is_set(globe->flags(), core::Entity::Bright)) {
- if ((entity->type() == core::Entity::Controlable)) {
- if (static_cast<core::EntityDynamic *>(entity)->eventstate() == core::Entity::Docked) {
- entity->state()->state_visible = false;
- }
- }
+ // bright globes set level light
+ GLfloat diffuse_light[4];
+ GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- entity->state()->state_detailvisible = false;
- entity->state()->state_targetable = false;
- entity->state()->state_distance = math::distance(Camera::eye(), entity->state()->location());
-
- if (entity->state()->visible()) {
- // globes
- if (entity->type() == core::Entity::Globe) {
- core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
-
- // add the globe to the globes list
- globes_list[globe->state()->distance()] = globe;
-
- // load globe textures
- if (!globe->render_texture && globe->texture().size()) {
- std::stringstream texname;
- texname << "textures/" << globe->texture();
- globe->render_texture = Textures::load(texname.str());
- if (!globe->render_texture)
- globe->entity_texture.clear();
- }
-
- if (flag_is_set(globe->flags(), core::Entity::Bright)) {
-
- // bright globes set level light
- GLfloat diffuse_light[4];
- GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
- GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
-
- for (size_t i=0; i <3; i++) {
- zone_light[i] = globe->location()[i];
- zone_color[i] = globe->color()[i];
- diffuse_light[i] = globe->color()[i] * 0.4;
- }
- zone_light[3] = 1.0f;
- diffuse_light[3] = 1.0f;
-
- glLightfv(GL_LIGHT1, GL_POSITION, zone_light);
- glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
- glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
- glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
- gl::enable(GL_LIGHT1);
- has_zone_light = true;
- }
-
- } else if (entity->model()) {
-
- float r = entity->model()->radius();
- math::clamp(r, 1.0f, farplane / drawfxdistance);
- if (entity->state()->distance() < drawfxdistance * r) {
- // entites within detail range
- entity->state()->state_visible = true;
- entity->state()->state_detailvisible = true;
- } else if (entity->state()->distance() < drawdistance * r && entity->state()->distance() < core::range::max) {
- // entities within drawing distance, outside detail range
- entity->state()->state_visible = true;
- entity->state()->state_detailvisible = false;
- } else {
- // out of range
- entity->state()->state_visible = false;
- entity->state()->state_detailvisible = false;
+ for (size_t i=0; i <3; i++) {
+ zone_light[i] = globe->location()[i];
+ zone_color[i] = globe->color()[i];
+ diffuse_light[i] = globe->color()[i] * 0.4;
}
+ zone_light[3] = 1.0f;
+ diffuse_light[3] = 1.0f;
+
+ glLightfv(GL_LIGHT1, GL_POSITION, zone_light);
+ glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
+ glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light);
+ gl::enable(GL_LIGHT1);
+ has_zone_light = true;
}
- }
+
+ }
}
}
@@ -265,7 +191,7 @@ void draw_globe(core::EntityGlobe *globe)
Globes have to be rendered distance sorted, closest last.
Globes behind farplane should be rendered with z-buffer writes disabled.
*/
- math::Vector3f location(globe->state()->location());
+ math::Vector3f location(globe->location());
float radius = globe->radius();
if(flag_is_set(globe->flags(), core::Entity::Bright)) {
@@ -282,10 +208,10 @@ void draw_globe(core::EntityGlobe *globe)
gl::enable(GL_TEXTURE_2D);
}
- if (globe->state()->distance() > farplane) {
+ if (ext_render(globe)->distance() > farplane) {
// globe is behind the far plane, make a fake size calculation
- location = Camera::eye() + (location - Camera::eye()) * (farplane / globe->state()->distance());
- radius *= farplane / globe->state()->distance();
+ location = Camera::eye() + (location - Camera::eye()) * (farplane / ext_render(globe)->distance());
+ radius *= farplane / ext_render(globe)->distance();
gl::depthmask(GL_FALSE);
@@ -293,7 +219,7 @@ void draw_globe(core::EntityGlobe *globe)
// move zone light
float fake_light[4];
for (size_t i=0; i < 3; i++) {
- fake_light[i] = zone_light[i] + location[i] - globe->state()->location()[i];
+ fake_light[i] = zone_light[i] + location[i] - globe->location()[i];
}
fake_light[3] = 1.0f;
glLightfv(GL_LIGHT1, GL_POSITION, fake_light);
@@ -314,9 +240,14 @@ void draw_globe(core::EntityGlobe *globe)
}
Textures::bind("bitmaps/fx/corona");
- if (globe->state()->distance() <= farplane) {
+ if (ext_render(globe)->distance() <= farplane) {
gl::depthmask(GL_FALSE);
}
+
+ //glDisableClientState(GL_VERTEX_ARRAY);
+ //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ //glDisableClientState(GL_NORMAL_ARRAY);
+
math::Color color(globe->color());
color.a = a - 0.1f;
@@ -325,30 +256,33 @@ void draw_globe(core::EntityGlobe *globe)
gl::begin(gl::Quads);
glTexCoord2f(0,1);
- gl::vertex((Camera::axis().up() - Camera::axis().left()) * radius * 2.0f);
+ gl::vertex((Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
glTexCoord2f(0,0);
- gl::vertex((Camera::axis().up() + Camera::axis().left()) * radius * 2.0f);
+ gl::vertex((Camera::axis().up() + Camera::axis().left()) * radius * 4.0f);
glTexCoord2f(1,0);
- gl::vertex((Camera::axis().up() * -1 + Camera::axis().left()) * radius * 2.0f);
+ gl::vertex((Camera::axis().up() * -1 + Camera::axis().left()) * radius * 4.0f);
glTexCoord2f(1,1);
- gl::vertex((Camera::axis().up() * -1 - Camera::axis().left()) * radius * 2.0f);
+ gl::vertex((Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
gl::end();
Stats::quads++;
+
+ //glEnableClientState(GL_VERTEX_ARRAY);
+ //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ //glEnableClientState(GL_NORMAL_ARRAY);
gl::disable(GL_BLEND);
- if (globe->state()->distance() <= farplane) {
+ if (ext_render(globe)->distance() <= farplane) {
gl::depthmask(GL_TRUE);
}
if (!globe->render_texture) {
gl::disable(GL_TEXTURE_2D);
}
}
- radius *= 0.5f;
}
- gl::multmatrix(globe->state()->axis());
+ gl::multmatrix(globe->axis());
if (globe->rotationspeed()) {
float angle = math::degrees360f(core::application()->time() * globe->rotationspeed());
@@ -359,7 +293,7 @@ void draw_globe(core::EntityGlobe *globe)
gl::pop();
- if (globe->state()->distance() > farplane) {
+ if (ext_render(globe)->distance() > farplane) {
gl::depthmask(GL_TRUE);
@@ -475,7 +409,7 @@ void draw_entity_diamond(core::Entity *entity)
gl::end();
/* ---- draw rotating body lines ---- */
- float angle = (core::application()->time() + entity->state()->fuzz() ) * 45.0f;
+ float angle = (core::application()->time() + ext_render(entity)->fuzz() ) * 45.0f;
angle = angle - 360.0f * floorf(angle / 360.0f);
gl::rotate(angle, math::Vector3f::Zaxis());
@@ -552,8 +486,8 @@ void draw_pass_default()
if (!entity->serverside() && !entity->model() && (entity->type() != core::Entity::Globe)) {
gl::push();
- gl::translate(entity->state()->location());
- gl::multmatrix(entity->state()->axis());
+ gl::translate(entity->location());
+ gl::multmatrix(entity->axis());
if (flag_is_set(entity->flags(), core::Entity::Bright)) {
gl::disable(GL_LIGHTING);
@@ -710,7 +644,7 @@ void draw_model_fragments(core::Entity *entity)
}
}
- draw_fragment(fragment, entity->state()->detailvisible());
+ draw_fragment(fragment, ext_render(entity)->detailvisible());
}
if (!use_light) {
@@ -758,10 +692,10 @@ void draw_pass_model_fragments()
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
- if (entity->model() && entity->state()->visible()) {
+ if (entity->model() && ext_render(entity)->visible()) {
gl::push();
- gl::translate(entity->state()->location());
- gl::multmatrix(entity->state()->axis());
+ gl::translate(entity->location());
+ gl::multmatrix(entity->axis());
draw_model_fragments(entity);
@@ -818,7 +752,7 @@ void draw_pass_model_fx(float elapsed)
power = false;
}
- if (entity->model() && entity->state()->detailvisible() && power) {
+ if (entity->model() && ext_render(entity)->detailvisible() && power) {
// draw model lights
for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) {
light = (*lit);
@@ -826,9 +760,9 @@ void draw_pass_model_fx(float elapsed)
// strobe frequency
t = 1.0f;
if (light->strobe())
- t = (core::application()->time() + entity->state()->fuzz() - light->offset()) * light->frequency();
+ t = (core::application()->time() + ext_render(entity)->fuzz() - light->offset()) * light->frequency();
if ((!light->strobe()) || (( t - floorf(t)) <= light->time())) {
- location.assign(entity->state()->location() + (entity->state()->axis() * light->location()));
+ location.assign(entity->location() + (entity->axis() * light->location()));
light_size = 0.0625 * light->radius();
if (current_texture != light->texture()) {
@@ -864,14 +798,14 @@ void draw_pass_model_fx(float elapsed)
// strobe frequency
t = 1.0f;
if (flare->strobe())
- t = (core::application()->time() + entity->state()->fuzz() - flare->offset()) * flare->frequency();
+ t = (core::application()->time() + ext_render(entity)->fuzz() - flare->offset()) * flare->frequency();
if ((!flare->strobe()) || (( t - floorf(t)) <= flare->time())) {
- flare_axis.assign(entity->state()->axis());
+ flare_axis.assign(entity->axis());
if (flare->angle())
flare_axis.change_direction(flare->angle());
- location.assign(entity->state()->location() + (entity->state()->axis() * flare->location()));
+ location.assign(entity->location() + (entity->axis() * flare->location()));
light_size = 0.0625 * flare->radius();
if (current_texture != flare->texture()) {
@@ -915,18 +849,18 @@ void draw_pass_model_fx(float elapsed)
}
if (u > 0) {
- t = entity->state()->state_engine_trail_offset;
+ t = ext_render(entity)->state_engine_trail_offset;
t += elapsed * 4.0f * u;
if (t > 1.0f)
t -= 1.0f;
math::clamp(t, 0.0f, 1.0f);
- entity->state()->state_engine_trail_offset = t;
+ ext_render(entity)->state_engine_trail_offset = t;
for(model::Model::Engines::iterator eit = entity->model()->engines().begin(); eit != entity->model()->engines().end(); eit++) {
engine = (*eit);
- location.assign(entity->state()->location() + (entity->state()->axis() * engine->location()));
+ location.assign(entity->location() + (entity->axis() * engine->location()));
engine_size = 0.0625 * engine->radius();
if (current_texture != engine->texture() ) {
@@ -935,10 +869,10 @@ void draw_pass_model_fx(float elapsed)
gl::begin(gl::Quads);
}
- quad[0].assign(entity->state()->axis().up() - entity->state()->axis().left());
- quad[1].assign(entity->state()->axis().up() + entity->state()->axis().left());
- quad[2].assign(entity->state()->axis().up() * -1 + entity->state()->axis().left());
- quad[3].assign(entity->state()->axis().up() * -1 - entity->state()->axis().left());
+ quad[0].assign(entity->axis().up() - entity->axis().left());
+ quad[1].assign(entity->axis().up() + entity->axis().left());
+ quad[2].assign(entity->axis().up() * -1 + entity->axis().left());
+ quad[3].assign(entity->axis().up() * -1 - entity->axis().left());
// assign engine color to the flare
if (!engine->noflare()){
@@ -965,7 +899,7 @@ void draw_pass_model_fx(float elapsed)
gl::begin(gl::Quads);
}
color.assign(1.0f, 1.0f);
- offset.assign(entity->state()->axis().forward() * engine_size);
+ offset.assign(entity->axis().forward() * engine_size);
if (t > 0)
location -= offset * t;
@@ -1010,7 +944,7 @@ void draw_pass_model_fx(float elapsed)
}
-void draw_pass_model_corona()
+void draw_pass_model_radius()
{
if (!(r_radius && r_radius->value()))
return;
@@ -1018,9 +952,9 @@ void draw_pass_model_corona()
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
- if (entity->model() && entity->state()->visible()) {
+ if (entity->model() && ext_render(entity)->visible()) {
gl::push();
- gl::translate(entity->state()->location());
+ gl::translate(entity->location());
math::Color color = entity->color();
color.a = 0.25f;
draw_sphere(color, entity->model()->radius());
@@ -1094,17 +1028,17 @@ void draw(float seconds)
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
- gl::enable(GL_DEPTH_TEST);
+ gl::disable(GL_DEPTH_TEST);
gl::depthmask(GL_FALSE); // disable depth buffer writing
draw_pass_sky(); // draw the skysphere
gl::depthmask(GL_TRUE); // enable writing to the depth buffer
+ gl::enable(GL_DEPTH_TEST);
gl::enable(GL_CULL_FACE); // enable culling
gl::enable(GL_COLOR_MATERIAL); // enable color tracking
@@ -1112,6 +1046,7 @@ void draw(float seconds)
//gl::enable(GL_RESCALE_NORMAL); // rescale normals by the transformation matrix scale factor
gl::enable(GL_NORMALIZE);
+
draw_pass_globes(); // draw globes
draw_pass_default(); // draw entities without model
@@ -1140,7 +1075,7 @@ void draw(float seconds)
gl::enable(GL_LIGHTING);
gl::enable(GL_RESCALE_NORMAL);
- draw_pass_model_corona(); // draw entity radius
+ draw_pass_model_radius(); // draw entity radius
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
diff --git a/src/render/dust.cc b/src/render/dust.cc
index 81d40fb..4b74ef9 100644
--- a/src/render/dust.cc
+++ b/src/render/dust.cc
@@ -120,13 +120,13 @@ void Dust::draw(math::Color const &dustcolor)
float dsquare = 0;
for (size_t j = 0; j < 3; j++) {
dsquare += (core::localcontrol()->location()[j] - dust[i*3+j]) * (core::localcontrol()->location()[j] - dust[i*3+j]);
- v[j] = dust[i*3+j] - core::localcontrol()->state()->axis().forward()[j] * traillength;
+ v[j] = dust[i*3+j] - core::localcontrol()->axis().forward()[j] * traillength;
}
if (dsquare > (core::localcontrol()->radius() + DUSTDISTANCE)*(core::localcontrol()->radius() + DUSTDISTANCE)) {
for (size_t j = 0; j < 3; j++) {
dust[i*3+j] = core::localcontrol()->location()[j] + (math::randomf(2) - 1) * (DUSTDISTANCE + core::localcontrol()->radius());
- v[j] = dust[i*3+j] - core::localcontrol()->state()->axis().forward()[j] * traillength;
+ v[j] = dust[i*3+j] - core::localcontrol()->axis().forward()[j] * traillength;
}
}
diff --git a/src/render/render.cc b/src/render/render.cc
index 81237dc..ab3b751 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -118,6 +118,10 @@ void unload()
globe->render_texture = 0;
}
}
+
+ if (ext_render(entity)) {
+ delete ext_render(entity);
+ }
}
}
@@ -143,6 +147,10 @@ void clear()
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
globe->render_texture = 0;
}
+
+ if (ext_render(entity)) {
+ delete ext_render(entity);
+ }
}
// clear model refistry
diff --git a/src/render/render.h b/src/render/render.h
index 4317540..422e521 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -17,6 +17,7 @@
#include "render/gl.h"
#include "render/text.h"
#include "render/textures.h"
+#include "render/renderext.h"
namespace render {
@@ -44,6 +45,12 @@ namespace render {
extern model::VertexArray *vertexarray;
+
+ inline RenderExt *ext_render(core::Entity *entity) { return static_cast<RenderExt *>(entity->extension((size_t)core::Extension::Render)); }
+
+ const float drawdistance = 256.0f;
+ const float drawfxdistance = 64.0f;
+ const float farplane = 1016.0f;
}
diff --git a/src/render/renderext.cc b/src/render/renderext.cc
new file mode 100644
index 0000000..ffe462f
--- /dev/null
+++ b/src/render/renderext.cc
@@ -0,0 +1,114 @@
+/*
+ render/renderext.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include <sstream>
+#include <iomanip>
+
+#include "math/functions.h"
+#include "core/range.h"
+#include "model/model.h"
+#include "render/renderext.h"
+#include "render/render.h"
+#include "render/textures.h"
+
+namespace render
+{
+
+RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Render, entity)
+{
+ state_visible = false;
+ state_detailvisible = false;
+ state_fuzz = math::randomf();
+
+ state_engine_trail_offset = 0;
+
+ using namespace model;
+
+ if (entity->model()) {
+ model::Model *model = entity->model();
+
+ for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) {
+ Light *light = (*lit);
+
+ // load light texture
+ std::stringstream flarename;
+ flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << light->flare();
+ light->render_texture = Textures::load(flarename.str());
+ }
+
+ for(Model::Engines::iterator eit = model->engines().begin(); eit != model->engines().end(); eit++) {
+ Engine *engine = (*eit);
+
+ if (!engine->flare()) engine->engine_flare = 1;
+
+ // load engine texture
+ std::stringstream flarename;
+ flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << engine->flare();
+ engine->render_texture = Textures::load(flarename.str());
+ }
+
+ for (Model::Flares::iterator flit = model->flares().begin(); flit != model->flares().end(); flit++) {
+ Flare *flare = (*flit);
+
+ // load flare texture
+ std::stringstream flarename;
+ flarename << "bitmaps/fx/flare" << std::setfill('0') << std::setw(2) << flare->flare();
+ flare->render_texture = Textures::load(flarename.str());
+ }
+ } else if (entity->type() == core::Entity::Globe) {
+ core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
+
+ // load globe textures
+ if (!globe->render_texture && globe->texture().size()) {
+ std::stringstream texname;
+ texname << "textures/" << globe->texture();
+ globe->render_texture = Textures::load(texname.str());
+ if (!globe->render_texture)
+ globe->entity_texture.clear();
+ }
+ }
+}
+
+RenderExt::~RenderExt()
+{
+}
+
+void RenderExt::frame(float elapsed)
+{
+ state_distance = math::distance(Camera::eye(), entity()->location());
+
+ state_visible = entity()->visible();
+ state_detailvisible = false;
+
+ if ((entity()->type() == core::Entity::Controlable)) {
+ if (static_cast<core::EntityDynamic *>(entity())->eventstate() == core::Entity::Docked) {
+ state_visible = false;
+ }
+ }
+
+ if (state_visible && entity()->model()) {
+ float r = entity()->model()->radius();
+ math::clamp(r, 1.0f, farplane / drawfxdistance);
+ if (distance() < drawfxdistance * r) {
+ // entity within detail range
+ state_visible = true;
+ state_detailvisible = true;
+ } else if ((distance() < drawdistance * r) && (distance() < core::range::max)) {
+ // entity within drawing distance, outside detail range
+ state_visible = true;
+ state_detailvisible = false;
+ } else {
+ // entity out of range
+ state_visible = false;
+ state_detailvisible = false;
+ }
+ }
+
+}
+
+} // namespace render
+
+
diff --git a/src/render/renderext.h b/src/render/renderext.h
new file mode 100644
index 0000000..eafa707
--- /dev/null
+++ b/src/render/renderext.h
@@ -0,0 +1,45 @@
+/*
+ render/renderext.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_RENDER_RENDEREXT_H__
+#define __INCLUDED_RENDER_RENDEREXT_H__
+
+#include "core/extension.h"
+
+namespace render
+{
+
+/// the render extension of an entity
+class RenderExt :public core::Extension {
+public:
+ RenderExt(core::Entity *entity);
+ ~RenderExt();
+
+ virtual void frame(float elapsed);
+
+ inline bool visible() const { return state_visible; }
+ inline bool detailvisible() const { return state_detailvisible; }
+
+ inline float fuzz() const { return state_fuzz; }
+
+ /// distance to the camera
+ inline float distance() const { return state_distance; }
+
+ // FIXME
+ float state_engine_trail_offset;
+
+private:
+ bool state_visible;
+ bool state_detailvisible;
+
+ float state_fuzz;
+ float state_distance;
+};
+
+} // namespace render
+
+#endif // __INCLUDED_RENDER_RENDEREXT_H__
+