3 #include "zsortedscene.h"
10 ZSortedScene::ZSortedScene():
15 void ZSortedScene::set_order(SortOrder o)
20 void ZSortedScene::set_reference(DepthReference r)
25 void ZSortedScene::render(Renderer &renderer, const Tag &tag) const
27 const Camera *camera = renderer.get_camera();
29 return SimpleScene::render(renderer, tag);
31 const Matrix &view_matrix = camera->get_matrix();
33 std::vector<DepthRenderable> sorted_renderables;
34 sorted_renderables.reserve(renderables.size());
36 float radius_factor = 1.0f-reference;
37 float sign = order*2.0f-1.0f;
39 setup_cullers(renderer);
40 for(RenderableSet::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
41 if(!cull(renderer, **i))
44 if(const Matrix *model_matrix = (*i)->get_matrix())
46 if(const Geometry::BoundingSphere<float, 3> *bsphere = (*i)->get_bounding_sphere())
47 z = (view_matrix**model_matrix*Vector4(bsphere->get_center(), 1.0f)).z+bsphere->get_radius()*radius_factor;
49 z = (view_matrix**model_matrix*Vector4(0.0f, 0.0f, 0.0f, 1.0f)).z;
51 sorted_renderables.push_back(DepthRenderable(z*sign, *i));
54 sort(sorted_renderables.begin(), sorted_renderables.end());
56 for(vector<DepthRenderable>::const_iterator i=sorted_renderables.begin(); i!=sorted_renderables.end(); ++i)
57 i->renderable->render(renderer, tag);
61 ZSortedScene::DepthRenderable::DepthRenderable(float d, const Renderable *r):