public static bool FindRandomTreeInPlaceArea(long entityId, out ItemInfo result)
        {
            result = default(ItemInfo);

            MyPlaceArea area = MyPlaceArea.FromEntity(entityId);

            if (area == null)
            {
                return(false);
            }

            var             areaBoundingBox = area.WorldAABB;
            List <MyEntity> entities        = null;

            try
            {
                entities = MyEntities.GetEntitiesInAABB(ref areaBoundingBox);

                m_tmpItemInfoList.Clear();
                foreach (var entity in entities)
                {
                    MyTrees trees = entity as MyTrees;
                    if (trees == null)
                    {
                        continue;
                    }

                    m_tmpEnvItemList.Clear();
                    trees.GetPhysicalItemsInRadius(areaBoundingBox.Center, (float)areaBoundingBox.HalfExtents.Length(), m_tmpEnvItemList);
                    foreach (var tree in m_tmpEnvItemList)
                    {
                        if (area.TestPoint(tree.Transform.Position))
                        {
                            var itemInfo = new ItemInfo();
                            itemInfo.ItemsEntityId = trees.EntityId;
                            itemInfo.ItemId        = tree.LocalId;
                            itemInfo.Target        = tree.Transform.Position;
                            m_tmpItemInfoList.Add(itemInfo);
                        }
                    }
                    m_tmpEnvItemList.Clear();
                }

                if (m_tmpItemInfoList.Count == 0)
                {
                    m_tmpItemInfoList.Clear();
                    return(false);
                }

                int treeIndex = (int)Math.Round(MyRandom.Instance.NextFloat() * (m_tmpItemInfoList.Count - 1));
                result = m_tmpItemInfoList[treeIndex];
                m_tmpItemInfoList.Clear();

                return(true);
            }
            finally
            {
                entities.Clear();
            }
        }
        private static bool FindClosestFracturedTreeInternal(Vector3D fromPosition, Vector3D searchCenter, double searchRadius, MyPlaceArea area, out EntityInfo result)
        {
            result = default(EntityInfo);

            double           closestDistanceSq = double.MaxValue;
            MyFracturedPiece closestTarget     = null;
            Vector3D         closestPoint      = default(Vector3D);

            BoundingSphereD searchSphere = new BoundingSphereD(searchCenter, searchRadius);

            m_tmpFracturePieceList.Clear();
            MyFracturedPiecesManager.Static.GetFracturesInSphere(ref searchSphere, ref m_tmpFracturePieceList);
            for (int i = 0; i < m_tmpFracturePieceList.Count; ++i)
            {
                var fracture = m_tmpFracturePieceList[i];

                // Skip non-tree fractures
                if (!MyTrees.IsEntityFracturedTree(fracture))
                {
                    continue;
                }

                if (IsFracturedTreeStump(fracture))
                {
                    continue;
                }

                Vector3D positionInTrunkLocal = Vector3D.Transform(fromPosition, fracture.PositionComp.WorldMatrixNormalizedInv);
                Vector3D closestPointOnTrunk;

                if (!FindClosestPointOnFracturedTree(positionInTrunkLocal, fracture, out closestPointOnTrunk))
                {
                    continue;
                }

                if (area == null || area.TestPoint(closestPointOnTrunk))
                {
                    double distanceSq = Vector3D.DistanceSquared(closestPointOnTrunk, fromPosition);

                    if (distanceSq < closestDistanceSq)
                    {
                        closestDistanceSq = distanceSq;
                        closestTarget     = fracture;
                        closestPoint      = closestPointOnTrunk;
                    }
                }
            }
            m_tmpFracturePieceList.Clear();

            if (closestTarget == null)
            {
                return(false);
            }

            result.EntityId = closestTarget.EntityId;
            result.Target   = closestPoint;
            return(true);
        }
Exemple #3
0
        public static bool FindClosestTreeInPlaceArea(Vector3D fromPosition, long entityId, MyHumanoidBot bot, out ItemInfo result)
        {
            result = default(ItemInfo);
            MyPlaceArea area = MyPlaceArea.FromEntity(entityId);

            if (area == null)
            {
                return(false);
            }

            var areaBoundingBox = area.WorldAABB;
            var entities        = MyEntities.GetEntitiesInAABB(ref areaBoundingBox, true);

            double closestDistanceSq = double.MaxValue;

            foreach (MyEntity entity in entities)
            {
                MyTrees trees = entity as MyTrees;
                if (trees == null)
                {
                    continue;
                }

                m_tmpEnvItemList.Clear();
                trees.GetPhysicalItemsInRadius(areaBoundingBox.Center, (float)areaBoundingBox.HalfExtents.Length(), m_tmpEnvItemList);

                foreach (var tree in m_tmpEnvItemList)
                {
                    if (!area.TestPoint(tree.Transform.Position))
                    {
                        continue;
                    }

                    if (!bot.AgentLogic.AiTarget.IsTreeReachable(entity, tree.LocalId))
                    {
                        continue;
                    }

                    double distanceSq = Vector3D.DistanceSquared(fromPosition, tree.Transform.Position);
                    if (distanceSq < closestDistanceSq)
                    {
                        result.ItemsEntityId = entity.EntityId;
                        result.ItemId        = tree.LocalId;
                        result.Target        = tree.Transform.Position;
                        closestDistanceSq    = distanceSq;
                    }
                }
                m_tmpEnvItemList.Clear();
            }

            entities.Clear();

            return(closestDistanceSq != double.MaxValue);
        }
