Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (simulatePose)
        {
            // use this predefines pose
            Quaternion q = new Quaternion(-0.2f, -0.8f, 0.4f, 0.4f);
            Vector3    p = new Vector3(14.7f, 12.8f, 203.0f);
            if (tranformCamera)
            {
                setCameraPosition(p, q);
            }
            else
            {
                transform.position = p;
                transform.rotation = q;
            }
            return;
        }

        int isTracking = MetaioSDKUnity.getTrackingValues(cosID, trackingValues);

        // Debug.Log("cosID " + cosID + ", isTracking: " + isTracking);

        if (isTracking > 0)
        {
            // Metaio SDK: RHS with X=right (on marker) Y=up (on marker, i.e. back) Z=up (away from marker)
            // Unity: LHS with X=right Y=up Z=back

            Quaternion q;
            q.x = -trackingValues[3];
            q.y = -trackingValues[4];
            q.z = trackingValues[5];
            q.w = trackingValues[6];
            Quaternion mul = new Quaternion(1, 0, 0, -1);
            q *= mul;

            //translation
            Vector3 p;
            p.x = trackingValues[0];
            p.y = trackingValues[1];
            p.z = -trackingValues[2];

//			Debug.Log("Cartesian translation: "+p);

            // Apply geo-location if specified
            if (geoLocation.x != 0f && geoLocation.y != 0f)
            {
                // convert LLA to cartesian translation
                MetaioSDKUnity.convertLLAToTranslation(geoLocation.x, geoLocation.y, enableLLALimits?1:0, translation);
//				Debug.Log("LLA translation: "+translation[0]+", "+translation[1]+", "+translation[2]);

                // Augment LLA cartesian translation
                Vector3 tLLA;
                tLLA.x = translation[1];
                tLLA.y = translation[2];
                tLLA.z = -translation[0];
                p      = p + q * tLLA;
            }

//			Debug.Log("Final translation: "+p);

            if (tranformCamera)
            {
                setCameraPosition(p, q);
            }
            else
            {
                transform.position = p;
                transform.rotation = q;
            }
            // show childs
            enableRenderingChilds(true);
        }
        else
        {
            // hide because target not tracked
            enableRenderingChilds(false);
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (simulatePose)
        {
            // use this predefined pose
            Quaternion q = new Quaternion(-0.2f, -0.8f, 0.4f, 0.4f);
            Vector3    p = new Vector3(14.7f, 12.8f, 203.0f);

            setCameraOrTrackerPosition(p, q);

            return;
        }

        int isTracking = MetaioSDKUnity.getTrackingValues(cosID, trackingValues);

        // Debug.Log("cosID " + cosID + ", isTracking: " + isTracking);

        if (isTracking > 0)
        {
            // Metaio SDK: RHS with X=right (on marker) Y=up (on marker, i.e. back) Z=up (away from marker)
            // Unity: LHS with X=right Y=up Z=back
            currentlyTracking = true;

            Quaternion q;
            q.x = -trackingValues[3];
            q.y = -trackingValues[4];
            q.z = trackingValues[5];
            q.w = trackingValues[6];
            Quaternion mul = new Quaternion(1, 0, 0, -1);
            q *= mul;

            // Must normalize quaternion because else may give wrong results when multiplying with vector
            double qLenRecip = 1.0 / Math.Sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
            q.x = (float)(q.x * qLenRecip);
            q.y = (float)(q.y * qLenRecip);
            q.z = (float)(q.z * qLenRecip);
            q.w = (float)(q.w * qLenRecip);

            //translation
            Vector3 p;

            // Apply geo-location if specified
            if (geoLocation.x != 0f && geoLocation.y != 0f)
            {
                // convert LLA to cartesian translation
                MetaioSDKUnity.convertLLAToTranslation(geoLocation.x, geoLocation.y, enableLLALimits?1:0, translation);
                //Debug.Log("LLA translation: "+translation[0]+", "+translation[1]+", "+translation[2]);

                Vector3 tLLA;
                tLLA.x = translation[0];
                tLLA.y = translation[2];
                tLLA.z = translation[1];

                // tLLA is relative to current GPS location
                p = q * tLLA;
            }
            else
            {
                p.x = trackingValues[0];
                p.y = trackingValues[1];
                p.z = -trackingValues[2];
            }

            setCameraOrTrackerPosition(p, q);

            // show childs
            enableRenderingChilds(true);
        }
        else
        {
            currentlyTracking = false;
            // hide because target not tracked
            enableRenderingChilds(false);
        }
    }