public static void RenderNode(AABBNode node,  Matrix world, Matrix view, Matrix proj, RenderContext render_context, Color leaf_color, Color marked_color)
        {
            if (node.IsLeaf)
              {
            Color color = leaf_color;
            if (node.Marked)
            {
              color = marked_color;
            }
            BoundingBoxRenderer.Render(node.BBox, render_context.GraphicsDevice, world, view, proj, color);

              }else{
            RenderNode(node.Left, world, view, proj, render_context, leaf_color, marked_color);
            RenderNode(node.Right, world, view, proj, render_context, leaf_color, marked_color);
              }
        }
 public static void RenderNode(AABBNode node, Matrix world, Matrix view, Matrix proj, RenderContext render_context, Color leaf_color)
 {
     RenderNode(node, world, view, proj, render_context, leaf_color, leaf_color);
 }
Пример #3
0
 public static void Leafs(AABBNode node, List<AABBNode> leafs)
 {
     if (node.IsLeaf)
     {
       leafs.Add(node);
     }
     else
     {
       Leafs(node.Left, leafs);
       Leafs(node.Right, leafs);
     }
 }
Пример #4
0
        public static void TransformAABBNode(AABBNode node, Matrix transform)
        {
            node.BBox = TransformBoundingBox(node.BBox, transform);
            if(node.Left != null){
              TransformAABBNode(node.Left, transform);
            }

            if (node.Right != null)
            {
              TransformAABBNode(node.Right, transform);
            }
        }
Пример #5
0
 public AABBTree(List<float[]> vertices, AABBNodeInfo tree_information)
 {
     root = new AABBNode(vertices, tree_information, 0);
 }
Пример #6
0
        private void _BuildTree_PreserveTriangles(List<float[]> vertices)
        {
            float[] min, max;
            AABBHelper.GetMinMax(vertices, out min, out max);
            box = new BoundingBox(
                new Vector3(min[0], min[1], min[2]),
                new Vector3(max[0], max[1], max[2])
            );

            //make prune control this
            if ((_tree_info.prune && vertices.Count <= _tree_info.leaf_min_verts) || _depth == _tree_info.max_tree_depth)
            {
                _isLeaf = true;
                return;
            }

            int chosen_axis = DetermineBestAxisAtFaceValue(vertices, box);

            float center = (min[chosen_axis] + max[chosen_axis]) / 2f;
            float face_center;

            List<float[]> left_side = new List<float[]>();
            List<float[]> right_side = new List<float[]>();

            float[][] tri = new float[3][];
            int count = 0;

            for (int i = 0; i < vertices.Count; i++)
            {
                tri[count] = vertices[i];
                if ( tri[count][0] < box.Min.X
                  || tri[count][1] < box.Min.Y
                  || tri[count][2] < box.Min.Z

                  || tri[count][0] > box.Max.X
                  || tri[count][1] > box.Max.Y
                  || tri[count][2] > box.Max.Z
                  )
                {
                  Debug.Report("Error in AABB calculation");
                }

                if (count == 2)
                {

                    face_center = (tri[0][chosen_axis] + tri[1][chosen_axis] + tri[2][chosen_axis]) / 3f;
                    if (face_center < center)
                    {
                        left_side.Add(tri[0]);
                        left_side.Add(tri[1]);
                        left_side.Add(tri[2]);
                    }
                    else
                    {
                        right_side.Add(tri[0]);
                        right_side.Add(tri[1]);
                        right_side.Add(tri[2]);

                    }
                    count = 0;

                }
                else
                {
                    count++;
                }
            }

            if (left_side.Count == 0 || right_side.Count == 0)
            {
              this._isLeaf = true;
            }
            else
            {
              _Left = new AABBNode(left_side, _tree_info, _depth + 1);
              _Right = new AABBNode(right_side, _tree_info, _depth + 1);
              this._isLeaf = false;
            }
        }