X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fzsortedscene.cpp;h=fe60803a54d8e3ff323a33f5e6f23d654044e6d8;hb=d386eadfd08b556ecb05627a7ceca14652e8b1e5;hp=709c5c26787478cf260d3257d069550aa38e59e6;hpb=af0077ac71c51aeed63bc0222fe4650d5077478a;p=libs%2Fgl.git diff --git a/source/zsortedscene.cpp b/source/zsortedscene.cpp index 709c5c26..fe60803a 100644 --- a/source/zsortedscene.cpp +++ b/source/zsortedscene.cpp @@ -12,13 +12,13 @@ ZSortedScene::ZSortedScene(): reference(FURTHEST) { } -void ZSortedScene::add(const Renderable &r) +void ZSortedScene::add(Renderable &r) { if(renderables.insert(&r).second && !sorted_cache.empty()) sorted_cache.push_back(&r); } -void ZSortedScene::remove(const Renderable &r) +void ZSortedScene::remove(Renderable &r) { renderables.erase(&r); sorted_cache.clear(); @@ -62,19 +62,19 @@ void ZSortedScene::render(Renderer &renderer, const Tag &tag) const for(SortedArray::iterator i=sorted_cache.begin(); i!=sorted_cache.end(); ++i) { i->in_frustum = (!use_frustum || !frustum_cull(*i->renderable)); - if(i->in_frustum) + if(!i->in_frustum) + continue; + + if(const Matrix *matrix = i->renderable->get_matrix()) { - if(const Matrix *model_matrix = i->renderable->get_matrix()) - { - if(const Geometry::BoundingSphere *bsphere = i->renderable->get_bounding_sphere()) - i->depth = dot(*model_matrix*bsphere->get_center()-camera_pos, look_dir)+bsphere->get_radius()*radius_factor; - else - i->depth = dot(*model_matrix*Vector3()-camera_pos, look_dir); - i->depth *= sign; - } + if(const Geometry::BoundingSphere *bsphere = i->renderable->get_bounding_sphere()) + i->depth = dot(*matrix*bsphere->get_center()-camera_pos, look_dir)+bsphere->get_radius()*radius_factor; else - i->depth = 0; + i->depth = dot(*matrix*Vector3()-camera_pos, look_dir); + i->depth *= sign; } + else + i->depth = 0; } for(SortedArray::iterator i=sorted_cache.begin(), j=i; i!=sorted_cache.end(); ++i) @@ -104,10 +104,10 @@ void ZSortedScene::render(Renderer &renderer, const Tag &tag) const } -ZSortedScene::SortedRenderable::SortedRenderable(const Renderable *r): +ZSortedScene::SortedRenderable::SortedRenderable(Renderable *r): + renderable(r), in_frustum(false), - depth(0.0f), - renderable(r) + depth(0.0f) { } } // namespace GL