Esempio n. 1
0
 public void load()
 {
     ptext  = "<xml><start></start></xml>";
     reader = XmlReader.Create(new StringReader(ptext));
     idhash = new Dictionary <int, int>();
     myTerr = new MyTerrain();
 }
Esempio n. 2
0
 public void load(string text)
 {
     ptext  = text;
     reader = XmlReader.Create(new StringReader(ptext));
     idhash = new Dictionary <int, int>();
     myTerr = new MyTerrain();
 }
 public void load(string text)
 {
     ptext = text;
     reader = XmlReader.Create(new StringReader(ptext));
     idhash = new Dictionary<int, int>();
     myTerr = new MyTerrain();
 }
Esempio n. 4
0
    private void testApproximation()
    {
        Debug.Log("Testing Approximation class!");
        MyTerrain        t  = new MyTerrain();
        List <Vector3[]> cs = new List <Vector3[]>();

        cs.Add(new Vector3[] {
            new Vector3(0f, 0f, 0f),
            new Vector3(100f, 0f, 0f),
            new Vector3(100f, 100f, 0f),
            new Vector3(0f, 100f, 0f)
        });
        cs.Add(new Vector3[] {
            new Vector3(0f, 0f, 0f),
            new Vector3(100f, 0f, 0f),
            new Vector3(0f, 100f, 0f),
            new Vector3(0f, 0f, 0f)
        });
        t.load(cs);
        for (int i = 0; i < cs.Count; i++)
        {
            Debug.Log("- " + "Contour number " + i);
            foreach (Vector3 v in t.getApproximatedContours(3)[i])
            {
                Debug.Log("- " + v.ToString());
            }
        }
        Debug.Log("Testing Approximation finished.");
    }
Esempio n. 5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //设置全屏
            //GraphicsAdapter adapter = graphics.GraphicsDevice.Adapter;
            //graphics.PreferredBackBufferWidth = adapter.CurrentDisplayMode.Width;
            //graphics.PreferredBackBufferHeight = adapter.CurrentDisplayMode.Height;
            //graphics.ToggleFullScreen();
            //初始化二维管理器
            mySpriteManager = new MySpriteManager(this);
            //初始化摄像机
            Matrix projection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4.0f /*视野范围*/, GraphicsDevice.Viewport.AspectRatio /*按屏幕比例转换*/, 1.0f /*最近距离*/, 10000.0f /*最远距离*/);

            myCamera          = new MyCamera(new Vector3(0, 0, 1000), Vector3.Forward, Vector3.Up, projection);
            my3DSpriteManager = new MyModelManager(this, myCamera);
            //初始化天空球
            mySky      = new MySkysphere(this);
            mySky.View = myCamera.View;
            //创建菜单
            myMenu = new MyMenu(this);
            //创建地形
            myTerrain          = new MyTerrain(this, Content.Load <Texture2D>("heightmap"), Content.Load <Texture2D>("GrassTx"), myCamera);
            myTerrain.Scale    = new Vector3(10, 150, 10);
            myTerrain.Position = new Vector3(-600, -200, 1000);
            //创建寻路算法测试
            foundRoad = new FoundRoadTest(this, graphics);

            Components.Add(foundRoad);
            Components.Add(myTerrain);
            Components.Add(mySky);
            Components.Add(mySpriteManager);
            Components.Add(my3DSpriteManager);
            Components.Add(myMenu);
            base.Initialize();
        }
 public void load()
 {
     ptext = "<xml><start></start></xml>";
     reader = XmlReader.Create(new StringReader(ptext));
     idhash = new Dictionary<int, int>();
     myTerr = new MyTerrain();
 }
Esempio n. 7
0
 private void InitModificator()
 {
     if (terrainModificator == null)
     {
         MyTerrain t = MyTerrain.GetTerrain();
         terrainModificator = new Modificator(t);
     }
 }
Esempio n. 8
0
 public void loadStringFromFile(string path)
 {
     try {
         ptext  = File.ReadAllText(path);
         myTerr = new MyTerrain();
     }
     catch (Exception e) {
         Debug.LogError("Nenasiel sa file " + e.Message);
     }
 }
Esempio n. 9
0
 private void UpdateTerrain()
 {
     if (HasChangedData() && MyTerrain.IsInitalized())
     {
         MyTerrain.GetTerrain().BeachWidth  = BeachWidth;
         MyTerrain.GetTerrain().SeaLevel    = SeaLevel;
         MyTerrain.GetTerrain().ScaleFactor = HeightMultiplier;
         //  MyTerrainV2.GetTerrain().BeachWidth = BeachWidth;
     }
 }
