Exemplo n.º 1
0
    // Update Virtual Button states.
    public void UpdateVirtualButtons(int numVirtualButtons, IntPtr virtualButtonPtr)
    {
        Dictionary <int, QCARManagerImpl.VirtualButtonData> vbResults = new Dictionary <int, QCARManagerImpl.VirtualButtonData>();

        // create a dictionary of all results
        for (int i = 0; i < numVirtualButtons; i++)
        {
            IntPtr vbPtr = new IntPtr(virtualButtonPtr.ToInt32() + i *
                                      Marshal.SizeOf(typeof(QCARManagerImpl.VirtualButtonData)));
            QCARManagerImpl.VirtualButtonData vbData = (QCARManagerImpl.VirtualButtonData)
                                                       Marshal.PtrToStructure(vbPtr, typeof(QCARManagerImpl.VirtualButtonData));

            vbResults.Add(vbData.id, vbData);
        }

        List <VirtualButtonBehaviour> vbBehavioursToUpdate = new List <VirtualButtonBehaviour>();

        // go over all trackable behaviours and find the virtual buttons to update
        foreach (TrackableBehaviour trackableBehaviour in mTrackableBehaviours.Values)
        {
            ImageTargetBehaviour it = trackableBehaviour as ImageTargetBehaviour;

            if (it != null && it.enabled)
            {
                foreach (VirtualButtonBehaviour virtualButtonBehaviour in it.GetVirtualButtonBehaviours())
                {
                    if (virtualButtonBehaviour.enabled)
                    {
                        vbBehavioursToUpdate.Add(virtualButtonBehaviour);
                    }
                }
            }
        }

        // update the virtual buttons:
        foreach (VirtualButtonBehaviour virtualButtonBehaviour in vbBehavioursToUpdate)
        {
            QCARManagerImpl.VirtualButtonData vbData;
            if (vbResults.TryGetValue(virtualButtonBehaviour.VirtualButton.ID, out vbData))
            {
                virtualButtonBehaviour.OnTrackerUpdated(vbData.isPressed > 0);
            }
            else
            {
                virtualButtonBehaviour.OnTrackerUpdated(false);
            }
        }
    }