Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <vlGraphics/PixelLODEvaluator.hpp>
00033 #include <vlGraphics/Camera.hpp>
00034
00035 using namespace vl;
00036
00037
00038 int PixelLODEvaluator::evaluate(Actor* actor, Camera* camera)
00039 {
00040 if (mPixelRangeSet.empty())
00041 return 0;
00042
00043 AABB aabb = actor->transform() ? actor->lod(0)->boundingBox().transformed( actor->transform()->worldMatrix() ) : actor->lod(0)->boundingBox();
00044
00045 vec3 corner[] =
00046 {
00047 vec3(aabb.minCorner().x(), aabb.minCorner().y(), aabb.minCorner().z()),
00048 vec3(aabb.minCorner().x(), aabb.maxCorner().y(), aabb.minCorner().z()),
00049 vec3(aabb.maxCorner().x(), aabb.maxCorner().y(), aabb.minCorner().z()),
00050 vec3(aabb.maxCorner().x(), aabb.minCorner().y(), aabb.minCorner().z()),
00051 vec3(aabb.minCorner().x(), aabb.minCorner().y(), aabb.maxCorner().z()),
00052 vec3(aabb.minCorner().x(), aabb.maxCorner().y(), aabb.maxCorner().z()),
00053 vec3(aabb.maxCorner().x(), aabb.maxCorner().y(), aabb.maxCorner().z()),
00054 vec3(aabb.maxCorner().x(), aabb.minCorner().y(), aabb.maxCorner().z())
00055 };
00056
00057 mat4 proj_matrix = camera->projectionMatrix() * camera->viewMatrix();
00058
00059 aabb.setNull();
00060
00061
00062 for(int i=0; i<8; ++i)
00063 {
00064 vec4 out = proj_matrix * vec4(corner[i],1);
00065
00066 if (out.w() == 0.0f)
00067 continue;
00068
00069 out.x() /= out.w();
00070 out.y() /= out.w();
00071 out.z() /= out.w();
00072
00073
00074 out.x() = out.x() * 0.5f + 0.5f;
00075 out.y() = out.y() * 0.5f + 0.5f;
00076 out.z() = out.z() * 0.5f + 0.5f;
00077
00078
00079 out.x() = out.x() * camera->viewport()->width() + camera->viewport()->x();
00080 out.y() = out.y() * camera->viewport()->height() + camera->viewport()->y();
00081
00082 aabb.addPoint(out.xyz());
00083 }
00084
00085 double pixels = aabb.width() * aabb.height();
00086
00087
00088 int i=0;
00089 for(; i<(int)mPixelRangeSet.size(); ++i)
00090 {
00091 if (pixels>mPixelRangeSet[mPixelRangeSet.size() - 1 - i])
00092 return i;
00093 }
00094
00095 return i;
00096 }
00097