I've been assigned to write small simulation visualization, that contains thousands of cubes (I know you heard that before). Now I'm working on optimization of stuff that takes place there, but suddenly I came across a brain teaser (maybe my math foo is to weak).

Scene is arranged in hierarchy, each cube can contain another cubes and so on (cubes always must be contained in parent cube, position is relative to parent cube (including transformation except scale). Now we added ability to rotate cubes and all hell broke lose. We use simple culling of objects that shouldn't be drawn this look like this (Warning C#):

    public bool CanDraw(ICamera camera, Vector3d offset)
        Vector3d pos = _translation + offset;

        _inFrustum = camera.SphereInFrustum(pos, _radius);

        if (_inFrustum == InFrustum.Partial && Children != null)
            foreach (IDrawable item in Children)
                item.CanDraw(camera, pos);

        return _inFrustum != InFrustum.No;

InFrustum enum can be Yes, No, Partial.

Now the problem that we get is when parent cube is rotated for example by 45 deg around Z axis and is partially visible all children are tested, but rotation is not included this results in child cubes not being drawn... further more if child cube is drawn, but is rotated problem is starting to get worse.

Do any of you how to solve this without moving test draw code into rendering loop (after transformations are made to see if point 0,0,0 is in frustum?

I imagine that I would have to rotate pos using offset as axis origin and parent rotation (how?), but still that parent object (offset and rotation) might be already rotated by it's parent.

I must do those checks, cause scene contains around 300k+ boxes and drawing all of them ends up in <0.1 FPS on machines that it's used.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.