Exemplo n.º 1
0
    // this is called when the planet generator is ready
    public void UpdateTerrainGridNow()
    {
        // get to the player data
        var playerData = DataController.m_instance.m_playerData;

        // get the planet controller
        var planetController = SpaceflightController.m_instance.m_starSystem.GetPlanetController(playerData.m_general.m_currentPlanetId);

        // save the planet generator
        m_planetGenerator = planetController.GetPlanetGenerator();

        // create the elevation texture
        var elevationTexture = m_planetGenerator.CreateElevationTexture();

        m_terrainGrid.SetElevationMap(elevationTexture, m_planetGenerator);

        // place the arth ship at the selected landing coordinates
        var shipPosition = Tools.LatLongToWorldCoordinates(playerData.m_general.m_selectedLatitude, playerData.m_general.m_selectedLongitude);

        m_arthShip.transform.localPosition = shipPosition;

        var minimumElevation = float.MaxValue;
        var chosenAngle      = 0;

        for (var angle = 0; angle < 360; angle += 15)
        {
            m_arthShip.transform.localRotation = Quaternion.Euler(0.0f, angle, 0.0f);

            var maximumElevation = float.MinValue;

            for (var z = m_arthShipGroundScanHeight * -0.5f; z <= m_arthShipGroundScanHeight * 0.5f; z += m_arthShipGroundScanInterval)
            {
                var modifiedScanWidth = m_arthShipGroundScanWidth * ((z >= (m_arthShipGroundScanHeight * -0.075f)) ? 0.5f : 1.0f);

                for (var x = modifiedScanWidth * -0.5f; x <= modifiedScanWidth * 0.5f; x += m_arthShipGroundScanInterval)
                {
                    var groundScanPosition = m_arthShip.transform.TransformPoint(new Vector3(x, 0.0f, z));

                    groundScanPosition = ApplyElevation(groundScanPosition, false);

                    if (groundScanPosition.y > maximumElevation)
                    {
                        maximumElevation = groundScanPosition.y;
                    }
                }
            }

            // Debug.Log( "Angle = " + angle + ", maximum elevation = " + maximumElevation );

            if (maximumElevation < minimumElevation)
            {
                minimumElevation = maximumElevation;
                chosenAngle      = angle;
            }
        }

        // Debug.Log( "Minimum elevation = " + minimumElevation + ", angle chosen = " + chosenAngle );

        shipPosition.y = minimumElevation + m_arthShipElevationAboveGround;

        m_arthShip.transform.localPosition = shipPosition;
        m_arthShip.transform.localRotation = Quaternion.Euler(0.0f, chosenAngle, 0.0f);

        // initialize the terrain vehicle
        m_terrainVehicle.Initialize();
    }