Jump to content

Surface or Mesh visible in frustrum


photo

Recommended Posts

Posted

Hi,

I have a mesh with many surfaces, I want detect which surfaces are visible in the frutrum. What is the best way to do that with script ?

I have also the possibility to split the surfaces into many ObjectMeshDynamic. I try to use engine.world.getIntersectionObjects with my projection and model view of my camera. But the function return also some object outside the frustrum.

    _players[CAM_COLLIDER].setFov(FOV + FOV * (engine.app.getWidth() / engine.app.getHeight()));
    
    mat4 projection = _players[CAM_COLLIDER].getProjection();
    mat4 modelview = _players[CAM_COLLIDER].getModelview();
    
    engine.world.getIntersectionObjects(projection,modelview,ret);

    log.message("Visible : %d\n",ret.size());


The log message say 96 visible but I have only 24 mesh front of my camera

 

dynamic.png

 

 

Any idea ?

Posted

Hello,
getProjection() returns the projection matrix with unit (1.0) aspect ratio.



int ret[0];
mat4 modelview = mat4(camera.getModelview()) * camera.getOffset();
float aspect = float(engine.app.getWidth()) / float(engine.app.getHeight());
mat4 projection = perspective(camera.getFov(),aspect,camera.getZNear(),camera.getZFar());
engine.world.getIntersectionObjects(projection,modelview,ret);
int num_surfaces = 0;
Unigine::BoundFrustum bound_frustum = new Unigine::BoundFrustum(projection,modelview);
forloop(int i = 0;ret.size()) {
    Object object = ret[i];
    forloop(int j = 0; object.getNumSurfaces()) {
        if(bound_frustum.insideBox(vec3(object.getBoundMin(j)),vec3(object.getBoundMax(j)),object.getWorldTransform())) {
            num_surfaces++;
        }
    }
}
engine.message("Visible surfaces: %d\n",num_surfaces);

engine.world.getIntersectionObjects() Intersection is performed with bounding box.

Do you want to cut overlapped objects?
Do you want to find the intersection with the polygons?

×
×
  • Create New...