Пример #1
0
    /// <summary>
    /// Loads 3D coordinates of features contained in the map
    /// </summary>
    public void loadMap(String mapPath)
    {
        clearMap();
        loadedFeatures = 0;
        totalFeatures  = MetaioSDKUnity.get3DPointsFrom3Dmap(Path.Combine(Application.streamingAssetsPath, mapPath), featuresRaw);
        Debug.Log(String.Format("Loaded map has {0} features", totalFeatures));

        map = new GameObject("Feature Map") as GameObject;
        map.AddComponent <EditorOnly>();
        map.tag = "EditorOnly"; // as set through editor
        metaioTracker[] trackers = (metaioTracker[])GameObject.FindObjectsOfType(typeof(metaioTracker));
        foreach (metaioTracker tracker in trackers)
        {
            if (tracker.cosID == 1)
            {
                map.transform.parent = tracker.transform;
                break;
            }
        }

        // we transform the map due to differences between Unity COS and metaio COS
        map.transform.eulerAngles = mapRotation;
        map.transform.localScale  = mapScale;

        Debug.Log("Start loading map... Don't delete Feature Map object while loading!");
    }
Пример #2
0
    private void createTexture()
    {
        uint movieWidth  = MetaioSDKUnity.getMovieTextureWidth(movieGeometry);
        uint movieHeight = MetaioSDKUnity.getMovieTextureHeight(movieGeometry);

        // Shouldn't happen, dimensions are initialized by now
        if (movieWidth == 0 || movieHeight == 0)
        {
            throw new Exception("Movie not loaded yet, width/height is zero");
        }

        int textureSizeX = nextPowerOf2(movieWidth);
        int textureSizeY = nextPowerOf2(movieHeight);

        Texture2D texture = new Texture2D(textureSizeX, textureSizeY, TextureFormat.RGBA32, false);

        // User has to set transparency-supporting shader himself since he might as well overwrite the shader with
        // a custom one, so we do not force anyone to use the Unity built-in shader
        Material mat = gameObject.renderer.material;

        texture.wrapMode = TextureWrapMode.Clamp;
        mat.mainTexture  = texture;

        // Most videos are not a power of 2 in dimensions, so scale the UV coordinates appropriately.
        // Unity seems to interpret the (0,0) coordinate of OpenGL textures as bottom left, so we
        // need to vertically flip the V coordinate here.
        mat.mainTextureScale  = new Vector2((float)movieWidth / textureSizeX, -(float)movieHeight / textureSizeY);
        mat.mainTextureOffset = new Vector2(0, (float)movieHeight / textureSizeY);

        textureID = texture.GetNativeTextureID();

        Debug.Log(string.Format("Texture ID for movie {0} ({1}x{2}): {3}", movieFile, movieWidth, movieHeight, textureID));
    }
Пример #3
0
    private void calcHandEyeCalibrationInverse(Matrix4x4 trackingMatrix, CameraType cameraType, out Matrix4x4 outInverted)
    {
        Vector3    translation;
        Quaternion rotation;

        MetaioSDKUnity.getHandEyeCalibration(out translation, out rotation, cameraType);

        Matrix4x4 rotationMatrix = new Matrix4x4();

        NormalizeQuaternion(ref rotation);
        rotationMatrix.SetTRS(Vector3.zero,
                              rotation,
                              new Vector3(1.0f, 1.0f, 1.0f));

        Matrix4x4 translationMatrix = new Matrix4x4();

        translationMatrix.SetTRS(translation,
                                 new Quaternion(0.0f, 0.0f, 0.0f, 1.0f),
                                 new Vector3(1.0f, 1.0f, 1.0f));

        Matrix4x4 composed = translationMatrix * rotationMatrix;

        composed *= trackingMatrix;

        outInverted = composed.inverse;
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (updateScreenOrientation())
        {
            // also update size/orientation of metaio SDK and camera projection
            // matrix
            MetaioSDKUnity.resizeRenderer(Screen.width, Screen.height);
            MetaioSDKUnity.updateScreenOrientation(screenOrientation);
            metaioCamera.updateCameraProjectionMatrix();
        }

        // Try to create the texture (must call every frame in case required size changes)
        textureCreated = createTexture(0);

        if (textureCreated)
        {
            updateCameraPlaneScale();
        }

        // TODO: GL.IssuePluginEvent should be used on all platforms,
        // but in Unity 3.5.x, the callbacks in the native plugin are
        // never called. Check if they work in Unity 4.x.
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR
        GL.IssuePluginEvent(textureID);
#elif UNITY_ANDROID || UNITY_IPHONE
        MetaioSDKUnity.UnityRenderEvent(textureID);
#endif
    }