Esempio n. 10
0
 public Chunk(GameObject gameObject, Material material)
 {
     go                    = gameObject;
     meshFilter            = go.AddComponent <MeshFilter>();
     meshRenderer          = go.AddComponent <MeshRenderer>();
     meshRenderer.material = material;
     position              = new Vector3(go.transform.position.x / WIDTH, go.transform.position.y / HEIGHT, go.transform.position.z / DEPTH);
     terrainGO             = GameObject.Find("Terrain");
     terrain               = terrainGO.GetComponent <MyTerrain>();
 }
 public void loadStringFromFile(string path)
 {
     try {
         ptext = File.ReadAllText(path);
         myTerr = new MyTerrain();
     }
     catch (Exception e) {
         Debug.LogError("Nenasiel sa file " + e.Message);
     }
 }
Esempio n. 12
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Esempio n. 13
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MyTerrain myTerrain = (MyTerrain)target;

        if (GUILayout.Button("update terrain"))
        {
            myTerrain.CreateMesh();
        }
    }
Esempio n. 14
0
        private MyTerrain CreateTerrainChunk(float[,] heights, Vector2 pos)
        {
            Rect rect = RectUtils.OverlapRect(new Rect(pos.x * (MyTerrain.maxChankSize - 1), pos.y * (MyTerrain.maxChankSize - 1), MyTerrain.maxChankSize, MyTerrain.maxChankSize), terrainRect);

            MyTerrain tmpMyTerrain = Instantiate(myTearrainGO).GetComponent <MyTerrain>();

            tmpMyTerrain.gameObject.transform.SetParent(transform, false);
            tmpMyTerrain.gameObject.transform.position += new Vector3(pos.x * MyTerrain.maxChankSize - pos.x, 0, pos.y * MyTerrain.maxChankSize - pos.y);
            tmpMyTerrain.Init(heights, rect);
            return(tmpMyTerrain);
        }
Esempio n. 15
0
 private void GuaranteeTerrainInitialization()
 {
     if (Terrain == null)
     {
         Terrain = MyTerrain.GetTerrainAndInitializeIfNeeded(
             GetComponent <TerrainProperties>().Heightmap,
             GetComponent <TerrainProperties>().SeaLevel,
             GetComponent <TerrainProperties>().BeachWidth,
             GetComponent <TerrainProperties>().HeightMultiplier);
     }
 }
Esempio n. 16
0
    private void Awake()
    {
        string realPath = Application.streamingAssetsPath + "/" + Path;

        if (File.Exists(realPath))
        {
            //字符流读取地形文件,并创建地形对象
            MyTerrain = new MyTerrain(File.ReadAllText(realPath));
        }

        MeshFilter   meshFilter   = gameObject.AddComponent <MeshFilter>();
        MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>();

        meshRenderer.material = Material;
        MyTerrain.SetMeshFilter(meshFilter);
    }
        public override void Execute(MyTerrain terrain, float intensity, Vector3 pointInWC)
        {
            int[] pointInImageCoordinate = WorldCoordinateToImageCoordinate(terrain, pointInWC);
            //Agora tenho a posição na imagem. Vou alterar o valor do pixel e atualizar o terreno
            Texture2D hm       = terrain.Heightmap;//Necessário  criar essa variável local pra forçar o setter do Heightmap, que flaga como Dirty
            Color     oldColor = hm.GetPixel(pointInImageCoordinate[0], pointInImageCoordinate[1]);
            Color     newColor = new Color(0, 0, 0);

            if (RaiseOrLower == ElevationChange.Lower)
            {
                newColor = oldColor - new Color(1.0f * intensity, 1.0f * intensity, 1.0f * intensity);
            }
            if (RaiseOrLower == ElevationChange.Raise)
            {
                newColor = oldColor + new Color(1.0f * intensity, 1.0f * intensity, 1.0f * intensity);
            }
            hm.SetPixel(pointInImageCoordinate[0], pointInImageCoordinate[1], newColor);
            terrain.Heightmap = hm;
        }
        //        https://en.wikipedia.org/wiki/Gaussian_function
        //        Olhar a sessão de gaussiano 2d
        public override void Execute(MyTerrain terrain, float intensity, Vector3 pointInWC)
        {
            int[] pointInImageCoordinate = WorldCoordinateToImageCoordinate(terrain, pointInWC);
            //pointInImageCoordinate é o centro da função gaussiana
            List <float> gaussianMaskPoints = new List <float>();
            int          width = terrain.Heightmap.width;//Assumo quadrado

            if (intensity == 0)
            {
                intensity = 0.001f;
            }
            float     sigmaX = intensity * 10.0f;
            float     sigmaY = intensity * 10.0f;
            float     A      = intensity / 50;
            Texture2D tex    = terrain.Heightmap;

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    int[] p          = new int[] { x, z };
                    float v          = EvaluateGaussian(pointInImageCoordinate, p, sigmaX, sigmaY, A);
                    Color oldColor   = terrain.Heightmap.GetPixel(x, z);
                    Color valueToAdd = new Color(v, v, v);
                    Color newColor;
                    if (this.RaiseOrLower == ElevationChange.Lower)
                    {
                        newColor = oldColor - valueToAdd;
                    }
                    else
                    {
                        newColor = oldColor + valueToAdd;
                    }
                    tex.SetPixel(x, z, newColor);
                }
            }
            tex.Apply();
            terrain.Heightmap = tex;
            //SaveTextureToFile(tex, "/Debug/debug" + (++ct) + ".png");
        }
 public override void Execute(MyTerrain terrain, float intensity, Vector3 pointInWC)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 20
