Ejemplo n.º 1
0
    /**
     * A utility function which returns the world origin based on values in
     * the LVC configuration file. Defaults to (0,0,0) if no values are set in
     * the configuration.
     */
    private static void InitializeLVCWorldOrigin()
    {
        // have we already done this?
        if( isLvcWorldOriginInitialised )
            // no need to go any further
            return;

        // check for values specified in configuration file
        if( LVCUtils.HasAllLVCConfigValues( CONF_UNITYCLIENT_FILENAME,
                                         new string[]{CONF_OriginLatitude, CONF_OriginLongitude}) )
        {
            // user has specified the world origin using latitude, longitude and altitude
            // check if they have used the 93*23'52.60" style format for degress minutes and seconds,
            // or specified  it as a decimal value in radians...
            double latitude = 0.0;
            string latitudeStr = GetLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginLatitude, "0.0" );
            double longitude = 0.0;
            string longitudeStr = GetLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginLongitude, "0.0" );
            try
            {
                // assume latitude is in raw radians to begin with
                latitude = System.Convert.ToDouble( latitudeStr );
            }
            catch(System.FormatException)
            {
                // fall back to d*m's" notation for latitude
                latitude = Degrees2Radians( DMStoDegrees( latitudeStr) );
            }
            try
            {
                // assume longitude is in raw radians to begin with
                longitude = System.Convert.ToDouble( longitudeStr );
            }
            catch(System.FormatException)
            {
                // fall back to d*m's" notation for longitude
                longitude = Degrees2Radians( DMStoDegrees( longitudeStr) );
            }

            // altitude is simple as it is in meters - just get the value
            double altitude = GetDoubleLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginAltitude, 0.0 );

            // initialise the world origin vector
            lvcWorldOriginLLA = new LVCGame.Vector3( latitude, longitude, altitude );
            lvcWorldOriginUTM = LVCGame.LVCCoordinates.llaToUtm( ref lvcWorldOriginLLA );
        }
        else if( HasAllLVCConfigValues(CONF_UNITYCLIENT_FILENAME,
                                             new string[]{CONF_OriginEasting, CONF_OriginNorthing, CONF_OriginHemisphere, CONF_OriginZone}) )
        {
            // user has specified the world origin using UTM (Easting, Northing, Hemisphere and Zone)
            double easting = GetDoubleLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginEasting, 0.0 );
            double northing = GetDoubleLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginNorthing, 0.0 );
            double altitude = GetDoubleLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginAltitude, 0.0 );
            char hemisphere = GetLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginHemisphere, "N" )[0];
            int zone = GetIntLVCConfigValue( CONF_UNITYCLIENT_FILENAME, CONF_OriginZone, 0 );

            // initialise the world origin from the extracted UTM values
            lvcWorldOriginUTM = new LVCGame.UTMCoordinate( easting, northing, altitude, zone, hemisphere );
            lvcWorldOriginLLA = LVCGame.LVCCoordinates.utmToLla( ref lvcWorldOriginUTM );
        }
        else
        {
            // assume that the world origin is at lat/long (0*0'0", 0*0'0")
            lvcWorldOriginUTM = new LVCGame.UTMCoordinate( 166021, 0, 0, 31, 'N' );
            lvcWorldOriginLLA = new LVCGame.Vector3( 0.0, 0.0, 0.0 );
        }

        Debug.Log("World origin is at LLA ("+LVCUtils.RadiansToDMS(lvcWorldOriginLLA.x, 2)+", "
                                            +LVCUtils.RadiansToDMS(lvcWorldOriginLLA.y, 2)+", "
                                            +lvcWorldOriginLLA.z+"m)"
                                            +", UTM ("+DisplayFormatted(lvcWorldOriginUTM)+")" );

        // ...and we're done.
        isLvcWorldOriginInitialised = true;
    }
Ejemplo n.º 2
0
 /**
  * Convert a Unity Engine Quaternion orientation into an LVC Game Vector 3, correcting for
  * the different interpretations of rotation axes between the systems
  *       AXIS (+ve): | UNITY | LVC |
  *       ------------+-------+-----
  *       ROLL        |   X   | -Z
  *       YAW         |   Y   |  X
  *       PITCH       |   Z   |  Y
  *
  * @param UEv3 the Unity Engine Vector3 to convert
  * @return the equivalent LVC Game Vector3, with corrected axes
  */
 public static LVCGame.Vector3 UnityOrientation_to_LVCGameOrientation( UnityEngine.Quaternion orientation )
 {
     UnityEngine.Vector3 eulerAngles = orientation.eulerAngles;
     LVCGame.Vector3 result = new LVCGame.Vector3(
          LVCUtils.Degrees2Radians( eulerAngles.y ), // YAW
          LVCUtils.Degrees2Radians( eulerAngles.z ), // PITCH
         -LVCUtils.Degrees2Radians( eulerAngles.x )  // ROLL
     );
     return result;
 }