Пример #5
0
    public void updateCameraPlaneScale()
    {
        // determine scale of the camera plane
        float scale = MetaioSDKUnity.getCameraPlaneScale();

        if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
        {
            // Windows
            cameraPlane.transform.localScale = new Vector3(-scale, scale, -scale);
        }
        else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
        {
            // OSX
            cameraPlane.transform.localScale = new Vector3(-scale, scale, scale);
        }
        else if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
        {
            // Android and iOS
            cameraPlane.transform.localScale = new Vector3(-scale, scale, scale);
        }
        else
        {
            Debug.LogError("Unsupported platform: " + Application.platform);
        }
    }
Пример #6
0
    /// <summary>
    /// Create camera texture and set it to the camera plane
    /// </summary>
    /// <returns>
    /// true when texture is created, else false
    /// </returns>
    public bool createTexture(uint enforceSize)
    {
        uint requiredSize;

        if (enforceSize > 0)
        {
            requiredSize = enforceSize;
        }
        else
        {
            requiredSize = MetaioSDKUnity.getRequiredTextureSize();
        }

        if (requiredSize <= 0)
        {
            return(false);
        }

        // Reuse old texture if required size didn't change
        if (textureCreated && currentTextureSize == requiredSize)
        {
            return(true);
        }

        // Create the texture that will hold camera frames

        // Android and OSX
        TextureFormat textureFormat = TextureFormat.RGBA32;

        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            // iOS
            textureFormat = TextureFormat.BGRA32;
        }
        else if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
        {
            // Windows
            textureFormat = TextureFormat.RGB24;
        }

        Debug.Log("Creating texture with size " + requiredSize + " and format " + textureFormat);



        texture = new Texture2D((int)requiredSize, (int)requiredSize, textureFormat, false);

        if (texture == null)
        {
            return(false);
        }

        currentTextureSize = requiredSize;

        cameraPlane.GetComponent <Renderer>().material.mainTexture = texture;
        textureID = texture.GetNativeTextureID();

        Debug.Log("Texture ID: " + textureID);

        return(true);
    }
Пример #7
0
    private void setCameraOrTrackerPosition(Vector3 p, Quaternion q)
    {
        // todo, make a function out of this, otherwhise its the same as metaioTracker.cs
        Matrix4x4 rotationMatrix = new Matrix4x4();

        NormalizeQuaternion(ref q);

        rotationMatrix.SetTRS(Vector3.zero,
                              q,
                              new Vector3(1.0f, 1.0f, 1.0f));

        Matrix4x4 translationMatrix = new Matrix4x4();

        translationMatrix.SetTRS(p,
                                 new Quaternion(0.0f, 0.0f, 0.0f, 1.0f),
                                 new Vector3(1.0f, 1.0f, 1.0f));

        Matrix4x4 composed = translationMatrix * rotationMatrix;

        if (transformCamera)
        {
            //center the camera in front of goal - z-axis
            if (cameraToPositionMono != null && cameraToPositionMono.enabled)
            {
                Matrix4x4 hecMonoInverse;
                calcHandEyeCalibrationInverse(composed, CameraType.Rendering, out hecMonoInverse);

                cameraToPositionMono.transform.position = (Vector3)hecMonoInverse.GetColumn(3);
                cameraToPositionMono.transform.rotation = QuaternionFromMatrix(hecMonoInverse);
            }

            if (cameraToPositionLeft != null && cameraToPositionLeft.enabled)
            {
                Matrix4x4 hecLeftInverse;
                calcHandEyeCalibrationInverse(composed, CameraType.RenderingLeft, out hecLeftInverse);

                cameraToPositionLeft.transform.position = (Vector3)hecLeftInverse.GetColumn(3);
                cameraToPositionLeft.transform.rotation = QuaternionFromMatrix(hecLeftInverse);
            }
            if (cameraToPositionRight != null && cameraToPositionRight.enabled)
            {
                Matrix4x4 hecRightInverse;
                calcHandEyeCalibrationInverse(composed, CameraType.RenderingRight, out hecRightInverse);

                cameraToPositionRight.transform.position = (Vector3)hecRightInverse.GetColumn(3);
                cameraToPositionRight.transform.rotation = QuaternionFromMatrix(hecRightInverse);
            }
        }
        else
        {
            // This only works for mono mode
            Vector3    translation;
            Quaternion rotation;
            MetaioSDKUnity.getHandEyeCalibration(out translation, out rotation, CameraType.Rendering);

            transform.position = translation + p;
            transform.rotation = rotation * q;
        }
    }