0
        //Inventory
        //----------------------------------------

        private void take_Or_Place_Item()
        {
            Ray cameraRay = cam.ScreenPointToRay(Input.mousePosition);

            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit[] hits;
                hits = Physics.RaycastAll(cameraRay, 2f);
                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.tag == "Block" || hit.collider.tag == "Vehicles" || hit.collider.tag == "Turret" || hit.collider.tag == "Chest")
                    {
                        Transform parent = hit.collider.transform;
                        if (hit.collider.tag != "Block")
                        {
                            parent = OtherMetods.FindParent(hit.collider.transform, "Entitys");
                        }
                        if (parent == null)
                        {
                            return;
                        }

                        int idItem = Id.getId(parent.name);

                        ItemInventory item = new ItemInventory(idItem, 1, Id.TypeItem.None);

                        if (hit.collider.tag == "Block")
                        {
                            item.type = Id.TypeItem.Block;
                        }
                        else
                        {
                            item.type = Id.TypeItem.Entity;
                        }

                        inventoryExchangeItems.inventory.AddItemInventory(item);

                        Destroy(parent.gameObject);
                        break;
                    }
                }
            }
            else if (Input.GetMouseButtonDown(1))
            {
                if (inventoryExchangeItems.inventory.arrItems[inventoryExchangeItems.inventory.currentItemToolbar].count > 0)
                {
                    RaycastHit hit;
                    Ray        ray = new Ray(cam.transform.position, cameraRay.direction * 2f);

                    ItemInventory item = inventoryExchangeItems.inventory.arrItems[inventoryExchangeItems.inventory.currentItemToolbar];

                    if (item.count > 0 && item.type != Id.TypeItem.None)
                    {
                        switch (item.type)
                        {
                        case Id.TypeItem.Block:
                        {
                            if (Physics.Raycast(ray, out hit, 2f))
                            {
                                int x, y, z;
                                x = Mathf.RoundToInt(hit.point.x);
                                y = Mathf.RoundToInt(hit.point.y);
                                z = Mathf.RoundToInt(hit.point.z);
                                if (hit.point.x % 0.5 == 0)
                                {
                                    if (transform.position.x < hit.point.x)
                                    {
                                        if (x != (int)hit.point.x)
                                        {
                                            x--;
                                        }
                                    }
                                    else
                                    {
                                        if (x != (int)hit.point.x + 1)
                                        {
                                            x++;
                                        }
                                    }
                                }
                                if (hit.point.y % 0.5 == 0)
                                {
                                    if (cam.transform.position.y < hit.point.y)
                                    {
                                        if (y != (int)hit.point.y)
                                        {
                                            y--;
                                        }
                                    }
                                    else
                                    {
                                        if (y != (int)hit.point.y + 1)
                                        {
                                            y++;
                                        }
                                    }
                                }
                                if (hit.point.z % 0.5 == 0)
                                {
                                    if (transform.position.z < hit.point.z)
                                    {
                                        if (z != (int)hit.point.z)
                                        {
                                            z--;
                                        }
                                    }
                                    else
                                    {
                                        if (z != (int)hit.point.z + 1)
                                        {
                                            z++;
                                        }
                                    }
                                }

                                MyTerrain.CreateBlock(item.id, new Vector3(x, y, z));
                            }
                            break;
                        }

                        case Id.TypeItem.Entity:
                        {
                            Vector3 pos = transform.position + transform.forward * 5;
                            MyTerrain.CreateEntity(item.id, pos, transform.rotation);
                            break;
                        }
                        }
                        inventoryExchangeItems.inventory.arrItems[inventoryExchangeItems.inventory.currentItemToolbar].count--;
                        if (inventoryExchangeItems.inventory.arrItems[inventoryExchangeItems.inventory.currentItemToolbar].count == 0)
                        {
                            inventoryExchangeItems.inventory.arrItems[inventoryExchangeItems.inventory.currentItemToolbar].type = Id.TypeItem.None;
                            inventoryExchangeItems.inventory.arrItems[inventoryExchangeItems.inventory.currentItemToolbar].id   = -1;
                        }
                    }
                }
            }
        }