示例#1
0
 void AABBQuery(TOctreeNode node, TVector <int> result, TAABB aabb)
 {
     if (node.is_end != -1)
     {
         result.Add(items[node.is_end]);
     }
     else
     {
         int i, k, t;
         for (i = 0; i < 2; i++)
         {
             if ((aabb.Get(0, i) < (node.dims.Get(0, 0) + node.dims.Get(0, 1)) * 0.5) != (i == 1))
             {
                 for (k = 0; k < 2; k++)
                 {
                     if ((aabb.Get(1, k) < (node.dims.Get(1, 0) + node.dims.Get(1, 1)) * 0.5) != (k == 1))
                     {
                         for (t = 0; t < 2; t++)
                         {
                             if ((aabb.Get(2, t) < (node.dims.Get(2, 0) + node.dims.Get(2, 1)) * 0.5) != (t == 1))
                             {
                                 if (node.GetChild(i, k, t) != -1)
                                 {
                                     AABBQuery(nodes[node.GetChild(i, k, t)], result, aabb);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public TTriMesh()
 {
     pos    = new TVector <Vector3>(1000);
     normal = new TVector <Vector3>(1000);
     //color = new TVector<int>(1000);
     triangle = new TVector <TMeshTri>(1000);
 }
示例#3
0
 public void DelTriangles(TVector <int> tri)
 {
     tri.Sort();
     for (int i = tri.High; i >= 0; i--)
     {
         triangle.Del(tri[i]);
     }
 }
示例#4
0
 public void AABBQuery(TVector <int> result, TAABB aabb)
 {
     result.Pop(result.Length);
     if (aabb.Overlaps(nodes[root].dims))
     {
         AABBQuery(nodes[root], result, aabb);
     }
     DeleteRepeatingValues(result);
 }
示例#5
0
 public void RayQuery(TVector <int> result, TRay ray)
 {
     result.Pop(result.Length);
     if (nodes[root].dims.Overlaps(ray))
     {
         RayQuery(nodes[root], result, ray);
     }
     DeleteRepeatingValues(result);
 }
示例#6
0
 public void Triangles(TVector <CustomVertex.PositionNormalColored> triangles)
 {
     if (triangles.Length == 0)
     {
         return;
     }
     _device.VertexFormat = CustomVertex.PositionNormalColored.Format;
     _device.DrawUserPrimitives(PrimitiveType.TriangleList, triangles.Length / 3, triangles.GetData());
 }
示例#7
0
        public void Add(TVector <T> value)
        {
            int t = v_high;

            if (NeedResize(v_high + value.v_high + 1))
            {
                SetHigh(v_high + value.v_high + 1);
            }
            else
            {
                v_high = v_high + value.v_high + 1;
            }
            for (int i = 0; i <= value.v_high; i++)
            {
                v[t + 1 + i] = value.v[i];
            }
        }
示例#8
0
 void RayQuery(TOctreeNode node, TVector <int> result, TRay ray)
 {
     if (node.is_end != -1)
     {
         result.Add(items[node.is_end]);
     }
     else
     {
         for (int i = 0; i < 8; i++)
         {
             if (node.child[i] != -1)
             {
                 if (nodes[node.child[i]].dims.Overlaps(ray))
                 {
                     RayQuery(nodes[node.child[i]], result, ray);
                 }
             }
         }
     }
 }
示例#9
0
 void DeleteRepeatingValues(TVector <int> result)
 {
     if (result.High >= 0)
     {
         result.Sort();
         int last_val = result[0];
         int offset   = 0;
         for (int i = 1; i <= result.High; i++)
         {
             if (result[i] == last_val)
             {
                 offset++;
             }
             else if (offset != 0)
             {
                 last_val           = result[i];
                 result[i - offset] = result[i];
             }
         }
         result.Pop(offset);
     }
 }
示例#10
0
        public void RebuildGeometry()
        {
            //need_props_refresh = true;//TODO если обновлять окно свойст здесь, то почему-то не происходит перерисовка моделей

            int last_high     = -1,
                normal_offset = 0,
                pos_offset    = 0,
                color_offset  = 0;

            if (objects.Count < 1)
            {
                return;
            }
            TTriMeshWithTree[] meshes            = new TTriMeshWithTree[objects.Count];
            TTriMesh[]         not_cutted_meshes = new TTriMesh[meshes.Length];
            float         node_size = 0;
            TVector <int> buffer    = new TVector <int>(1000);
            TAABB         scene_box = new TAABB();

            for (int i = 0; i < meshes.Length; i++)
            {
                not_cutted_meshes[i] = objects[i].GetTransformedMesh();
                meshes[i]            = new TTriMeshWithTree(not_cutted_meshes[i].GetCopy());
                node_size           += meshes[i].GetAverageTriSize();
                if (i == 0)
                {
                    scene_box = meshes[i].GetAABB();
                }
                else
                {
                    scene_box.Extend(meshes[i].GetAABB());
                }
            }
            node_size /= meshes.Length;

            scene = new TTriMeshWithTree(node_size * 2, scene_box);


            TVector <int> query_result  = new TVector <int>(1000);
            TVector <int> query_result1 = new TVector <int>(1000);

            for (int i = 0; i < meshes.Length; i++)
            {
                if (i != 0)
                {
                    //сечём треугольники объекта треугольниками сцены
                    scene.AABBQuery(query_result, meshes[i].GetAABB());
                    for (int k = 0; k <= query_result.High; k++)
                    {
                        meshes[i].Cut(buffer, scene.GetMesh(), query_result[k], scene.GetMesh().GetTriAABB(query_result[k]));
                    }
                    //сечём треугольники сцены треугольниками объекта(треугольники объекта не сечённые)
                    for (int k = 0; k <= not_cutted_meshes[i].triangle.High; k++)
                    {
                        scene.Cut(buffer, not_cutted_meshes[i], k, not_cutted_meshes[i].GetTriAABB(k));
                    }
                    scene.TrianglesInMeshQuery(buffer, query_result, meshes[i], true);
                    meshes[i].TrianglesInMeshQuery(buffer, query_result1, scene, false);
                    scene.DelTriangles(query_result);
                    meshes[i].DelTriangles(query_result1);
                    meshes[i].InverseNormals();
                }
                //добавляем объект в сцену
                scene.Add(meshes[i]);
            }
        }
示例#11
0
 public TIndexedVector(int use_reserve)
 {
     v      = new TVector <T>(use_reserve);
     free_v = new TVector <int>(use_reserve);
 }
示例#12
0
 public TIndexedVector()
 {
     v      = new TVector <T>();
     free_v = new TVector <int>();
 }