Пример #8
0
    public void updateCameraPlaneScale()
    {
        // determine scale of the camera plane
        float scale = MetaioSDKUnity.getCameraPlaneScale();

        // set scale of the camera plane
        cameraPlane.transform.localScale = new Vector3(-scale, scale, scale);
    }
Пример #9
0
 public void stop()
 {
     if (movieGeometry == IntPtr.Zero)
     {
         MetaioSDKUnity.stopMovieTexture(movieGeometry);
     }
     isPlaying = false;
 }
Пример #10
0
 public void pause()
 {
     if (movieGeometry != IntPtr.Zero)
     {
         MetaioSDKUnity.pauseMovieTexture(movieGeometry);
     }
     isPlaying = false;
 }
Пример #11
0
 void OnBecameInvisible()
 {
     // pause plackback when GameObject becomes invisible
     if (isPlaying && movieGeometry != IntPtr.Zero)
     {
         MetaioSDKUnity.pauseMovieTexture(movieGeometry);
     }
 }
Пример #12
0
 void OnDestroy()
 {
     if (movieGeometry != IntPtr.Zero)
     {
         MetaioSDKUnity.deleteMovieGeometry(movieGeometry);
         movieGeometryToGameObjectNameCache.Remove(movieGeometry);
     }
 }
Пример #13
0
    void LateUpdate()
    {
        // Only create movie once
        if (createMovie == false)
        {
            return;
        }
        createMovie = false;

        if (movieFile.Length == 0)
        {
            Debug.LogError("No movie texture file specified");
            return;
        }

        String fullPath = AssetsManager.getAssetPath(movieFile);

        if (fullPath == null)
        {
            Debug.Log("Movie texture file not found in streaming assets, using absolute path: " + movieFile);
            fullPath = movieFile;
        }

        movieGeometry = MetaioSDKUnity.createGeometryFromMovie(fullPath);

        if (movieGeometry == IntPtr.Zero)
        {
            throw new Exception(string.Format("Failed to load movie {0}", fullPath));
        }

        movieGeometryToGameObjectNameCache[movieGeometry] = this.name;

        createTexture();

        MetaioSDKUnity.setMovieTextureTargetTextureID(movieGeometry, textureID);

        Debug.Log("Loaded movie " + movieFile);

        if (autoResizeGameObjectToVideoDimensions)
        {
            autoResizeGameObject();
        }

        // If we know the video frame is rotated, we automatically rotate it to the correct orientation here
        if (isRotatedCCW)
        {
            // Y axis (green) faces up from the plane, so do left-handed 90° rotation (i.e. clockwise by 90°)
            gameObject.transform.Rotate(new Vector3(0, 90, 0));
        }

        // if the associated GameObject is visible, play movie if it should
        // be played
        if (gameObject.renderer.isVisible && isPlaying)
        {
            play(isLooping);
        }
    }
Пример #14
0
 override protected void onInstantTrackingEvent(string filepath)
 {
     Debug.Log("onInstantTrackingEvent: " + filepath);
     if (filepath.Length > 0)
     {
         int result = MetaioSDKUnity.setTrackingConfiguration(filepath, 1);
         Debug.Log("onInstantTrackingEvent: instant tracking configuration loaded: " + result);
     }
 }
Пример #15
0
    public void play(bool loop)
    {
        if (movieGeometry != IntPtr.Zero)
        {
            MetaioSDKUnity.startMovieTexture(movieGeometry, loop ? 1 : 0);
        }

        isLooping = loop;
        isPlaying = true;
    }
