Beispiel #1
0
    public void BuildFromLandingSpot(SphericalCoord landingSpot)
    {
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        terrainChunks = new DynamicTerrainChunk[numCols, numRows];

        // Create the center chunk.

        Quaternion rotation = CoordHelper.SphericalToRotation(landingSpot);

        if (rotTest)
        {
            rotation *= Quaternion.Euler(0, 0, 45);
        }

        Vector3 position = new Vector3(
            (-WorldUnitsPerChunk / 2f),
            0,
            (-WorldUnitsPerChunk / 2f)
            );

        // FIXME: Hardcoded?
        terrainChunks[1, 1] = BuildChunk(rotation, position);

        BuildChunkArray();

        //RebuildChunks();
        sw.Stop();
        Debug.Log("Terrain generation time: " + (sw.ElapsedMilliseconds / 1000f));
    }
    /// <summary>
    /// Converts a SphericalCoord (Lat/Lon) into a Vector3 that represents
    /// the position of the Lat/Lon on this terrain chunk
    /// </summary>
    /// <param name="sc">Sc.</param>
    Vector3 SphericalToLocalPosition(SphericalCoord sc)
    {
        //Debug.Log( gameObject.name + " -- " + sc.ToString());

        Quaternion buildingQat = CoordHelper.SphericalToRotation(sc);

        float xAngleDiff = buildingQat.eulerAngles.x - ChunkRotation.eulerAngles.x;

        while (xAngleDiff < -360)
        {
            xAngleDiff += 360;
        }
        while (xAngleDiff > 360)
        {
            xAngleDiff -= 360;
        }

        float yAngleDiff = buildingQat.eulerAngles.y - ChunkRotation.eulerAngles.y;

        //Debug.Log( gameObject.name + " -- xAngleDiff: " + xAngleDiff);
        //Debug.Log( gameObject.name + " -- yAngleDiff: " + yAngleDiff);

        Vector3 distFromCenter = new Vector3(
            ((yAngleDiff / DegreesPerChunk)) * WorldUnitsPerChunk,
            0,  // HEIGHT of building
            ((xAngleDiff / DegreesPerChunk)) * WorldUnitsPerChunk
            );

        // Rotate the vector based on chunk's rotation
        // FIXME:   I AM WRONG HERE. MAKE MATH MORE BETTER PLEASE
        // Do we need to incorporate longitude? I think we do.
        //   I think we need to check the different in longitude between the center of the
        //   terrain chunk and where the building is.
        distFromCenter = Quaternion.Euler(0, -ChunkRotation.eulerAngles.z, 0) * distFromCenter;

        // Now move the vector's origin to the bottom-left corner and return that

        return(distFromCenter + new Vector3(WorldUnitsPerChunk / 2, 0, WorldUnitsPerChunk / 2));
    }
Beispiel #3
0
    public void BuildFromLandingSpot(SphericalCoord landingSpot)
    {
        terrainChunks = new DynamicTerrainChunk[numCols, numRows];

        // Create the center chunk.

        Quaternion rotation = CoordHelper.SphericalToRotation(landingSpot);

        //rotation *= Quaternion.Euler( 0, 0, 45 );

        Vector3 position = new Vector3(
            (-WorldUnitsPerChunk / 2f),
            0,
            (-WorldUnitsPerChunk / 2f)
            );

        // FIXME: Hardcoded?
        terrainChunks[1, 1] = BuildChunk(rotation, position);

        BuildChunkArray();

        //RebuildChunks();
    }