/// <summary>
        /// Builds the FIR filter weights depending on size and filter type.
        /// </summary>
        ///
        private void InitialiseFilter()
        {
            float framerate  = MoCapManager.GetInstance().GetFramerate();
            int   filterSize = Mathf.Clamp((int)(framerate * filterTime), 1, maximumFilterSize);

            filter = new float[filterSize];
            for (int i = 0; i < filterSize; i++)
            {
                float x = (i - (filterSize / 2.0f)) / framerate;
                switch (filterType)
                {
                case FilterType.Rectangle:
                    filter[i] = 1.0f;
                    break;

                case FilterType.Gaussian:
                    float d2 = 0.25f * 0.25f;                             // squared standard deviation range
                    filter[i] = 1.0f / (2.0f * Mathf.PI * d2) * Mathf.Exp(-(x * x) / (2.0f * d2));
                    break;

                case FilterType.LowPass:
                    x        *= Mathf.PI * 2;
                    x        += 0.00001f;                      // avoid division by zero
                    filter[i] = Mathf.Sin(x) / x;
                    break;
                }
            }
            oldFilterTime = filterTime;
        }
Exemple #2
0
        private void CollectMoCapWriters()
        {
            writers.Clear();
            int index = 1;

            Scene s = MoCapManager.GetInstance().GetScene();

            foreach (Actor a in s.actors)
            {
                writers.Add(new MoCapActorWriter(a));
                index++;
            }
            foreach (Device d in s.devices)
            {
                writers.Add(new MoCapDeviceWriter(d));
                index++;
            }

            foreach (Transform t in Transforms)
            {
                writers.Add(new TransformWriter(t, index));
                index++;
            }

            // collect overall stats
            numberOfActors  = 0;
            numberOfDevices = 0;
            foreach (IMoCapWriter writer in writers)
            {
                numberOfActors  += writer.GetNumberOfActors();
                numberOfDevices += writer.GetNumberOfDevices();
            }
        }
 //// <summary>
 /// Called just before the frame renders.
 /// </summary>
 ///
 public void OnPreRender()
 {
     if ((updateType == UpdateType.PreRender) ||
         (updateType == UpdateType.UpdateAndPreRender))
     {
         MoCapManager.GetInstance().OnPreRender();
         UpdateObject();
     }
 }
Exemple #4
0
        /// <summary>
        /// Called at the start of the game.
        /// Tries to find the MoCap client singleton and then
        /// registers this object as a listener with the client.
        /// </summary>
        ///
        void Start()
        {
            boneList = null;

            // find any MoCap data modifiers and store them
            modifiers = GetComponents <IMoCapDataModifier>();

            MoCapManager.GetInstance().AddSceneListener(this);
        }
        public void Start()
        {
            // calculate maximum filter size if necessary
            if (maximumFilterSize <= 0)
            {
                maximumFilterSize = (int)(filterTime * MoCapManager.GetInstance().GetFramerate());
                maximumFilterSize = Mathf.Max(maximumFilterSize, 1);
            }

            InitialiseFilter();
        }
Exemple #6
0
        /// <summary>
        /// Creates a new input device handler instance for a specific device.
        /// </summary>
        /// <param name="deviceName">the device to attach to</param>
        /// <param name="channelName">the channel to attach to</param>
        ///
        public InputDeviceHandler(string deviceName, string channelName)
        {
            this.deviceName  = deviceName;
            this.channelName = channelName;

            value         = 0;
            oldValue      = 0;
            warningIssued = false;

            PressThreshold = 1.0f;

            MoCapManager.GetInstance().AddSceneListener(this);
        }
        /// <summary>
        /// Called at the beginning of the program execution.
        /// </summary>
        ///
        void Start()
        {
            // initialise variables
            rootNode        = null;
            controllingBone = null;
            boneList        = new Dictionary <Bone, GameObject>();
            disabled        = false;

            notFoundWarningIssued = false;

            // find any MoCap data modifiers and store them
            modifiers = GetComponents <IMoCapDataModifier>();

            // let the MoCap manager handle the forced Update calls
            MoCapManager.GetInstance().StartCoroutine(ForceUpdateCall(this));

            MoCapManager.GetInstance().AddSceneListener(this);
        }
        /// <summary>
        /// Called at the start of the game.
        /// Tries to find the MoCap client singleton and then
        /// registers this object as a listener with the client.
        /// </summary>
        ///
        void Start()
        {
            // initialise variables
            skeletonNode = null;
            actor        = null;
            boneList     = new Dictionary <Bone, BoneObject>();

            // sanity checks
            if (boneTemplate == null)
            {
                Debug.LogWarning("No bone template defined");
            }

            // find any MoCap data modifiers and store them
            modifiers = GetComponents <IMoCapDataModifier>();

            // start receiving MoCap data
            MoCapManager.GetInstance().AddSceneListener(this);
        }
Exemple #9
0
 public void Start()
 {
     framerate = MoCapManager.GetInstance().GetFramerate();
 }
Exemple #10
0
        private void OpenLogfile()
        {
            // save pure data
            string filename = OutputFilename.Replace("{timestamp}", System.DateTime.Now.ToString("yyyyMMdd_HHmmss"));

            writer = new MoCapFileWriter(new StreamWriter(filename));
            Debug.Log("Opened MoCap logfile '" + filename + "'");

            foreach (IMoCapWriter w in writers)
            {
                w.SetWriter(writer);
            }

            // write MOT file header
            writer
            .WriteTag(MOT_FILE_IDENTIFIER)                    // header
            .Write(MOT_FILE_VERSION)                          // version
            .Write(MoCapManager.GetInstance().GetFramerate()) // framerate
            .EndLine();

            // write description section
            writer
            .WriteTag(MOT_SECTION_DESCRIPTIONS)                     // keyword
            .Write((numberOfActors * 2) + numberOfDevices)          // number of descriptions (actors *2: markerset + rigidbbody)
            .EndLine();
            int index = 0;

            foreach (IMoCapWriter w in writers)
            {
                w.WriteMarkersetDescription(ref index);
            }
            foreach (IMoCapWriter w in writers)
            {
                w.WriteRigidBodyDescription(ref index);
            }
            foreach (IMoCapWriter w in writers)
            {
                w.WriteDeviceDescription(ref index);
            }

            // start data section
            writer.WriteTag(MOT_SECTION_FRAMES).EndLine();

            // write data headers
            writer.WriteTag("#frame").WriteTag("timestamp").WriteTag("latency");
            writer.WriteTag("markersetTag").WriteTag("markersetCount");
            foreach (IMoCapWriter w in writers)
            {
                w.WriteMarkersetHeader();
            }
            writer.WriteTag("rigidbodyTag").WriteTag("rigidbodyCount");
            foreach (IMoCapWriter w in writers)
            {
                w.WriteRigidBodyHeader();
            }
            writer.WriteTag("skeletonTag").WriteTag("skeletonCount");
            writer.WriteTag("forceplateTag").WriteTag("forceplateCount");
            foreach (IMoCapWriter w in writers)
            {
                w.WriteDeviceHeader();
            }
            writer.EndLine();
        }