Пример #16
0
    void OnDisable()
    {
        Debug.Log("OnDisable: deleting metaio sdk...");

        // stop camera before deleting the instance
        MetaioSDKUnity.stopCamera();

        // delete the instance
        MetaioSDKUnity.deleteMetaioSDKUnity();
    }
Пример #17
0
    void OnApplicationPause(bool pause)
    {
        Debug.Log("OnApplicationPause: " + pause);

        if (pause)
        {
            MetaioSDKUnity.onPauseApplication();
        }
        else
        {
            MetaioSDKUnity.onResumeApplication();
        }
    }
Пример #18
0
    // Update is called once per frame
    void Update()
    {
        if (!updateProjectionMatrix)
        {
            return;
        }

        float[] m = new float[16];

        // Retrieve camera projection matrix
        MetaioSDKUnity.getProjectionMatrix(
            m,
            monoStereoCameraSelection == 1
                                ? CameraType.RenderingLeft
                                : (monoStereoCameraSelection == 2 ? CameraType.RenderingRight : CameraType.Rendering));

        // quick test to validate projection matrix
        if (m[0] > 0)
        {
            // Create matrix, note that array returned by SDK is column-major

            Matrix4x4 matrix;

            matrix.m00 = m[0];
            matrix.m10 = m[1];
            matrix.m20 = m[2];
            matrix.m30 = m[3];

            matrix.m01 = m[4];
            matrix.m11 = m[5];
            matrix.m21 = m[6];
            matrix.m31 = m[7];

            matrix.m02 = m[8];
            matrix.m12 = m[9];
            matrix.m22 = m[10];
            matrix.m32 = m[11];

            matrix.m03 = m[12];
            matrix.m13 = m[13];
            matrix.m23 = m[14];
            matrix.m33 = m[15];

            camera.projectionMatrix = matrix;

            Debug.Log("Setting projection matrix: " + camera.projectionMatrix.ToString());

            updateProjectionMatrix = false;
        }
    }
Пример #19
0
    /// <summary>
    /// Loads 3D coordinates of features contained in the map
    /// </summary>
    public void loadMap(String mapPath)
    {
        clearMap();
        loadedFeatures = 0;
        totalFeatures  = MetaioSDKUnity.get3DPointsFrom3Dmap(Application.dataPath + "\\StreamingAssets\\" + mapPath, featuresRaw);
        Debug.Log(String.Format("Loaded map has {0} features", totalFeatures));

        map = new GameObject("Feature Map") as GameObject;

        // we transform the map due to differences between Unity COS and metaio COS
        map.transform.eulerAngles = mapRotation;
        map.transform.localScale  = mapScale;

        Debug.Log("Start loading map... Don't delete Feature Map object while loading!");
    }
Пример #20
0
    private IEnumerator CallPluginAtEndOfFrames()
    {
        while (true)
        {
            // Wait until all frame rendering is done
            yield return(new WaitForEndOfFrame());

            // Note that the following call triggers the tracking in the SDK, so you must not disable/remove *this* script!
#if UNITY_IPHONE
            MetaioSDKUnity.UnityRenderEvent(textureID);
#else
            GL.IssuePluginEvent(textureID);
#endif
        }
    }
Пример #21
0
    private void autoResizeGameObject()
    {
        var mesh = gameObject.GetComponent <MeshFilter>().mesh;

        if (mesh == null)
        {
            Debug.LogError("Cannot adjust game object dimensions to movie, no mesh attached (try a plane)");
        }
        else
        {
            float objectWidth  = mesh.bounds.size.x * gameObject.transform.localScale.x;
            float objectHeight = mesh.bounds.size.z * gameObject.transform.localScale.z;
            float movieAspect  = MetaioSDKUnity.getMovieTextureDisplayAspect(movieGeometry);            // NOT movieWidth/movieHeight, this is the DAR

            if (objectWidth <= 0.01 || objectHeight <= 0.01)
            {
                Debug.LogWarning("Not adjusting game object dimensions to movie, X or Z bound/scale is zero, is this a plane mesh?");
            }
            else if (Math.Abs(objectWidth / objectHeight - movieAspect) > 0.03)
            {
                Debug.Log(string.Format("Adjusting game object to movie texture aspect ratio {0}", movieAspect));

                if (isRotatedCCW)
                {
                    // Implementation note: If isRotatedCCW=true, then movieWidth/movieHeight are actually swapped, i.e.
                    // represent the inverse display size.

                    // In that case, we'll rotate the mesh (see below), so X scale is for height, Z scale for width
                    gameObject.transform.localScale = new Vector3(
                        gameObject.transform.localScale.x * movieAspect,
                        gameObject.transform.localScale.y,
                        gameObject.transform.localScale.z * (objectWidth / objectHeight));
                }
                else
                {
                    gameObject.transform.localScale = new Vector3(
                        gameObject.transform.localScale.x,
                        gameObject.transform.localScale.y,
                        gameObject.transform.localScale.z * (objectWidth / objectHeight) / movieAspect);
                }
            }
            else
            {
                Debug.Log("Not adjusting game object dimensions, already has same aspect ratio as movie");
            }
        }
    }
