Beispiel #1
0
 public QuadtreeNode()
 {
     type      = QuadtreeNodeType.None;
     position  = Vector2.Zero;
     size      = 0;
     children  = new QuadtreeNode[4];
     draw_info = new QuadtreeDrawInfo();
 }
Beispiel #2
0
 public QuadtreeNode()
 {
     type = QuadtreeNodeType.None;
     position = Vector2.Zero;
     size = 0;
     children = new QuadtreeNode[4];
     draw_info = new QuadtreeDrawInfo();
 }
Beispiel #3
0
        public bool ConstructLeaf(ref int v_index, List<VertexPositionColorNormal> vertices, int grid_size)
        {
            int corners = 0;
            float[,] samples = new float[2, 2];
            for (int i = 0; i < 4; i++)
            {
                if ((samples[i / 2, i % 2] = Sampler.Sample(position + new Vector2(i / 2, i % 2))) < 0)
                    corners |= 1 << i;
            }

            if (corners == 0 || corners == 15)
                return false;

            QEF qef = new QEF();
            Vector3 average_normal = new Vector3();
            for (int i = 0; i < 4; i++)
            {
                int c1 = Sampler.Edges[i, 0];
                int c2 = Sampler.Edges[i, 1];

                int m1 = (corners >> c1) & 1;
                int m2 = (corners >> c2) & 1;
                if (m1 == m2)
                    continue;

                float d1 = samples[c1 / 2, c1 % 2];
                float d2 = samples[c2 / 2, c2 % 2];

                Vector2 p1 = new Vector2((float)((c1 / 2)), (float)((c1 % 2)));
                Vector2 p2 = new Vector2((float)((c2 / 2)), (float)((c2 % 2)));

                Vector2 intersection = Sampler.GetIntersection(p1, p2, d1, d2);
                Vector2 normal = Sampler.GetNormal(intersection + position);//GetNormal(x, y);
                average_normal += new Vector3(normal, 0);

                qef.Add(intersection, normal);
            }

            average_normal /= (float)qef.Intersections.Count;
            average_normal.Normalize();

            draw_info = new QuadtreeDrawInfo();
            draw_info.position = qef.Solve2(0, 0, 0);
            draw_info.averageNormal = average_normal;
            draw_info.corners = corners;
            draw_info.index = v_index++;
            Color n_c = new Color(average_normal * 0.5f + Vector3.One * 0.5f);
            vertices.Add(new VertexPositionColorNormal(new Vector3(position * grid_size + draw_info.position * size * grid_size, 0), n_c, average_normal));

            type = QuadtreeNodeType.Leaf;
            return true;
        }
Beispiel #4
0
        public bool ConstructLeaf(ref int v_index, List <VertexPositionColorNormal> vertices, int grid_size)
        {
            int corners = 0;

            float[,] samples = new float[2, 2];
            for (int i = 0; i < 4; i++)
            {
                if ((samples[i / 2, i % 2] = Sampler.Sample(position + new Vector2(i / 2, i % 2))) < 0)
                {
                    corners |= 1 << i;
                }
            }

            if (corners == 0 || corners == 15)
            {
                return(false);
            }

            QEF     qef            = new QEF();
            Vector3 average_normal = new Vector3();

            for (int i = 0; i < 4; i++)
            {
                int c1 = Sampler.Edges[i, 0];
                int c2 = Sampler.Edges[i, 1];

                int m1 = (corners >> c1) & 1;
                int m2 = (corners >> c2) & 1;
                if (m1 == m2)
                {
                    continue;
                }

                float d1 = samples[c1 / 2, c1 % 2];
                float d2 = samples[c2 / 2, c2 % 2];

                Vector2 p1 = new Vector2((float)((c1 / 2)), (float)((c1 % 2)));
                Vector2 p2 = new Vector2((float)((c2 / 2)), (float)((c2 % 2)));

                Vector2 intersection = Sampler.GetIntersection(p1, p2, d1, d2);
                Vector2 normal       = Sampler.GetNormal(intersection + position);          //GetNormal(x, y);
                average_normal += new Vector3(normal, 0);

                qef.Add(intersection, normal);
            }

            average_normal /= (float)qef.Intersections.Count;
            average_normal.Normalize();

            draw_info               = new QuadtreeDrawInfo();
            draw_info.position      = qef.Solve2(0, 0, 0);
            draw_info.averageNormal = average_normal;
            draw_info.corners       = corners;
            draw_info.index         = v_index++;
            Color n_c = new Color(average_normal * 0.5f + Vector3.One * 0.5f);

            vertices.Add(new VertexPositionColorNormal(new Vector3(position * grid_size + draw_info.position * size * grid_size, 0), n_c, average_normal));

            type = QuadtreeNodeType.Leaf;
            return(true);
        }