diff options
author | Stijn Buys <ingar@osirion.org> | 2009-08-14 11:37:10 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-08-14 11:37:10 +0000 |
commit | bab6eff9da1927a4fc1e22d97e56199c1b677670 (patch) | |
tree | 14a06a6abd5b74c8b368b992594cb2f3133ab553 /src | |
parent | 69d54b593f96c0f7e525c0dff560ca0614071cf3 (diff) |
model API cleanup, render WORLDSCALE
Diffstat (limited to 'src')
-rw-r--r-- | src/client/buymenu.cc | 2 | ||||
-rw-r--r-- | src/client/hud.cc | 2 | ||||
-rw-r--r-- | src/client/targets.cc | 6 | ||||
-rw-r--r-- | src/core/range.h | 12 | ||||
-rw-r--r-- | src/model/mapfile.cc | 71 | ||||
-rw-r--r-- | src/model/parts.cc | 16 | ||||
-rw-r--r-- | src/model/parts.h | 183 | ||||
-rw-r--r-- | src/render/camera.cc | 64 | ||||
-rw-r--r-- | src/render/camera.h | 15 | ||||
-rw-r--r-- | src/render/draw.cc | 242 | ||||
-rw-r--r-- | src/render/render.h | 4 | ||||
-rw-r--r-- | src/render/renderext.cc | 22 | ||||
-rw-r--r-- | src/render/state.cc | 14 |
13 files changed, 364 insertions, 289 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc index 79b5444..8c69a7a 100644 --- a/src/client/buymenu.cc +++ b/src/client/buymenu.cc @@ -32,7 +32,7 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent) menu_modelview = new ui::ModelView(menu_modelpane); menu_modelview->set_label("modelview"); menu_modelview->set_background(false); - menu_modelview->set_border(true); + menu_modelview->set_border(false); menu_closebutton = new ui::Button(menu_modelpane, "Close","view hide"); diff --git a/src/client/hud.cc b/src/client/hud.cc index 3d32d3a..102c445 100644 --- a/src/client/hud.cc +++ b/src/client/hud.cc @@ -117,7 +117,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) target = render::Camera::axis().transpose() * target; // calculate the intersection between the line (0,0,0)-target and the frustum front - float t = (render::Camera::frustum_front() + 0.001f) / target.x; + float t = (render::FRUSTUMFRONT + 0.001f) / target.x; Vector3f center(target *t); float cx = render::State::width() * (0.5 - center.y); diff --git a/src/client/targets.cc b/src/client/targets.cc index c634557..496f4e5 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -226,7 +226,7 @@ void func_target_center(std::string const &args) // this is essentialy the hover algorithm with the cursor in the center core::Entity *new_target = 0; - math::Vector3f center = render::Camera::eye() + render::Camera::axis().forward() * (render::Camera::frustum_front() + 0.001); + math::Vector3f center = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001); float smallest_d = -1; for (core::Zone::Content::iterator it=core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) { @@ -359,11 +359,11 @@ void frame() y = (float)(input::mouse_position_y() - render::State::height() /2) / (float)render::State::height() / render::State::aspect(); } - Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::Camera::frustum_front() + 0.001); + Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001); cursor -= render::Camera::axis().left() * x; cursor -= render::Camera::axis().up() * y; - math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::Camera::frustum_front() +0.001f)); + math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT +0.001f)); for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); diff --git a/src/core/range.h b/src/core/range.h index 5921e70..aa194bb 100644 --- a/src/core/range.h +++ b/src/core/range.h @@ -10,16 +10,20 @@ namespace core { namespace range { - /// maximal range + /// maximal visiblae range (world distance) /** This is the distance of the frustum far plane, * the maximal distance at which non-controlable entities can be drawn. * the maximal radar range for controlable entities, * and the maximal range to send entity updates */ - const float max = 1024.0f; + const float maxdistance = 1024.0f; - /// maximal visible range for controlable entities - const float visible = 512.0f; + /// maximal visible range for controlable entities (world distance) + const float maxvisible = 512.0f; + + + /// detail/fx distance (world distance) + const float fxdistance = 256.0f; } } diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 271af06..36dc536 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -920,6 +920,7 @@ Model * MapFile::load(std::string const &name) std::string modelname; math::Vector3f location; + math::Color color; typedef std::list<SubModel *> SubModelList; SubModelList submodel_list; @@ -1021,17 +1022,17 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.classname().compare("light") == 0) { // light attributes - if (mapfile.got_key_vector3f("origin", light->light_location)) { - light->light_location *= SCALE; + if (mapfile.got_key_vector3f("origin", location)) { + light->set_location(location * SCALE); continue; } else if (mapfile.got_key_color("_color", light->light_color)) { continue; } else if (mapfile.got_key_int("spawnflags", u)) { - light->light_strobe = spawnflag_isset(u, 1); - light->light_entity = spawnflag_isset(u, 2); - light->light_engine = spawnflag_isset(u, 4); + light->set_strobe(spawnflag_isset(u, 1)); + light->set_entity(spawnflag_isset(u, 2)); + light->set_engine(spawnflag_isset(u, 4)); } else if (mapfile.got_key_float("light", light->light_radius)) { light->light_radius *= LIGHTSCALE; @@ -1105,17 +1106,17 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.classname().compare("fx_flare") == 0) { // flare attributes - if (mapfile.got_key_vector3f("origin", flare->light_location)) { - flare->light_location *= SCALE; + if (mapfile.got_key_vector3f("origin", location)) { + flare->set_location(location * SCALE); continue; } else if (mapfile.got_key_color("_color", flare->light_color)) { continue; } else if (mapfile.got_key_int("spawnflags", u)) { - flare->light_strobe = spawnflag_isset(u, 1); - flare->light_entity = spawnflag_isset(u, 2); - flare->flare_engine = spawnflag_isset(u, 4); + flare->set_strobe(spawnflag_isset(u, 1)); + flare->set_entity(spawnflag_isset(u, 2)); + flare->set_engine(spawnflag_isset(u, 4)); } else if (mapfile.got_key_float("radius", flare->light_radius)) { flare->light_radius *= LIGHTSCALE; @@ -1134,30 +1135,30 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_key_float("angle", angle)) { if (angle == ANGLEUP) { - flare->flare_axis.change_pitch(90.0f); + flare->get_axis().change_pitch(90.0f); } else if (angle == ANGLEDOWN) { - flare->flare_axis.change_pitch(-90.0f); + flare->get_axis().change_pitch(-90.0f); } else { - flare->flare_axis.change_direction(angle); + flare->get_axis().change_direction(angle); } } else if (mapfile.got_key_float("direction", angle)) { - flare->flare_axis.change_direction(angle); + flare->get_axis().change_direction(angle); } else if (mapfile.got_key_float("pitch", angle)) { - flare->flare_axis.change_pitch(angle); + flare->get_axis().change_pitch(angle); } else if (mapfile.got_key_float("roll", angle)) { - flare->flare_axis.change_roll(angle); + flare->get_axis().change_roll(angle); } else if (mapfile.got_key_string("cull", str)) { aux::to_lowercase(str); if (str.compare("none") == 0) { - flare->flare_cull = CullNone; + flare->set_cull(CullNone); } else if (str.compare("back") == 0) { - flare->flare_cull = CullBack; + flare->set_cull(CullBack); } else if (str.compare("front") == 0) { - flare->flare_cull = CullFront; + flare->set_cull(CullFront); } else { mapfile.unknown_value(); } @@ -1215,31 +1216,31 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.classname().compare("fx_particles") == 0) { // particle system attributes - if (mapfile.got_key_vector3f("origin", particles->particles_location)) { - particles->particles_location *= SCALE; + if (mapfile.got_key_vector3f("origin", location)) { + particles->set_location(location * SCALE); continue; } else if (mapfile.got_key_string("script", particles->particles_script)) { continue; } else if (mapfile.got_key_float("angle", angle)) { if (angle == ANGLEUP) { - particles->particles_axis.change_pitch(90.0f); + particles->get_axis().change_pitch(90.0f); } else if (angle == ANGLEDOWN) { - particles->particles_axis.change_pitch(-90.0f); + particles->get_axis().change_pitch(-90.0f); } else { - particles->particles_axis.change_direction(angle); + particles->get_axis().change_direction(angle); } } else if (mapfile.got_key_float("direction", angle)) { - particles->particles_axis.change_direction(angle); + particles->get_axis().change_direction(angle); } else if (mapfile.got_key_float("pitch", angle)) { - particles->particles_axis.change_pitch(angle); + particles->get_axis().change_pitch(angle); } else if (mapfile.got_key_float("roll", angle)) { - particles->particles_axis.change_roll(angle); + particles->get_axis().change_roll(angle); } else if (mapfile.got_key_int("spawnflags", u)) { - particles->particles_entity = spawnflag_isset(u, 2); - particles->particles_engine = spawnflag_isset(u, 4); + particles->set_entity(spawnflag_isset(u, 2)); + particles->set_engine(spawnflag_isset(u, 4)); } else if (mapfile.got_key_float("radius", r)) { particles->set_radius(r * LIGHTSCALE); @@ -1248,11 +1249,11 @@ Model * MapFile::load(std::string const &name) aux::to_lowercase(str); if (str.compare("none") == 0) { - particles->particles_cull = CullNone; + particles->set_cull(CullNone); } else if (str.compare("back") == 0) { - particles->particles_cull = CullBack; + particles->set_cull(CullBack); } else if (str.compare("front") == 0) { - particles->particles_cull = CullFront; + particles->set_cull(CullFront); } else { mapfile.unknown_value(); } @@ -1269,15 +1270,15 @@ Model * MapFile::load(std::string const &name) // reposition docks, lights, flares and particles according to the model center for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) { - (*lit)->light_location -= mapfile.map_center; + (*lit)->get_location() -= mapfile.map_center; } for (Model::Flares::iterator flit = model->flares().begin(); flit != model->flares().end(); flit++) { - (*flit)->light_location -= mapfile.map_center; + (*flit)->get_location() -= mapfile.map_center; } for (Model::ParticleSystems::iterator pit = model->particles().begin(); pit != model->particles().end(); pit++) { - (*pit)->particles_location -= mapfile.map_center; + (*pit)->get_location() -= mapfile.map_center; } for (Model::Docks::iterator dit = model->docks().begin(); dit != model->docks().end(); dit++) { diff --git a/src/model/parts.cc b/src/model/parts.cc index d4ff20b..bcd8446 100644 --- a/src/model/parts.cc +++ b/src/model/parts.cc @@ -11,17 +11,20 @@ namespace model { /* ---- class Light ------------------------------------------------ */ Light::Light() : - light_location(), + Part(), light_color(1.0f, 1.0f, 1.0f) { light_entity = false; + light_engine = false; light_strobe = false; + light_radius = 1.0f; light_frequency = 1.0f; light_offset = 0.0f; light_time = 0.5f; + light_flare = 0; - light_engine = 0; + render_texture = 0; } @@ -32,7 +35,6 @@ Light::~Light() Flare::Flare() : Light() { - flare_engine = false; flare_cull = CullBack; } @@ -42,7 +44,7 @@ Flare::~Flare() /* ---- class Particles -------------------------------------------- */ Particles::Particles() : - particles_location() + Part() { particles_entity = false; particles_engine = false; @@ -51,16 +53,12 @@ Particles::Particles() : } Particles::Particles(math::Vector3f const & location) : - particles_location(location) + Part(location) { } Particles::~Particles() -{} - -void Particles::set_radius(const float radius) { - particles_radius = radius; } /* ---- class Dock ------------------------------------------------- */ diff --git a/src/model/parts.h b/src/model/parts.h index 3e5e74f..78ad5e4 100644 --- a/src/model/parts.h +++ b/src/model/parts.h @@ -14,6 +14,9 @@ namespace model { +/* ---- globals ---------------------------------------------------- */ + +// FIXME this should end up in material.h /** * @brief @@ -23,23 +26,82 @@ namespace model */ enum Cull { CullNone=0, CullBack=1, CullFront=2 }; +/* ---- class Part ------------------------------------------------- */ + +/** + * @brief a special part of a model + */ +class Part +{ +public: + /** + * @brief default constructor + */ + inline Part() : part_location() + { + } + + /** + * @brief constructor with location + */ + inline Part(const math::Vector3f &location) : part_location(location) + { + } + + /* ---- inspectors ----------------------------------------- */ + + /** + * @brief location of this part within the parent model + */ + inline const math::Vector3f &location() const + { + return part_location; + } + + /* ---- mutators ------------------------------------------- */ + /** + * @brief set the location within the parent model + */ + inline void set_location(const math::Vector3f location) { part_location.assign(location); } + + /** + * @brief set the location within the parent model + */ + inline void set_location(const float x, const float y, const float z) { part_location.assign(x, y, z); } + + /* ---- actors --------------------------------------------- */ + + /** + * @brief mutable reference to the location of this part within the parent model + */ + inline math::Vector3f &get_location() + { + return part_location; + } + +private: + math::Vector3f part_location; +}; + /* ---- class Light ------------------------------------------------ */ /// an exterior light -class Light +class Light : public Part { public: + /** + * @brief default constructor + */ Light(); - - Light(const math::Vector3f & location, const math::Color & color, bool strobe=false, bool engine=false); - + + /** + * @brief destructor + */ ~Light(); - inline const math::Vector3f & location() const - { - return light_location; - } - + /* ---- inspectors ----------------------------------------- */ + + /// light color inline const math::Color & color() const { return light_color; @@ -56,6 +118,12 @@ public: { return light_entity; } + + /// true if this light has engine activation + inline const bool engine() const + { + return light_engine; + } /// size of the light, default is 1.0f inline float radius() const @@ -86,32 +154,42 @@ public: { return light_flare; } - - /// true if this light has engine activation - inline const bool engine() const - { - return light_engine; - } /// render texture number inline size_t texture() const { return render_texture; } - - math::Vector3f light_location; + /* ---- mutators ------------------------------------------- */ + + /// set strobe on or off + inline void set_strobe(bool strobe) { light_strobe = strobe; } + + /** + * @brief set entity color on or off + */ + inline void set_entity(bool entity) { light_entity = entity; } + + /** + * @brief set engine activation on or off + */ + inline void set_engine(bool engine) { light_engine = engine; } + + math::Color light_color; - bool light_strobe; - bool light_entity; - bool light_engine; float light_radius; float light_frequency; float light_offset; float light_time; - + unsigned int light_flare; - + size_t render_texture; + +private: + bool light_strobe; + bool light_engine; + bool light_entity; }; /* ---- class Flare ------------------------------------------------ */ @@ -121,46 +199,47 @@ class Flare : public Light { public: Flare(); + ~Flare(); + /* ---- inspectors ----------------------------------------- */ + inline const math::Axis axis() const { return flare_axis; } - inline const bool engine() const - { - return flare_engine; - } - inline const Cull cull() const { return flare_cull; } + /* ---- mutators ------------------------------------------- */ + + inline void set_cull(const Cull cull) { flare_cull = cull; } + + /* ---- actors --------------------------------------------- */ + + /** + * @brief mutable reference to the axis + */ + inline math::Axis &get_axis() { return flare_axis; } + +private: math::Axis flare_axis; - bool flare_engine; Cull flare_cull; }; /* ---- class Particles -------------------------------------------- */ /// a particle system -class Particles +class Particles : public Part { public: Particles(); - Particles(const math::Vector3f & location); ~Particles(); - void set_radius(const float radius); - - inline const math::Vector3f & location() const - { - return particles_location; - } - inline const math::Axis &axis() const { return particles_axis; @@ -191,14 +270,36 @@ public: return particles_cull; } + /* ---- mutators ------------------------------------------- */ + + /** + * @brief set entity color on or off + */ + inline void set_entity(const bool entity) { particles_entity = entity; } + + /** + * @brief set engine activation on or off + */ + inline void set_engine(const bool engine) { particles_engine = engine; } + + inline void set_radius(const float radius) { particles_radius = radius; } + + inline void set_cull(const Cull cull) { particles_cull = cull; } + + /* ---- actors --------------------------------------------- */ + + /** + * @brief mutable reference to the axis + */ + inline math::Axis &get_axis() { return particles_axis; } + std::string particles_script; - math::Vector3f particles_location; - math::Axis particles_axis; +private: + math::Axis particles_axis; + float particles_radius; bool particles_entity; bool particles_engine; - - float particles_radius; Cull particles_cull; }; diff --git a/src/render/camera.cc b/src/render/camera.cc index 092cc26..ba82ea6 100644 --- a/src/render/camera.cc +++ b/src/render/camera.cc @@ -28,9 +28,6 @@ const float pitch_free = -30.0f; const float pitch_track = -5.0f; const float pitch_overview = -5.0f; -float Camera::camera_frustum_size = 0.5f; -float Camera::camera_frustum_front = 1.0f; - math::Vector3f Camera::camera_eye; math::Vector3f Camera::camera_target; math::Axis Camera::camera_axis; @@ -52,9 +49,6 @@ float Camera::camera_zoom; void Camera::init() { - camera_frustum_size = 0.5f; - camera_frustum_front = 1.0f; - direction_current = 0; direction_target = 0; @@ -92,9 +86,6 @@ void Camera::set_mode(Mode newmode) { target_pitch = 0.0f; distance = 0.4f; - camera_frustum_size = 0.5f; - camera_frustum_front = 1.0f; - camera_axis.clear(); if (camera_mode != Overview) @@ -296,15 +287,17 @@ void Camera::frame(float seconds) if (angle > MIN_DELTA) camera_axis.rotate(n, -angle); } -/* + if (core::localcontrol()->model()) { - camera_target -= (core::localcontrol()->model()->maxbbox().x + core::localcontrol()->model()->radius() + 0.1f) * 0.5f * camera_axis.forward(); - camera_target += (core::localcontrol()->model()->maxbbox().z + core::localcontrol()->model()->radius() + 0.1f) * 0.5f * camera_axis.up(); + camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().x); + camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().z); + } else { + camera_target -= camera_axis.forward() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius()); + camera_target += camera_axis.up() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius()); } -*/ - float f = ( camera_frustum_size/State::aspect() ); - camera_target += camera_axis.up() * math::max(f, core::localcontrol()->radius()); - distance = math::max(f, core::localcontrol()->radius()) + camera_zoom * core::localcontrol()->radius(); + + distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f; + } else if (mode() == Free) { camera_axis.assign(target_axis); @@ -321,33 +314,24 @@ void Camera::frame(float seconds) d = degrees180f(pitch_current - pitch_target); pitch_current = degrees360f(pitch_current - d * seconds); camera_axis.change_pitch(pitch_current); - /* - // set distance and location - distance = camera_zoom * core::localcontrol()->radius(); - //distance += (2.0f*core::localcontrol()->radius()) / ( camera_frustum_size/State::aspect() ); - - camera_target -= COS_PI_4 * (core::localcontrol()->model() ? core::localcontrol()->model()->maxbbox().x : core::localcontrol()->radius()) * camera_axis.forward(); - camera_target += COS_PI_4 * (core::localcontrol()->model() ? core::localcontrol()->model()->maxbbox().z : core::localcontrol()->radius()) * camera_axis.up(); camera_target += camera_frustum_size/State::aspect() * target_axis.up(); - */ - float f = ( camera_frustum_size/State::aspect() ); - distance = f + camera_zoom * core::localcontrol()->radius(); + + distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f; + } else if (mode() == Cockpit) { camera_axis.assign(target_axis); if (core::localcontrol()->model()) { - camera_target += (core::localcontrol()->model()->maxbbox().x+0.05) * + camera_target += (core::localcontrol()->model()->maxbbox().x) * core::localcontrol()->axis().forward(); } else { - camera_target += (core::localcontrol()->radius() + 0.05) * + camera_target += (core::localcontrol()->radius()) * core::localcontrol()->axis().forward(); } - distance = 0.0f; + distance = (FRUSTUMFRONT / WORLDSCALE) - 0.001f; } } - distance += camera_frustum_front; - // calculate eye position camera_eye = camera_target - (distance * camera_axis.forward()); } @@ -358,7 +342,7 @@ void Camera::frustum() gl::matrixmode(GL_PROJECTION); gl::loadidentity(); - gl::frustum(-camera_frustum_size, camera_frustum_size, -camera_frustum_size/State::aspect(), camera_frustum_size/State::aspect(), camera_frustum_front, 1023.0f); + gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE); gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); @@ -371,7 +355,10 @@ void Camera::frustum() matrix.assign(camera_axis); gl::multmatrix(matrix.transpose()); + gl::scale(4.0f, 4.0f, 4.0f); + gl::translate(-1.0f * camera_eye); + } void Camera::frustum_default(float distance, float cx, float cy) @@ -380,10 +367,11 @@ void Camera::frustum_default(float distance, float cx, float cy) gl::matrixmode(GL_PROJECTION); gl::loadidentity(); + // move eye to (cx, cy) // note: the factor 2.0f probably has to be 1.0f/frustum_size gl::translate(2.0f*(-State::width() * 0.5f + cx)/State::width() , 2.0f*(State::height() * 0.5f - cy)/State::height(), 0.0f); - gl::frustum(-camera_frustum_size, camera_frustum_size, -camera_frustum_size/State::aspect(), camera_frustum_size/State::aspect(), camera_frustum_front, 1023.0f); + gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, 1023.0f); gl::matrixmode(GL_MODELVIEW); gl::loadidentity(); @@ -426,14 +414,4 @@ void Camera::reset() set_mode(camera_mode); } -float Camera::frustum_front() -{ - return camera_frustum_front; -} - -float Camera::frustum_size() -{ - return camera_frustum_size; -} - } diff --git a/src/render/camera.h b/src/render/camera.h index 349aef8..49cba74 100644 --- a/src/render/camera.h +++ b/src/render/camera.h @@ -8,9 +8,15 @@ #define __INCLUDED_RENDER_CAMERA_H__ #include "math/mathlib.h" +#include "core/range.h" namespace render { +const float WORLDSCALE = 4.0f; +const float FARPLANE = core::range::maxdistance; +const float FRUSTUMSIZE = 0.5f; +const float FRUSTUMFRONT = 1.0f; + /// camera functions class Camera { @@ -76,20 +82,13 @@ public: /// set specified camera mode static void set_mode(Mode newmode); - /// current frustum front - static float frustum_front(); - - /// current frustum size (height); - static float frustum_size(); - private: static math::Vector3f camera_eye; static math::Vector3f camera_target; static math::Axis camera_axis; static Mode camera_mode; static Mode camera_previous_mode; - static float camera_frustum_size; - static float camera_frustum_front; + // current and target yaw angle in XZ plane, positive is looking left static float direction_current; diff --git a/src/render/draw.cc b/src/render/draw.cc index 4768b7d..a48908f 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -58,6 +58,24 @@ void pass_prepare(float seconds) { using namespace model; + // lighting settings for the default light GL_LIGHT0 + GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; + GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f }; + GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; + + for (size_t i=0; i <3; i++) { + light_position[i] = Camera::eye()[i]; + } + + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); + glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); + + // GL_LIGHT0 is always enabled + gl::enable(GL_LIGHT0); + // reset light state gl::disable(GL_LIGHT1); has_zone_light = false; @@ -206,10 +224,10 @@ void draw_globe(core::EntityGlobe *globe) gl::enable(GL_TEXTURE_2D); } - if (ext_render(globe)->distance() > farplane) { + if (ext_render(globe)->distance() > (FARPLANE - globe->radius())) { // globe is behind the far plane, make a fake size calculation - location = Camera::eye() + (location - Camera::eye()) * (farplane / ext_render(globe)->distance()); - radius *= farplane / ext_render(globe)->distance(); + location = Camera::eye() + (location - Camera::eye()) * (FARPLANE / ext_render(globe)->distance()); + radius *= FARPLANE / ext_render(globe)->distance(); gl::depthmask(GL_FALSE); @@ -287,7 +305,7 @@ void draw_globe(core::EntityGlobe *globe) } - if (ext_render(globe)->distance() > farplane) { + if (ext_render(globe)->distance() > (FARPLANE - globe->radius())) { gl::depthmask(GL_TRUE); @@ -861,7 +879,6 @@ void draw_pass_model_fx(float elapsed) float a = 0.0f; float light_size = 0.0f; bool power = true; - bool draw_quad = true; float thrust = 0.0f; math::Vector3f location; @@ -897,7 +914,6 @@ void draw_pass_model_fx(float elapsed) // draw model lights for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { model::Light *light = (*lit); - draw_quad = true; // engine activated lights if (light->engine()) { @@ -908,66 +924,62 @@ void draw_pass_model_fx(float elapsed) } else { thrust = ec->thrust(); if (thrust < 0.001f) { - draw_quad = false; + continue; // next light } } } else { - draw_quad = false; + continue; // next light } } // strobe frequency - if (draw_quad && light->strobe()) { - + if (light->strobe()) { t = (core::application()->time() + ext_render(entity)->fuzz() - light->offset()) * light->frequency(); if ((t - floorf(t)) > light->time()) { - draw_quad = false; + continue; // next light } } - // draw visible lights - if (draw_quad) { - // default alpha is 0.8 - a = 0.8f; - if (light->entity()) { - color.assign(entity->color()); - } else if (light->engine()) { - color.assign(entity->model()->enginecolor()); - a *= thrust; - } else { - color.assign(light->color()); - } - color.a = a; - - location.assign(entity->location() + (entity->axis() * light->location())); - light_size = 0.0625f * light->radius(); - - // track OpenGL state changes - if (current_texture != light->texture()) { - gl::end(); - current_texture = Textures::bind(light->texture()); - gl::begin(gl::Quads); - } - - // draw the quad - gl::color(color); - - glTexCoord2f(0,1); - gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * light_size); - glTexCoord2f(0,0); - gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * light_size); - glTexCoord2f(1,0); - gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size); - glTexCoord2f(1,1); - gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size); - Stats::quads++; + // default alpha is 0.8 + a = 0.8f; + if (light->entity()) { + color.assign(entity->color()); + } else if (light->engine()) { + color.assign(entity->model()->enginecolor()); + a *= thrust; + } else { + color.assign(light->color()); } + color.a = a; + + location.assign(entity->location() + (entity->axis() * light->location())); + light_size = 0.0625f * light->radius(); + + // track OpenGL state changes + if (current_texture != light->texture()) { + gl::end(); + current_texture = Textures::bind(light->texture()); + gl::begin(gl::Quads); + } + + // draw the quad + gl::color(color); + + glTexCoord2f(0,1); + gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * light_size); + glTexCoord2f(0,0); + gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * light_size); + glTexCoord2f(1,0); + gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * light_size); + glTexCoord2f(1,1); + gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * light_size); + Stats::quads++; + } // draw flares for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { model::Flare *flare = (*flit); - draw_quad = true; // engine activated flares if (flare->engine()) { @@ -978,95 +990,87 @@ void draw_pass_model_fx(float elapsed) } else { thrust = ec->thrust(); if (thrust < 0.001f) { - draw_quad = false; + continue; // next flare } } } else { - draw_quad = false; + continue; // next flare } } // strobe frequency - if (draw_quad && flare->strobe()) { - + if (flare->strobe()) { t = (core::application()->time() + ext_render(entity)->fuzz() - flare->offset()) * flare->frequency(); if ((t - floorf(t)) > flare->time()) { - draw_quad = false; + continue; // next flare } } // calulcate viewing angle factor - if (draw_quad) { - flare_axis.assign(entity->axis() * flare->axis()); - a = math::absf(dotproduct(flare_axis.forward(), Camera::axis().forward())); - - if (a < 0.01f) { - draw_quad = false; - } + flare_axis.assign(entity->axis() * flare->axis()); + a = math::absf(dotproduct(flare_axis.forward(), Camera::axis().forward())); + if (a < 0.01f) { + continue; // next flare } - // draw visible flares - if (draw_quad) { + // alpha decreases with viewing angle + a *= 0.8f; + if (flare->entity()) { + color.assign(entity->color()); + } else if (flare->engine()) { + color.assign(entity->model()->enginecolor()); + a *= thrust; + } else { + color.assign(flare->color()); + } + color.a = a; - // alpha decreases with viewing angle - a *= 0.8f; - if (flare->entity()) { - color.assign(entity->color()); - } else if (flare->engine()) { - color.assign(entity->model()->enginecolor()); - a *= thrust; - } else { - color.assign(flare->color()); - } - color.a = a; + location.assign(entity->location() + (entity->axis() * flare->location())); + light_size = 0.0625f * flare->radius(); - location.assign(entity->location() + (entity->axis() * flare->location())); - light_size = 0.0625f * flare->radius(); + // track OpenGL state changes + if ((current_cull != flare->cull()) || (current_texture != flare->texture())) { + gl::end(); - // track OpenGL state changes - if ((current_cull != flare->cull()) || (current_texture != flare->texture())) { - gl::end(); + if (current_texture != flare->texture()) { + current_texture = Textures::bind(flare->texture()); + } - if (current_texture != flare->texture()) { - current_texture = Textures::bind(flare->texture()); - } + if (current_cull != flare->cull()) { + if (flare->cull() == model::CullNone) { + gl::disable(GL_CULL_FACE); + current_cull = model::CullNone; + } else { + if (current_cull == model::CullNone) { + gl::enable(GL_CULL_FACE); + } - if (current_cull != flare->cull()) { - if (flare->cull() == model::CullNone) { - gl::disable(GL_CULL_FACE); - current_cull = model::CullNone; + if (flare->cull() == model::CullBack) { + gl::cullface(GL_BACK); + current_cull = model::CullBack; } else { - if (current_cull == model::CullNone) { - gl::enable(GL_CULL_FACE); - } - - if (flare->cull() == model::CullBack) { - gl::cullface(GL_BACK); - current_cull = model::CullBack; - } else { - gl::cullface(GL_FRONT); - current_cull = model::CullFront; - } + gl::cullface(GL_FRONT); + current_cull = model::CullFront; } } - - gl::begin(gl::Quads); } - // draw the quad - gl::color(color); - - glTexCoord2f(0,1); - gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); - glTexCoord2f(0,0); - gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); - glTexCoord2f(1,0); - gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); - glTexCoord2f(1,1); - gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); - - Stats::quads++; + gl::begin(gl::Quads); } + + // draw the quad + gl::color(color); + + glTexCoord2f(0,1); + gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); + glTexCoord2f(0,0); + gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); + glTexCoord2f(1,0); + gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); + glTexCoord2f(1,1); + gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); + + Stats::quads++; } gl::end(); @@ -1207,24 +1211,18 @@ void draw(float seconds) gl::enable(GL_CULL_FACE); // enable culling gl::enable(GL_COLOR_MATERIAL); // enable color tracking - gl::enable(GL_LIGHTING); - //gl::enable(GL_RESCALE_NORMAL); // rescale normals by the transformation matrix scale factor - gl::enable(GL_NORMALIZE); - + gl::enable(GL_LIGHTING); // enable lighting + gl::enable(GL_NORMALIZE); // enable rescaling of normals + draw_pass_globes(); // draw globes draw_pass_default(); // draw entities without model - - gl::disable(GL_NORMALIZE); - //gl::disable(GL_RESCALE_NORMAL); - -// glEnableClientState(GL_COLOR_ARRAY); draw_pass_model_fragments(); -// glDisableClientState(GL_COLOR_ARRAY); - gl::disable(GL_LIGHTING); + gl::disable(GL_NORMALIZE); // disable resaling of normals + gl::disable(GL_LIGHTING); // disable lighting gl::enable(GL_BLEND); gl::depthmask(GL_FALSE); // disable depth buffer writing diff --git a/src/render/render.h b/src/render/render.h index a453464..3d07796 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -56,10 +56,6 @@ namespace render { extern core::Cvar *r_mipmap; 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 index 6a59870..b0462d4 100644 --- a/src/render/renderext.cc +++ b/src/render/renderext.cc @@ -107,20 +107,34 @@ void RenderExt::frame(float elapsed) if ((entity()->type() == core::Entity::Controlable)) { if (static_cast<core::EntityDynamic *>(entity())->state() == core::Entity::Docked) { state_visible = false; + return; } } if (state_visible && entity()->model()) { - float r = entity()->model()->radius(); - math::clamp(r, 1.0f, farplane / drawfxdistance); - if (distance() < drawfxdistance * r) { + + if (distance() < core::range::fxdistance) { // entity within detail range state_visible = true; state_detailvisible = true; - } else if ((distance() < drawdistance * r) && (distance() < core::range::max)) { + + } else if (distance() < core::range::maxvisible) { // entity within drawing distance, outside detail range state_visible = true; state_detailvisible = false; + + } else if (distance() < core::range::maxdistance) { + + if ((entity()->type() == core::Entity::Controlable)) { + // controlable entity out of range + state_visible = false; + state_detailvisible = false; + } else { + // entity within drawing distance, outside detail range + state_visible = true; + state_detailvisible = false; + + } } else { // entity out of range state_visible = false; diff --git a/src/render/state.cc b/src/render/state.cc index 2bf50af..96c7c0a 100644 --- a/src/render/state.cc +++ b/src/render/state.cc @@ -79,20 +79,6 @@ void State::clear() gl::shademodel(GL_SMOOTH); //gl::shademodel(GL_FLAT); - // lighting settings for the default light GL_LIGHT0 - GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; - GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f }; - GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f }; - - glLightfv(GL_LIGHT0, GL_POSITION, light_position); - glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); - glLightfv(GL_LIGHT0, GL_SPECULAR, specular_light); - - // GL_LIGHT0 is always enabled - gl::enable(GL_LIGHT0); - // color tracking glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); |