Exemple #4
0
    public void instantiateTrees(Terrain terrain, TerrainData terrainData)
    {
        MyTrees trees = new MyTrees();

        TreePrototype[] protos = new TreePrototype[] {
            createTreePrototype(prefabTreePalm),
            createTreePrototype(prefabTreeFir),
            createTreePrototype(prefabTreeOak),
        };
        terrainData.treePrototypes = protos;
        trees.palmTree             = instantiateTree(0);
        trees.firTree = instantiateTree(1);
        trees.oakTree = instantiateTree(2);
        this.trees    = trees;
    }
Exemple #5
0
 private void ConnectDB(bool isSqlite)
 {
     MyTrees.InitTreeDB(isSqlite);
     if (isSqlite)
     {
         SelectDB();
     }
     else
     {
         UserAdmin.InitDB(MyTrees.treeDB);
         connectView = new ConnDBView(new InvokeDelegate(SelectDB), MyTrees.treeDB);
         mainGrid.Children.Remove(loginView);
         mainGrid.Children.Add(connectView);
     }
 }
Exemple #6
0
        private void Btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn      = sender as Button;
            string selectDB = btn.Content.ToString();

            MyTrees.OpenSampleData(selectDB);

            WindowView windowView = new WindowView();

            this.Content = windowView;

            this.WindowState = WindowState.Maximized;
            this.ResizeMode  = ResizeMode.CanResize;
            this.Width       = 1000;
            this.Height      = 700;
        }
Exemple #7
0
        private void StartUp(string selectDB)
        {
            MyTrees.SetDBName(selectDB);

//			new InvokeDelegate(()=>{
            WindowView windowView = new WindowView();

            mainGrid.Children.Remove(datasetListView);
            mainGrid.Children.Add(windowView);
//						        myWaiting.Visibility = Visibility.Visible;
//			                   }).BeginInvoke(ayncResult=>{
//			                myWaiting.Visibility = Visibility.Collapsed;
//			               }, null);

            this.WindowState = WindowState.Maximized;
            this.ResizeMode  = ResizeMode.CanResize;
            this.Width       = 1000;
            this.Height      = 700;
        }
        private static void FindFracturedTreesInternal(Vector3D fromPosition, MyPlaceArea area, BoundingSphereD sphere)
        {
            Debug.Assert(m_tmpFracturePieceList.Count == 0, "m_tmpFracturePieceList was not cleared after last use!");

            MyFracturedPiecesManager.Static.GetFracturesInSphere(ref sphere, ref m_tmpFracturePieceList);

            for (int i = m_tmpFracturePieceList.Count - 1; i >= 0; i--)
            {
                MyFracturedPiece fracture = m_tmpFracturePieceList[i];

                if (!MyTrees.IsEntityFracturedTree(fracture))
                {
                    m_tmpFracturePieceList.RemoveAtFast(i);
                    continue;
                }

                if (IsFracturedTreeStump(fracture))
                {
                    m_tmpFracturePieceList.RemoveAtFast(i);
                    continue;
                }

                Vector3D positionInTrunkLocal = Vector3D.Transform(fromPosition, fracture.PositionComp.WorldMatrixNormalizedInv);
                Vector3D closestPointOnTrunk;

                if (!FindClosestPointOnFracturedTree(positionInTrunkLocal, fracture, out closestPointOnTrunk))
                {
                    m_tmpFracturePieceList.RemoveAtFast(i);
                    continue;
                }

                if (!area.TestPoint(closestPointOnTrunk))
                {
                    m_tmpFracturePieceList.RemoveAtFast(i);
                    continue;
                }
            }
        }
        public static bool FindClosestTreeInRadius(Vector3D fromPosition, float radius, out ItemInfo result)
        {
            result = default(ItemInfo);

            BoundingSphereD sphere   = new BoundingSphereD(fromPosition, (double)radius);
            var             entities = MyEntities.GetEntitiesInSphere(ref sphere);

            double closestDistanceSq = double.MaxValue;

            foreach (MyEntity entity in entities)
            {
                MyTrees trees = entity as MyTrees;
                if (trees == null)
                {
                    continue;
                }

                trees.GetPhysicalItemsInRadius(fromPosition, radius, m_tmpEnvItemList);

                foreach (var tree in m_tmpEnvItemList)
                {
                    double distanceSq = Vector3D.DistanceSquared(fromPosition, tree.Transform.Position);
                    if (distanceSq < closestDistanceSq)
                    {
                        result.ItemsEntityId = entity.EntityId;
                        result.ItemId        = tree.LocalId;
                        result.Target        = tree.Transform.Position;
                        closestDistanceSq    = distanceSq;
                    }
                }
            }

            entities.Clear();

            return(closestDistanceSq != double.MaxValue);
        }