blob: 5b6f3b470149af397c4ef3f784655308926fd489 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
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() && entity->modelname().size()) {
entity->set_modelname(entity->modelname());
if (!entity->model())
entity->set_modelname("");
}
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());
}
if ((entity->type() == core::Entity::Controlable) && entity->model()->engines().size()) {
size_t trail_texure = Textures::load("bitmaps/fx/circle00");
for(Model::Engines::iterator eit = model->engines().begin(); eit != model->engines().end(); eit++) {
Engine *engine = (*eit);
// add trail particles
math::Color c;
ParticleStream *p = new ParticleStream(engine->location(), c, 0.0625 * engine->radius(), trail_texure, static_cast<core::EntityControlable *>(entity), true);
state_particles.push_back(p);
}
}
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()
{
for (Particles::iterator it = state_particles.begin(); it != state_particles.end(); it++) {
delete (*it);
}
state_particles.clear();
}
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
|