Esempio n. 1
0
        private void DrawSubdivision(ref Matrix4 mvp, Vector3 position, Vector3 boxSize, ModelOctreeNode[] modelOctrees, int subdiv)
        {
            int index = 0;

            for (int z = 0; z < 2; z++)
            {
                for (int y = 0; y < 2; y++)
                {
                    for (int x = 0; x < 2; x++)
                    {
                        Vector3 cubePosition = position + boxSize * new Vector3(x, y, z);

                        if (modelOctrees[index].Children == null)
                        {
                            DrawableBoundingBox.DrawBoundingBox(mvp, boxSize / 2f, cubePosition + boxSize / 2f, System.Drawing.Color.Red);
                        }
                        else
                        {
                            DrawSubdivision(ref mvp, cubePosition, boxSize / 2f, modelOctrees[index].Children, subdiv++);
                        }

                        index++;
                    }
                }
            }
        }
Esempio n. 2
0
        private void DrawOctrees(ref Matrix4 mvp)
        {
            foreach (var model in KclFile.Models)
            {
                if (model.HitOctrees.Count > 0)
                {
                    var boundings  = model.GetOctreeBoundings();
                    var hitOctrees = model.HitOctrees;
                    foreach (var bounding in boundings)
                    {
                        foreach (var octree in hitOctrees)
                        {
                            if (octree == bounding.Octree)
                            {
                                Vector3 pos   = new Vector3(bounding.Position.X, bounding.Position.Y, bounding.Position.Z);
                                Vector3 bsize = new Vector3(bounding.Size);
                                DrawableBoundingBox.DrawBoundingBox(mvp, bsize, pos + bsize, System.Drawing.Color.Red);
                            }
                        }
                    }
                }
            }

            return;

            var     octreeMax    = KclFile.MaxCoordinate;
            var     octreeOrigin = KclFile.MinCoordinate;
            Vector3 max          = new Vector3((float)octreeMax.X, (float)octreeMax.Y, (float)octreeMax.Z);
            Vector3 min          = new Vector3((float)octreeOrigin.X, (float)octreeOrigin.Y, (float)octreeOrigin.Z);
            Vector3 size         = max - min;

            Vector3 boxSize = new Vector3(
                (1 << (int)KclFile.CoordinateShift.X),
                (1 << (int)KclFile.CoordinateShift.Y),
                (1 << (int)KclFile.CoordinateShift.Z));

            Console.WriteLine($"boxSize {boxSize} SIZE {max - min}");

            DrawSubdivision(ref mvp, min, boxSize / 2f, KclFile.ModelOctreeRoot.Children, 0);
        }