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>2010-10-30 12:38:41 +0000
committerStijn Buys <ingar@osirion.org>2010-10-30 12:38:41 +0000
commit37a8c7aa64bdded36f452e6f95c829165d44e792 (patch)
tree61b428a69222b1942db6b996ef07903bf3a7ecbb
parentdda07be1e679458aad9a82a7a2af5af13e733b32 (diff)
moved clientside thrust and power state into render::RenderExt, added engine spawnflag to func_rotate
-rw-r--r--src/model/fragment.h9
-rw-r--r--src/model/mapfile.cc8
-rw-r--r--src/model/mapfile.h1
-rw-r--r--src/render/draw.cc75
-rw-r--r--src/render/draw.h2
-rw-r--r--src/render/renderext.cc90
-rw-r--r--src/render/renderext.h41
-rwxr-xr-xsrc/ui/modelview.cc2
8 files changed, 123 insertions, 105 deletions
diff --git a/src/model/fragment.h b/src/model/fragment.h
index 9da30b0..31b7b96 100644
--- a/src/model/fragment.h
+++ b/src/model/fragment.h
@@ -113,6 +113,10 @@ public:
inline const bool transform() const {
return group_transform;
}
+
+ inline const bool engine() const {
+ return group_engine;
+ }
inline const size_t size() const {
return group_fragments.size();
@@ -128,6 +132,10 @@ public:
group_type = type;
}
+ inline void set_engine(const bool engine) {
+ group_engine = engine;
+ }
+
inline void set_location(const math::Vector3f &location) {
group_location.assign(location);
}
@@ -164,6 +172,7 @@ private:
float group_scale;
bool group_transform;
+ bool group_engine;
};
}
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 47ea354..9fbcbc5 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -150,6 +150,8 @@ MapFile::MapFile()
in_patchdef = false;
warning_q2brush = false;
+ class_engine = false;
+ class_speed = 0;
for (size_t i = 0; i < 3; i++) {
class_minbbox[i] = MAX_BOUNDS;
@@ -818,6 +820,7 @@ void MapFile::clear_bbox()
class_axis.clear();
class_speed = 0;
+ class_engine = false;
}
void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_type)
@@ -835,6 +838,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
// default rotation speed 45 degrees per second
class_speed = 45.0f;
}
+// group->set_engine(class_engine);
}
// calculate map bbox
@@ -1060,6 +1064,10 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_key_float("roll", angle)) {
mapfile.class_axis.change_roll(angle);
+ } else if (mapfile.got_key_int("spawnflags", u)) {
+ mapfile.class_engine = spawnflag_isset(u, 4);
+ continue;
+
} else if (mapfile.got_key_float("speed", mapfile.class_speed)) {
continue;
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index 75db76e..fbb594c 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -171,6 +171,7 @@ private:
math::Vector3f class_maxbbox;
math::Axis class_axis;
float class_speed;
+ bool class_engine;
Materials map_materials;
diff --git a/src/render/draw.cc b/src/render/draw.cc
index ed2c8f7..945e04b 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -565,7 +565,7 @@ void draw_fragment(const model::Fragment *fragment, bool draw_details)
void draw_model_fragments(model::Model *model,
const math::Color & color_primary, const math::Color & color_secondary,
- const bool detail, const bool power, const float thrust)
+ const float time, const bool detail, const bool power, const float thrust)
{
// default material, lighted and geometry color
const model::Material *material = 0;
@@ -588,7 +588,7 @@ void draw_model_fragments(model::Model *model,
gl::translate(group->location());
if (group->type() == model::FragmentGroup::Rotate) {
- float rotation_angle = math::degrees360f(core::application()->time() * group->speed());
+ float rotation_angle = math::degrees360f(time * group->speed());
gl::rotate(-rotation_angle, group->axis().forward());
} else {
gl::multmatrix(group->axis());
@@ -609,21 +609,9 @@ void draw_model_fragments(model::Model *model,
if (material) {
if (material->flags() & model::Material::Engine) {
- /*
- if (use_color_array) {
- glDisableClientState(GL_COLOR_ARRAY);
- use_color_array = false;
- }
- */
color.assign(model->enginecolor() * thrust);
} else if (material->flags() & model::Material::Tertiary) {
- /*
- if (use_color_array) {
- use_color_array = false;
- glDisableClientState(GL_COLOR_ARRAY);
- }
- */
if ((material->flags() & model::Material::Tertiary) == model::Material::Tertiary) {
for (size_t i = 0; i < 3; i++)
@@ -641,12 +629,7 @@ void draw_model_fragments(model::Model *model,
color.g *= material->color().g;
color.b *= material->color().b;
} else {
- /*
- if (!use_color_array) {
- glEnableClientState(GL_COLOR_ARRAY);
- use_color_array = true;
- }
- */
+
color.assign(material->color());
}
@@ -740,12 +723,6 @@ void draw_model_fragments(model::Model *model,
use_texture = false;
}
- /*
- if (!use_color_array) {
- glEnableClientState(GL_COLOR_ARRAY);
- use_color_array = true;
- }
- */
color.assign(1.0f, 0.0f, 1.0f);
}
}
@@ -775,42 +752,6 @@ void draw_model_fragments(model::Model *model,
use_texture = false;
}
- /*
- if (!use_color_array) {
- glEnableClientState(GL_COLOR_ARRAY);
- }
- */
-}
-
-void draw_model_fragments(core::Entity *entity)
-{
- model::Model *model = entity->model();
- if (!model)
- return;
-
- bool power = true;
- float thrust = 0.0f;
-
- if ((entity->type() == core::Entity::Dynamic) || (entity->type() == core::Entity::Controlable)) {
-
- int state = static_cast<core::EntityDynamic *>(entity)->state();
-
- if ((state == core::Entity::NoPower) || (state == core::Entity::Destroyed)) {
- power = false;
-
- } else if (entity->type() == core::Entity::Controlable) {
-
- core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
-
- if ((ec->state() == core::Entity::Impulse) || (ec->state() == core::Entity::ImpulseInitiate)) {
- thrust = 1.0f;
- } else {
- thrust = ec->thrust();
- }
- }
- }
-
- draw_model_fragments(model, entity->color(), entity->color_second(), ext_render(entity)->detailvisible(), power, thrust);
}
// draw bounding box
@@ -892,7 +833,15 @@ void draw_pass_model_fragments()
gl::translate(entity->location());
gl::multmatrix(entity->axis());
- draw_model_fragments(entity);
+ draw_model_fragments(
+ entity->model(),
+ entity->color(),
+ entity->color_second(),
+ ext_render(entity)->enginetime(),
+ ext_render(entity)->detailvisible(),
+ ext_render(entity)->power(),
+ ext_render(entity)->thrust()
+ );
if (r_bbox->value()) {
gl::color(entity->color());
diff --git a/src/render/draw.h b/src/render/draw.h
index 54e8507..a2b3abc 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -29,7 +29,7 @@ void draw_sphere(math::Color const & color, float radius);
/// draw a model
void draw_model_fragments(model::Model *model,
const math::Color & color_primary, const math::Color & color_secondary,
- const bool detail = true, const bool power = true, const float thrust = 0.0f);
+ const float time, const bool detail, const bool power, const float thrust);
class Stats
{
diff --git a/src/render/renderext.cc b/src/render/renderext.cc
index 989a892..197ca6d 100644
--- a/src/render/renderext.cc
+++ b/src/render/renderext.cc
@@ -8,6 +8,7 @@
#include <iomanip>
#include "math/functions.h"
+#include "core/application.h"
#include "core/range.h"
#include "model/model.h"
#include "render/renderext.h"
@@ -23,8 +24,7 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
state_visible = false;
state_detailvisible = false;
state_fuzz = math::randomf();
-
- //state_engine_trail_offset = 0;
+ state_enginetime = state_fuzz * core::application()->time();
if (!entity->model() && entity->modelname().size()) {
entity->set_modelname(entity->modelname());
@@ -56,6 +56,8 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
for (model::Model::ParticleSystems::iterator pit = model->particles().begin(); pit != model->particles().end(); pit++) {
model::Particles *particlesystem = (*pit);
+ // TODO multiple particlesystems per script
+
// load particle systems
ParticleScript *script = ParticleScript::load(particlesystem->script());
if (script) {
@@ -104,55 +106,83 @@ void RenderExt::frame(float elapsed)
state_visible = entity()->visible();
state_detailvisible = false;
state_behind = false;
+ state_power = true;
+ state_thrust = 0.0f;
if (!state_visible)
return;
- if ((entity()->type() == core::Entity::Controlable)) {
- if (static_cast<core::EntityDynamic *>(entity())->state() == core::Entity::Docked) {
+ if (entity()->type() == core::Entity::Dynamic) {
+
+ int state = static_cast<core::EntityDynamic *>(entity())->state();
+
+ if ((state == core::Entity::NoPower) || (state == core::Entity::Destroyed)) {
+ state_power = false;
+ }
+
+ state_enginetime += elapsed;
+
+ } else if ((entity()->type() == core::Entity::Controlable)) {
+
+ core::EntityControlable *controlable = static_cast<core::EntityControlable *>(entity());
+
+ if (controlable->state() == core::Entity::Docked) {
state_visible = false;
return;
}
+
+ if ((controlable->state() == core::Entity::NoPower) || (controlable->state() == core::Entity::Destroyed)) {
+ state_power = false;
+ }
+
+ if ((controlable->state() == core::Entity::Impulse) || (controlable->state() == core::Entity::ImpulseInitiate)) {
+ state_thrust = 1.0f;
+ } else {
+ state_thrust = controlable->thrust();
+ }
+
+ state_enginetime += elapsed * state_thrust;
+
+ } else {
+
+ state_enginetime += elapsed;
}
- if (!entity()->model())
- return;
+ if (entity()->model()) {
+
+ if (distance() < core::range::fxdistance) {
+ // entity within detail range
+ state_visible = true;
+ state_detailvisible = true;
- if (distance() < core::range::fxdistance) {
- // entity within detail range
- state_visible = true;
- state_detailvisible = true;
+ } else if (distance() < core::range::maxdistance) {
- } else if (distance() < core::range::maxdistance) {
+ // funky radius factor
+ float r = entity()->model()->radius();
+ math::clamp(r, entity()->model()->radius(), core::range::maxdistance / core::range::fxdistance);
- // funky radius factor
- float r = entity()->model()->radius();
- math::clamp(r, entity()->model()->radius(), core::range::maxdistance / core::range::fxdistance);
+ if (distance() < core::range::fxdistance * r) {
+ // entity within drawing distance, outside detail range
+ state_visible = true;
+ state_detailvisible = false;
- if (distance() < core::range::fxdistance * r) {
- // entity within drawing distance, outside detail range
- state_visible = true;
- state_detailvisible = false;
+ } else {
+ // entity within drawing distance, outside detail range
+ state_visible = true;
+ state_detailvisible = false;
+ }
} else {
- // entity within drawing distance, outside detail range
- state_visible = true;
+ // entity out of range
+ state_visible = false;
state_detailvisible = false;
+ return;
}
-
- } else {
- // entity out of range
- state_visible = false;
- state_detailvisible = false;
- return;
}
-
+
if (math::dotproduct(Camera::axis().forward(), entity()->location() + Camera::axis().forward() * entity()->radius() - Camera::eye()) < 0.0f) {
state_behind = true;
}
-
-
-
}
} // namespace render
diff --git a/src/render/renderext.h b/src/render/renderext.h
index ce4b2a4..b70b4a0 100644
--- a/src/render/renderext.h
+++ b/src/render/renderext.h
@@ -24,44 +24,65 @@ public:
typedef std::list<ParticleSystem *> ParticleSystems;
- virtual void frame(float elapsed);
-
- inline bool visible() const {
+ inline const bool visible() const {
return state_visible;
}
- inline bool detailvisible() const {
+ inline const bool detailvisible() const {
return state_detailvisible;
}
+ inline const bool power() const {
+ return state_power;
+ }
+
/**
- * true if the entity is behind the camera
+ * @brief returns true if the entity is behind the camera
*/
- inline bool behind() const {
+ inline const bool behind() const {
return state_behind;
}
- inline float fuzz() const {
+ inline const float fuzz() const {
return state_fuzz;
}
- /// distance to the camera
+ inline const float thrust() const {
+ return state_thrust;
+ }
+
+ inline const float enginetime() const {
+ return state_enginetime;
+ }
+
+ /**
+ * @brief distance from attached entity to camera
+ */
inline float distance() const {
return state_distance;
}
- /// particles
+ /**
+ * @brief particle systems for the attached entity
+ */
inline ParticleSystems &particles() {
return state_particles;
}
-
+
+ virtual void frame(float elapsed);
+
private:
bool state_visible;
bool state_detailvisible;
bool state_behind;
+ bool state_power;
+
float state_fuzz;
float state_distance;
+
+ float state_enginetime;
+ float state_thrust;
ParticleSystems state_particles;
};
diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc
index e756be0..1485d79 100755
--- a/src/ui/modelview.cc
+++ b/src/ui/modelview.cc
@@ -170,7 +170,7 @@ void ModelView::draw()
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
- render::draw_model_fragments(model, core::localplayer()->color(), core::localplayer()->color_second(), true, true, 0);
+ render::draw_model_fragments(model, core::localplayer()->color(), core::localplayer()->color_second(), core::application()->time(), true, true, 0.0f);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);