Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r--src/render/draw.cc225
1 files changed, 80 insertions, 145 deletions
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);