Пример #22
0
    public void Start()
    {
        UnityEngine.Object[] callbacks = FindObjectsOfType(typeof(metaioCallback));
        int activeCallbacks            = 0;

        foreach (UnityEngine.Object obj in callbacks)
        {
            activeCallbacks += ((metaioCallback)obj).gameObject.GetComponent <metaioCallback>().enabled ? 1 : 0;
        }
        if (activeCallbacks > 1)
        {
            Debug.LogError("Multiple metaioCallback objects active. There should only be one, else you will receive events in an arbitrary instance.");
        }

        // Enable callbacks
        MetaioSDKUnity.registerCallback(1);
    }
Пример #23
0
    // Update is called once per frame
    void Update()
    {
        if (!updateProjectionMatrix)
        {
            return;
        }

        float[] m = new float[16];

        // Retrieve camera projection matrix
        MetaioSDKUnity.getProjectionMatrix(m, cameraType);

        // quick test to validate projection matrix
        if (m[0] > 0)
        {
            // Create matrix, note that array returned by SDK is column-major

            Matrix4x4 matrix;

            matrix.m00 = m[0];
            matrix.m10 = m[1];
            matrix.m20 = m[2];
            matrix.m30 = m[3];

            matrix.m01 = m[4];
            matrix.m11 = m[5];
            matrix.m21 = m[6];
            matrix.m31 = m[7];

            matrix.m02 = m[8];
            matrix.m12 = m[9];
            matrix.m22 = m[10];
            matrix.m32 = m[11];

            matrix.m03 = m[12];
            matrix.m13 = m[13];
            matrix.m23 = m[14];
            matrix.m33 = m[15];

            camera.projectionMatrix = matrix * Matrix4x4.Scale(new Vector3(-1, 1, 1));
            updateProjectionMatrix  = false;
        }
    }
Пример #24
0
    // Update is called once per frame
    void Update()
    {
        if (updateScreenOrientation())
        {
            // also update size/orientation of metaio SDK and camera projection
            // matrix
            MetaioSDKUnity.resizeRenderer(Screen.width, Screen.height);
            MetaioSDKUnity.updateScreenOrientation(screenOrientation);
            metaioCamera.updateCameraProjectionMatrix();
        }

        // Try to create the texture (must call every frame in case required size changes)
        textureCreated = createTexture(0);

        if (textureCreated)
        {
            updateCameraPlaneScale();
        }
    }
Пример #25
0
    void OnApplicationPause(bool pause)
    {
        Debug.Log("OnApplicationPause: " + pause);

        if (pause)
        {
            MetaioSDKUnity.pauseSensors();

            if (MetaioSDKUnity.usingCamera)
            {
                MetaioSDKUnity.stopCamera();
            }
        }
        else
        {
            MetaioSDKUnity.resumeSensors();

            if (MetaioSDKUnity.usingCamera)
            {
                // Resume same camera as previously set
                MetaioSDKUnity.startCamera(MetaioSDKUnity.requestedCamera);
            }
        }
    }
