Beispiel #1
0
    public static List <Model3d> Query(OctreeNode node, AABB3d aabb)
    {
        //std::vector<Model*> result;
        List <Model3d> result = new List <Model3d>();

        if (IntersectionTest3D.AABB3dWithAABB3d(aabb, node.m_bounds))
        {
            if (node.m_children == null)
            {
                for (int i = 0, size = node.m_models.Count; i < size; ++i)
                {
                    OBB3d bounds = node.m_models[i].GetOBB();
                    if (IntersectionTest3D.AABB3dWithOBB3d(aabb, bounds))
                    {
                        result.Add(node.m_models[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < 8; ++i)
                {
                    List <Model3d> child = Query(node.m_children[i], aabb);
                    if (child.Count > 0)
                    {
                        //result.insert(result.end(), child.begin(), child.end());
                        result.AddRange(child);
                    }
                }
            }
        }

        return(result);
    }
Beispiel #2
0
    public static void SplitTree(OctreeNode node, int depth)
    {
        if (depth-- <= 0)
        { // Decrements depth
            return;
        }

        if (node.m_children == null)
        {
            node.m_children = new OctreeNode[8];

            Vector3L c = node.m_bounds.m_pos;
            Vector3L e = node.m_bounds.GetHalfSize() * 0.5f;

            node.m_children[0].m_bounds = new AABB3d(c + new Vector3L(-e.x, +e.y, -e.z), node.m_bounds.GetHalfSize());
            node.m_children[1].m_bounds = new AABB3d(c + new Vector3L(+e.x, +e.y, -e.z), node.m_bounds.GetHalfSize());
            node.m_children[2].m_bounds = new AABB3d(c + new Vector3L(-e.x, +e.y, +e.z), node.m_bounds.GetHalfSize());
            node.m_children[3].m_bounds = new AABB3d(c + new Vector3L(+e.x, +e.y, +e.z), node.m_bounds.GetHalfSize());
            node.m_children[4].m_bounds = new AABB3d(c + new Vector3L(-e.x, -e.y, -e.z), node.m_bounds.GetHalfSize());
            node.m_children[5].m_bounds = new AABB3d(c + new Vector3L(+e.x, -e.y, -e.z), node.m_bounds.GetHalfSize());
            node.m_children[6].m_bounds = new AABB3d(c + new Vector3L(-e.x, -e.y, +e.z), node.m_bounds.GetHalfSize());
            node.m_children[7].m_bounds = new AABB3d(c + new Vector3L(+e.x, -e.y, +e.z), node.m_bounds.GetHalfSize());
        }

        if (node.m_children != null && node.m_models.Count > 0)
        {
            for (int i = 0; i < 8; ++i)
            { // For each child
                for (int j = 0, size = node.m_models.Count; j < size; ++j)
                {
                    OBB3d obb = node.m_models[j].GetOBB();
                    if (IntersectionTest3D.AABB3dWithOBB3d(node.m_children[i].m_bounds, obb))
                    {
                        node.m_children[i].m_models.Add(node.m_models[j]);
                    }
                }
            }
            node.m_models.Clear();

            // Recurse
            for (int i = 0; i < 8; ++i)
            {
                SplitTree(node.m_children[i], depth);
            }
        }
    }
Beispiel #3
0
    public static void Insert(OctreeNode node, Model3d model)
    {
        OBB3d bounds = model.GetOBB();

        if (IntersectionTest3D.AABB3dWithOBB3d(node.m_bounds, bounds))
        {
            if (node.m_children == null)
            {
                node.m_models.Add(model);
            }
            else
            {
                for (int i = 0; i < 8; ++i)
                {
                    Insert(node.m_children[i], model);
                }
            }
        }
    }
Beispiel #4
0
    public List <Model3d> Query(AABB3d aabb)
    {
        if (m_octree != null)
        {
            // :: lets the compiler know to look outside class scope
            return(Octree3d.Query(m_octree, aabb));
        }

        List <Model3d> result = new List <Model3d>();

        for (int i = 0, size = m_modleList.Count; i < size; ++i)
        {
            OBB3d bounds = m_modleList[i].GetOBB();
            if (IntersectionTest3D.AABB3dWithOBB3d(aabb, bounds))
            {
                result.Add(m_modleList[i]);
            }
        }
        return(result);
    }