Esempio n. 1
0
        /// <summary>
        /// Update an Augmenta object extra data from incoming data.
        /// </summary>
        /// <param name="augmentaObject"></param>
        /// <param name="args"></param>
        private void UpdateAugmentaObjectExtra(AugmentaObject augmentaObject, ArrayList args)
        {
            Vector3 highest = new Vector3((float)args[3], (float)args[4], augmentaObject.highest.z);

            if (flipX)
            {
                highest.x = 1 - highest.x;
            }

            if (flipY)
            {
                highest.y = 1 - highest.y;
            }

            augmentaObject.id               = (int)args[1];
            augmentaObject.oid              = (int)args[2];
            augmentaObject.highest          = highest;
            augmentaObject.distanceToSensor = (float)args[5];
            augmentaObject.reflectivity     = (float)args[6];

            //Inactive time reset to zero : the object has just been updated
            augmentaObject.inactiveTime = 0;

            augmentaObject.UpdateAugmentaObject();
        }
Esempio n. 2
0
        /// <summary>
        /// Send the Augmenta event of corresponding type, according to the desired object.
        /// </summary>
        /// <param name="eventType"></param>
        /// <param name="augmentaObject"></param>
        public void SendAugmentaEvent(AugmentaEventType eventType, AugmentaObject augmentaObject = null, AugmentaDataType augmentaDataType = AugmentaDataType.Main)
        {
            switch (eventType)
            {
            case AugmentaEventType.AugmentaObjectEnter:
                augmentaObjectEnter?.Invoke(augmentaObject, augmentaDataType);
                break;

            case AugmentaEventType.AugmentaObjectUpdate:
                augmentaObjectUpdate?.Invoke(augmentaObject, augmentaDataType);
                break;

            case AugmentaEventType.AugmentaObjectLeave:
                augmentaObjectLeave?.Invoke(augmentaObject, augmentaDataType);
                break;

            case AugmentaEventType.SceneUpdated:
                sceneUpdated?.Invoke();
                break;

            case AugmentaEventType.FusionUpdated:
                fusionUpdated?.Invoke();
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update an Augmenta object data from incoming data
        /// </summary>
        /// <param name="augmentaObject"></param>
        /// <param name="args"></param>
        /// <param name="augmentaDataType"></param>
        private void UpdateAugmentaObject(AugmentaObject augmentaObject, ArrayList args, AugmentaDataType augmentaDataType = AugmentaDataType.Main)
        {
            switch (augmentaDataType)
            {
            case AugmentaDataType.Main:
                UpdateAugmentaObjectMain(augmentaObject, args);
                break;

            case AugmentaDataType.Extra:
                UpdateAugmentaObjectExtra(augmentaObject, args);
                break;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Add new Augmenta object.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        private AugmentaObject AddAugmentaObject(ArrayList args, AugmentaDataType objectDataType = AugmentaDataType.Main)
        {
            GameObject newAugmentaObjectObject = Instantiate(augmentaObjectPrefab, augmentaScene.gameObject.transform);

            AugmentaObject newAugmentaObject = newAugmentaObjectObject.GetComponent <AugmentaObject>();

            newAugmentaObject.augmentaManager = this;
            newAugmentaObject.useCustomObject = customObjectPrefab;
            newAugmentaObject.showDebug       = showObjectDebug;
            newAugmentaObject.ShowDebug(showObjectDebug);

            UpdateAugmentaObject(newAugmentaObject, args, objectDataType);

            augmentaObjects.Add(newAugmentaObject.id, newAugmentaObject);

            newAugmentaObjectObject.name = "Augmenta Object " + newAugmentaObject.id;
            SetLayerRecursively(newAugmentaObjectObject, gameObject.layer);

            return(newAugmentaObject);
        }
Esempio n. 5
0
        /// <summary>
        /// Parse the OSC message using Augmenta protocol V2
        /// </summary>
        /// <param name="message"></param>
        private void ParseAugmentaProtocolV2(OSCMessage message)
        {
            string    address = message.Address;
            ArrayList args    = new ArrayList(message.Data);

            int            id, oid;
            AugmentaObject augmentaObject = null;

            switch (address)
            {
            case "/object/enter/":
            case "/object/enter":

                id  = (int)args[1];
                oid = (int)args[2];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (!augmentaObjects.ContainsKey(id))
                    {
                        //New object
                        augmentaObject = AddAugmentaObject(args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectEnter, augmentaObject);
                    }
                    else
                    {
                        //Object was already there
                        augmentaObject = augmentaObjects[id];
                        UpdateAugmentaObject(augmentaObject, args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectUpdate, augmentaObject);
                    }
                }

                break;

            case "/object/update/":
            case "/object/update":

                id  = (int)args[1];
                oid = (int)args[2];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (!augmentaObjects.ContainsKey(id))
                    {
                        augmentaObject = AddAugmentaObject(args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectEnter, augmentaObject);
                    }
                    else
                    {
                        augmentaObject = augmentaObjects[id];
                        UpdateAugmentaObject(augmentaObject, args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectUpdate, augmentaObject);
                    }
                }

                break;

            case "/object/leave/":
            case "/object/leave":

                id  = (int)args[1];
                oid = (int)args[2];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (augmentaObjects.ContainsKey(id))
                    {
                        augmentaObject = augmentaObjects[id];
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectLeave, augmentaObject);
                        RemoveAugmentaObject(id);
                    }
                }

                break;

            case "/object/enter/extra/":
            case "/object/enter/extra":

                id  = (int)args[1];
                oid = (int)args[2];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (!augmentaObjects.ContainsKey(id))
                    {
                        //New object
                        augmentaObject = AddAugmentaObject(args, AugmentaDataType.Extra);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectEnter, augmentaObject, AugmentaDataType.Extra);
                    }
                    else
                    {
                        //Object was already there
                        augmentaObject = augmentaObjects[id];
                        UpdateAugmentaObject(augmentaObject, args, AugmentaDataType.Extra);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectUpdate, augmentaObject, AugmentaDataType.Extra);
                    }
                }

                break;

            case "/object/update/extra/":
            case "/object/update/extra":

                id  = (int)args[1];
                oid = (int)args[2];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (!augmentaObjects.ContainsKey(id))
                    {
                        augmentaObject = AddAugmentaObject(args, AugmentaDataType.Extra);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectEnter, augmentaObject, AugmentaDataType.Extra);
                    }
                    else
                    {
                        augmentaObject = augmentaObjects[id];
                        UpdateAugmentaObject(augmentaObject, args, AugmentaDataType.Extra);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectUpdate, augmentaObject, AugmentaDataType.Extra);
                    }
                }

                break;

            case "/object/leave/extra/":
            case "/object/leave/extra":

                id  = (int)args[1];
                oid = (int)args[2];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (augmentaObjects.ContainsKey(id))
                    {
                        augmentaObject = augmentaObjects[id];
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectLeave, augmentaObject, AugmentaDataType.Extra);
                        RemoveAugmentaObject(id);
                    }
                }

                break;

            case "/scene/":
            case "/scene":

                augmentaScene.augmentaObjectCount = (int)args[1];
                augmentaScene.width  = (float)args[2];
                augmentaScene.height = (float)args[3];

                SendAugmentaEvent(AugmentaEventType.SceneUpdated);

                break;

            case "/fusion/":
            case "/fusion":

                videoOutputOffset       = new Vector2((float)args[0], (float)args[1]);
                videoOutputSizeInMeters = new Vector2((float)args[2], (float)args[3]);
                videoOutputSizeInPixels = new Vector2Int((int)args[4], (int)args[5]);

                SendAugmentaEvent(AugmentaEventType.FusionUpdated);

                break;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Parse the OSC message using Augmenta protocol V1
        /// </summary>
        /// /// <param name="message"></param>
        private void ParseAugmentaProtocolV1(OSCMessage message)
        {
            string    address = message.Address;
            ArrayList args    = new ArrayList(message.Data);

            int            id, oid;
            AugmentaObject augmentaObject = null;

            switch (address)
            {
            case "/au/personEntered/":
            case "/au/personEntered":

                id  = (int)args[0];
                oid = (int)args[1];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (!augmentaObjects.ContainsKey(id))
                    {
                        //New object
                        augmentaObject = AddAugmentaObject(args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectEnter, augmentaObject);
                    }
                    else
                    {
                        //Object was already there
                        augmentaObject = augmentaObjects[id];
                        UpdateAugmentaObject(augmentaObject, args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectUpdate, augmentaObject);
                    }
                }

                break;

            case "/au/personUpdated/":
            case "/au/personUpdated":

                id  = (int)args[0];
                oid = (int)args[1];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (!augmentaObjects.ContainsKey(id))
                    {
                        augmentaObject = AddAugmentaObject(args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectEnter, augmentaObject);
                    }
                    else
                    {
                        augmentaObject = augmentaObjects[id];
                        UpdateAugmentaObject(augmentaObject, args);
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectUpdate, augmentaObject);
                    }
                }

                break;

            case "/au/personWillLeave/":
            case "/au/personWillLeave":

                id  = (int)args[0];
                oid = (int)args[1];

                if (IsAugmentaObjectDesired(oid))
                {
                    if (augmentaObjects.ContainsKey(id))
                    {
                        augmentaObject = augmentaObjects[id];
                        SendAugmentaEvent(AugmentaEventType.AugmentaObjectLeave, augmentaObject);
                        RemoveAugmentaObject(id);
                    }
                }

                break;

            case "/au/scene/":
            case "/au/scene":

                augmentaScene.augmentaObjectCount = (int)args[2];
                augmentaScene.width  = (int)args[5] * pixelSize;
                augmentaScene.height = (int)args[6] * pixelSize;

                SendAugmentaEvent(AugmentaEventType.SceneUpdated);

                break;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Update an Augmenta object main data from incoming data.
        /// </summary>
        /// <param name="augmentaObject"></param>
        /// <param name="args"></param>
        private void UpdateAugmentaObjectMain(AugmentaObject augmentaObject, ArrayList args)
        {
            Vector2 centroid     = Vector2.zero;
            Vector2 velocity     = Vector2.zero;
            Vector3 highest      = Vector3.zero;
            Rect    boundingRect = new Rect();
            float   orientation  = 0;
            float   rotation     = 0;

            switch (protocolVersion)
            {
            case AugmentaProtocolVersion.V1:

                augmentaObject.id          = (int)args[0];
                augmentaObject.oid         = (int)args[1];
                augmentaObject.ageInFrames = (int)args[2];
                centroid             = new Vector2((float)args[3], (float)args[4]);
                velocity             = new Vector2((float)args[5], (float)args[6]);
                augmentaObject.depth = (float)args[7];
                boundingRect         = new Rect((float)args[8], (float)args[9], (float)args[10], (float)args[11]);
                highest = new Vector3((float)args[12], (float)args[13], (float)args[14]);
                break;

            case AugmentaProtocolVersion.V2:

                augmentaObject.id           = (int)args[1];
                augmentaObject.oid          = (int)args[2];
                augmentaObject.ageInSeconds = (float)args[3];
                centroid     = new Vector2((float)args[4], (float)args[5]);
                velocity     = new Vector2((float)args[6], (float)args[7]);
                orientation  = (float)args[8];
                boundingRect = new Rect((float)args[9], (float)args[10], (float)args[11], (float)args[12]);
                rotation     = (float)args[13];
                highest      = new Vector3(augmentaObject.highest.x, augmentaObject.highest.y, (float)args[14]);
                break;
            }

            if (flipX)
            {
                centroid.x     = 1 - centroid.x;
                velocity.x     = -velocity.x;
                orientation    = orientation > 180 ? 360.0f - orientation : 180.0f - orientation;
                boundingRect.x = 1 - boundingRect.x;
                rotation       = rotation > 180 ? 360.0f - rotation : 180.0f - rotation;
                highest.x      = 1 - highest.x;
            }

            if (flipY)
            {
                centroid.y     = 1 - centroid.y;
                velocity.y     = -velocity.y;
                orientation    = 360.0f - orientation;
                boundingRect.y = 1 - boundingRect.y;
                rotation       = 360.0f - rotation;
                highest.y      = 1 - highest.y;
            }

            augmentaObject.centroid             = centroid;
            augmentaObject.velocity             = velocity;
            augmentaObject.orientation          = orientation;
            augmentaObject.boundingRect         = boundingRect;
            augmentaObject.boundingRectRotation = rotation;
            augmentaObject.highest = highest;

            //Inactive time reset to zero : the object has just been updated
            augmentaObject.inactiveTime = 0;

            augmentaObject.UpdateAugmentaObject();
        }