Пример #26
0
    void Start()
    {
        int result = MetaioSDKUnity.createMetaioSDKUnity(parseApplicationSignature());

        if (result == 0)
        {
            Debug.Log("metaio SDK created successfully");
        }
        else
        {
            Debug.LogError("Failed to create metaio SDK!");
        }

        bool mustRestoreAutoRotation = false;

        if (Screen.orientation == ScreenOrientation.Unknown)
        {
            // In this case we know that auto-rotation was active, because else Unity would immediately set a certain
            // default orientation (as defined in player settings).
            mustRestoreAutoRotation = true;

            Debug.Log("Fixing unknown orientation problem");

            switch (Input.deviceOrientation)
            {
            case DeviceOrientation.PortraitUpsideDown:
                Screen.orientation = ScreenOrientation.PortraitUpsideDown;
                break;

            case DeviceOrientation.LandscapeLeft:
                Screen.orientation = ScreenOrientation.LandscapeLeft;
                break;

            case DeviceOrientation.LandscapeRight:
                Screen.orientation = ScreenOrientation.LandscapeRight;
                break;

            case DeviceOrientation.FaceDown:
            case DeviceOrientation.FaceUp:
            case DeviceOrientation.Portrait:
            case DeviceOrientation.Unknown:
            default:
                Screen.orientation = ScreenOrientation.Portrait;
                break;
            }
        }

        MetaioSDKUnity.updateScreenOrientation(Screen.orientation);

        if (mustRestoreAutoRotation)
        {
            Screen.orientation = ScreenOrientation.AutoRotation;
        }

        MetaioCamera camera = new MetaioCamera();

        camera.index        = cameraIndex;
        camera.resolution.x = cameraWidth;
        camera.resolution.y = cameraHeight;
        camera.downsample   = (uint)cameraDownsample;
        camera.flip         = (uint)cameraFlip;
        MetaioSDKUnity.startCamera(camera);

        // Load tracking configuration
        if (String.IsNullOrEmpty(trackingConfiguration))
        {
            Debug.Log("No tracking configuration specified");

            result = MetaioSDKUnity.setTrackingConfiguration("", 0);
        }
        else
        {
            result = MetaioSDKUnity.setTrackingConfigurationFromAssets(trackingConfiguration);

            if (result == 0)
            {
                Debug.LogError("Start: failed to load tracking configuration: " + trackingConfiguration);
            }
            else
            {
                Debug.Log("Loaded tracking configuration: " + trackingConfiguration);
            }
        }

        // Set LLA objects' rendering limits
        MetaioSDKUnity.setLLAObjectRenderingLimits(10, 1000);

        // Set renderer clipping plane limits
        MetaioSDKUnity.setRendererClippingPlaneLimits(nearClippingPlaneLimit, farClippingPlaneLimit);

        // Apply initial settings for mono/stereo and (non-)see-through mode
        stereoRenderingEnabled = _stereoRenderingEnabled;
        seeThroughEnabled      = _seeThroughEnabled;
    }
Пример #27
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);
        }
    }
Пример #28
0
    void Start()
    {
        int result = MetaioSDKUnity.createMetaioSDKUnity(parseApplicationSignature());

        if (result == 0)
        {
            Debug.Log("metaio SDK created successfully");
        }
        else
        {
            Debug.LogError("Failed to create metaio SDK!");
        }

        bool mustRestoreAutoRotation = false;

        if (Screen.orientation == ScreenOrientation.Unknown)
        {
            // In this case we know that auto-rotation was active, because else Unity would immediately set a certain
            // default orientation (as defined in player settings).
            mustRestoreAutoRotation = true;

            Debug.Log("Fixing unknown orientation problem");

            switch (Input.deviceOrientation)
            {
            case DeviceOrientation.PortraitUpsideDown:
                Screen.orientation = ScreenOrientation.PortraitUpsideDown;
                break;

            case DeviceOrientation.LandscapeLeft:
                Screen.orientation = ScreenOrientation.LandscapeLeft;
                break;

            case DeviceOrientation.LandscapeRight:
                Screen.orientation = ScreenOrientation.LandscapeRight;
                break;

            case DeviceOrientation.FaceDown:
            case DeviceOrientation.FaceUp:
            case DeviceOrientation.Portrait:
            case DeviceOrientation.Unknown:
            default:
                Screen.orientation = ScreenOrientation.Portrait;
                break;
            }
        }

        MetaioSDKUnity.updateScreenOrientation(Screen.orientation);

        if (mustRestoreAutoRotation)
        {
            Screen.orientation = ScreenOrientation.AutoRotation;
        }

        System.Collections.Generic.List <MetaioCamera> cameras = MetaioSDKUnity.getCameraList();

        /*Debug.Log("Listing the cameras");
         *
         * for (int i = 0; i < cameras.Count; i++)
         * {
         *  Debug.Log("Camera " + (i+1) + " : " + cameras[i].friendlyName);
         * }*/

        //Debug.Log("Starting the default camera with facing: " + cameraFacing);

        //cameras [1].flip = MetaioCamera.FLIP_HORIZONTAL;
        //Debug.Log("###WOPA####" + (int) cameras[1].flip);

        MetaioSDKUnity.startCamera(cameras[0]);

        // Load tracking configuration
        if (String.IsNullOrEmpty(trackingConfiguration))
        {
            Debug.Log("No tracking configuration specified");

            result = MetaioSDKUnity.setTrackingConfiguration("", 0);
        }
        else
        {
            result = MetaioSDKUnity.setTrackingConfigurationFromAssets(trackingConfiguration);

            if (result == 0)
            {
                Debug.LogError("Start: failed to load tracking configuration: " + trackingConfiguration);
            }
            else
            {
                Debug.Log("Loaded tracking configuration: " + trackingConfiguration);
            }
        }

        // Set LLA objects' rendering limits
        MetaioSDKUnity.setLLAObjectRenderingLimits(10, 1000);

        // Set renderer clipping plane limits
        MetaioSDKUnity.setRendererClippingPlaneLimits(nearClippingPlaneLimit, farClippingPlaneLimit);

        // Apply initial settings for mono/stereo and (non-)see-through mode
        stereoRenderingEnabled = _stereoRenderingEnabled;
        seeThroughEnabled      = _seeThroughEnabled;
    }
