Пример #1
0
        public Chunk(Planet planet, int i, int u, int v, ShapeGenerator shapeGenerator)
        {
            this.shapeGenerator = shapeGenerator;
            this.planet         = planet;
            this.face           = planet.terrainFaces[i];
            this.faceI          = i;
            this.faceU          = u;
            this.faceV          = v;
            this.shapeData      = this.planet.shapeData;

            chunkID = "Chunk " + faceI + " (" + faceU + "," + faceV + ")";

            SetLOD();

            //Centre point
            int ResM1 = chunkResolution - 1;

            float   UVstep = 1f / shapeData.chunksPerFace;
            float   step   = UVstep / ResM1;
            Vector2 offset = new Vector3((-0.5f + faceU * UVstep), (-0.5f + faceV * UVstep));

            int x = chunkResolution / 2;

            Vector2 p = offset + new Vector2(x * step, x * step);
            Vector3 pointOnUnitCube   = face.axisB * p.x + face.axisA * p.y + face.height * -0.5f;
            Vector3 pointOnUnitSphere = SphereMaths.UnitCubeToUnitSphere(pointOnUnitCube);
            Vector3 point             = planet.ShapeGenerator.CalculatePointOnPlanet(pointOnUnitSphere);

            this.centre = GeoCoord.GetLatLon(planet, point);
        }
Пример #2
0
        public void CacheChunks(Chunk[] chunks)
        {
            for (int j = 0; j < chunks.Length; j++)
            {
                if (chunks[j].hasMesh)
                {
                    chunks[j].gameObject.SetActive(false);
                }
            }

            for (int i = 0; i < triggerObjects.Length; i++)
            {
                float  nearestDist  = Mathf.Infinity;
                Chunk  nearestChunk = null;
                LatLon position     = GeoCoord.GetLatLon(planet, triggerObjects[i].position);

                for (int j = 0; j < chunks.Length; j++)
                {
                    float dist = GeoCoord.GetDistance(position, chunks[j].centre);
                    if (dist < nearestDist)
                    {
                        nearestDist  = dist;
                        nearestChunk = chunks[j];
                    }
                }

                if (nearestChunk != null)
                {
                    ActivateChunk(nearestChunk);
                    Chunk[] connectedChunks = nearestChunk.ConnectedChunks;
                    for (int j = 0; j < connectedChunks.Length; j++)
                    {
                        ActivateChunk(connectedChunks[j]);
                    }
                }
            }
        }
Пример #3
0
 //A quick script to get pos above ground
 public virtual LatLon GetGeoPos()
 {
     return(GeoCoord.GetLatLon(gb, transform.position));
 }