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 /src/render
parentdda07be1e679458aad9a82a7a2af5af13e733b32 (diff)
moved clientside thrust and power state into render::RenderExt, added engine spawnflag to func_rotate
Diffstat (limited to 'src/render')
-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
4 files changed, 104 insertions, 104 deletions
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;
};