Пример #29
0
 void Track()
 {
     MetaioSDKUnity.startInstantTracking("INSTANT_3D", "");
 }
Пример #30
0
    public void Update()
    {
        EUNITY_CALLBACK_EVENT eventID = (EUNITY_CALLBACK_EVENT)MetaioSDKUnity.getUnityCallbackEventID();

        if (eventID != EUNITY_CALLBACK_EVENT.EUCE_NONE)
        {
            uint   eventValueLength = 0;
            IntPtr eventValuePtr    = MetaioSDKUnity.getUnityCallbackEventValue(out eventValueLength);

//			Debug.Log("Callback event: "+eventID+", "+eventValue);

            switch (eventID)
            {
            case EUNITY_CALLBACK_EVENT.EUCE_LOG:
                onLog(Marshal.PtrToStringAnsi(eventValuePtr));
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_LOG_WARNING:
                onLogWarning(Marshal.PtrToStringAnsi(eventValuePtr));
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_LOG_ERROR:
                onLogError(Marshal.PtrToStringAnsi(eventValuePtr));
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_SDK_READY:
                onSDKReady();
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_TRACKING_EVENT:
                byte[] pbAsBytes = new byte[eventValueLength];
                Marshal.Copy(eventValuePtr, pbAsBytes, 0, (int)eventValueLength);
                metaio.unitycommunication.OnTrackingEventProtocol prot = metaio.unitycommunication.OnTrackingEventProtocol.ParseFrom(pbAsBytes);
                List <TrackingValues> listTV = new List <TrackingValues>();
                for (int i = 0; i < prot.TrackingValuesCount; ++i)
                {
                    listTV.Add(TrackingValues.FromPB(prot.TrackingValuesList[i]));
                }
                onTrackingEvent(listTV);
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_INSTANT_TRACKING_EVENT:
                onInstantTrackingEvent(eventValuePtr.MarshalToStringUTF8());
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_CAMERA_IMAGE_SAVED:
                onCameraImageSaved(eventValuePtr.MarshalToStringUTF8());
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_VISUAL_SEARCH_RESULT:
                parseVisualSearchResponse(eventValuePtr, eventValueLength);
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_VISUAL_SEARCH_STATUS:
                onVisualSearchStatusChanged(Marshal.PtrToStringAnsi(eventValuePtr));
                break;

            case EUNITY_CALLBACK_EVENT.EUCE_MOVIE_END:
                IntPtr movieTextureGeometryPtr = new IntPtr(int.Parse(Marshal.PtrToStringAnsi(eventValuePtr)));
                onMovieEnd(metaioMovieTexture.getGameObjectNameForMovieTextureGeometryPtr(movieTextureGeometryPtr));
                break;
            }

            // remove the callback event from queue
            MetaioSDKUnity.removeUnityCallbackEvent();
        }
    }