示例#1
0
    public override bool InstantiateLibraryObject(LibraryObject libObj)
    {
        //return base.InstantiateLibraryObject(libObj);

        // DONT raycast planes, but place it by GPS difference
        if (!hasDetectedPlane || !hasGPSData || !hasCompassData)
        {
            return(false);
        }

        GeolocatedObject geoObj = libObj as GeolocatedObject;

        if (geoObj == null)
        {
            Debug.Log("object is not Geolocated");
            return(false);
        }

        LocationTools.LocationData to = new LocationTools.LocationData();
        to.latitude  = geoObj.latitude;
        to.longitude = geoObj.longitude;
        Vector3 offset = LocationTools.GetMetersDistanceHeadingNorth(gpsData, to);

        Vector3 camPosOnFloor = detectedPlane.plane.ClosestPointOnPlane(Camera.main.transform.position);
        //Vector3 worldPos = camOnPlane + Quaternion.identity * offset; // assuming north is forward for now

        // ORIENT North to apply offset
        Vector3 headingVector = Camera.main.transform.up; // Cam up is heading compassHeading (top of screen vector)

        if (Camera.main.transform.forward.y >= 0)
        {
            // If cam is looking to the sky - then we have to use the FWD instead, since compass heading seems to be in accordance with Forward instead of Up
            headingVector = Camera.main.transform.forward;
        }
        //-project into the plane and get north in plane
        Vector3 headingOnFloor = Vector3.ProjectOnPlane(headingVector, detectedPlane.plane.normal).normalized;
        Vector3 northOnFloor   = Quaternion.AngleAxis(-compassHeading, Vector3.up) * headingOnFloor;

        northOnFloor = northOnFloor.normalized;
        Vector3 worldPos = camPosOnFloor + Quaternion.FromToRotation(Vector3.forward, northOnFloor) * offset;

        Debug.Log("Instantiating Geolocated obj. GPSData: (" + gpsData.latitude + "," + gpsData.longitude + ")" +
                  " CompassHeading: " + compassHeading +
                  " metersDist: " + offset.ToString("F2") +
                  " Resulting worldPos: " + worldPos.ToString("F2")
                  );

        GameObject obj = InstantiateLibraryObject(libObj, worldPos);

        //obj.transform.rotation = Quaternion.FromToRotation(Vector3.forward, northOnPlane);// when heading is exactly 180.0 Unity AngleAxis chooses to make a rotation in X axis instead of Y, turning things up-down
        obj.transform.rotation = Quaternion.LookRotation(northOnFloor, Vector3.up); // Orient North - model is done with fwd North
        return(true);
    }
示例#2
0
    private void Update()
    {
        if (!objectInstantiated)
        {
            if (Input.compass.enabled &&
                (!hasCompassData || compassHeading != Input.compass.trueHeading))
            {
                compassHeading = Input.compass.trueHeading;
                onCompassData.Invoke(compassHeading);
                hasCompassData = true;
            }
            if (Input.location.status == LocationServiceStatus.Running &&
                (!hasGPSData ||
                 gpsData.latitude != Input.location.lastData.latitude ||
                 gpsData.longitude != Input.location.lastData.longitude))
            {
                gpsData           = new LocationTools.LocationData();
                gpsData.latitude  = Input.location.lastData.latitude;
                gpsData.longitude = Input.location.lastData.longitude;
                onGPSData.Invoke(gpsData);
                hasGPSData = true;
            }

#if UNITY_EDITOR
            compassHeading = editorDebugHeading;
            onCompassData.Invoke(compassHeading);
            hasCompassData = true;

            gpsData = editorDebugGPSData;
            onGPSData.Invoke(gpsData);
            hasGPSData = true;
#endif

            CheckInstantiation();
        }
    }
示例#3
0
 public void OnGPS(LocationTools.LocationData gpsData)
 {
     toggleGPS.isOn = true;
     textGPS.text   = gpsData.latitude.ToString() + "\n" + gpsData.longitude.ToString();
 }