Example #1
0
        void Update()
        {
            if (FStarted)
            {
                IntPtr userPixels = FUserGenerator.GetUserPixels(0).LabelMapPtr;
                FImageMask.Image.SetPixels(userPixels);
                FImageMask.Send();

                lock (FLockUserData)
                {
                    FUserPositions.SliceCount = FUserData.Count;
                    foreach (var u in FUserData)
                    {
                        Point3D p = FUserGenerator.GetCoM(u.Key);
                        FUserData[u.Key].Position = new Vector3D(p.X / 1000.0d, p.Y / 1000.0d, p.Z / 1000.0d);
                    }
                }
            }
        }
    public Point3D RotateHandPoint(Point3D HandPoint)
    {
        //TODO: handle user getting/losing CoM better.
        //TODO: Smoothing on CoM (so sudden CoM changes won't mess with the hand
        //      point too much)

        // get userID of user to whom the hand is attached
        int userID = WhichUserDoesThisPointBelongTo(HandPoint);

        if (userID == 0)
        {
            // no CoM, do nothing
            return(HandPoint);
        }
        Vector3 user = Point3DToVector3(userGenerator.GetCoM(userID));

        // use line between com and sensor as Z
        Quaternion newOrientation = Quaternion.FromToRotation(user.normalized, Vector3.forward);
        Vector3    newHandPoint   = newOrientation * Point3DToVector3(HandPoint);

        return(new Point3D(newHandPoint.x, newHandPoint.y, newHandPoint.z));
    }
Example #3
0
    public Vector3 GetUserCenterOfMass(int userId)
    {
        Point3D com = userGenerator.GetCoM(userId);

        return(new Vector3(com.X, com.Y, -com.Z));
    }
Example #4
0
 /// <summary>
 /// Atualiza as articulações e o centro de massa do usuário identificado por id.
 /// </summary>
 public void UpdateUser(int id)
 {
     users[id].UpdateJoints(userGenerator.SkeletonCapability, skeleton);
     users[id].CoM = userGenerator.GetCoM(id);
 }
Example #5
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            // Creates the User Generator from the Context Object
                            FUserGenerator = new UserGenerator(FContextIn[0]);

                            //Set the resolution of the texture
                            FTexWidth  = FUserGenerator.GetUserPixels(0).FullXRes;
                            FTexHeight = FUserGenerator.GetUserPixels(0).FullYRes;

                            //Reinitalie the vvvv texture
                            Reinitialize();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            //create new texture if outputmode changed
            if (FOutputMode.IsChanged)
            {
                Reinitialize();
            }

            if (FUserGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FUserGenerator.StartGenerating();
                    }
                    else
                    {
                        FUserGenerator.StopGenerating();
                    }
                }

                if (FUserGenerator.IsDataNew)
                {
                    FUserIdOut.SliceCount   = FUserGenerator.NumberOfUsers;
                    FPositionOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FTextureOut.SliceCount  = 1;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //copies a list of all users and sort them
                        int[] tUsers = FUserGenerator.GetUsers();
                        int[] Users  = (int[])tUsers.Clone();
                        Array.Sort(Users);

                        for (int i = 0; i < Users.Length; i++)
                        {
                            FUserIdOut[i] = Users[i];
                            try
                            {
                                //middle point of the User
                                Point3D  Point    = FUserGenerator.GetCoM(Users[i]);
                                Vector3D Position = new Vector3D(Point.X, Point.Y, Point.Z);

                                //map postion values to vvvv coordinates
                                FPositionOut[i] = Position / 1000;
                            }
                            catch (StatusException ex)
                            {
                                FLogger.Log(ex);
                            }
                        }
                    }

                    //update the vvvv texture
                    Update();
                }
            }
            else
            {
                FUserIdOut.SliceCount   = 0;
                FPositionOut.SliceCount = 0;
                FTextureOut.SliceCount  = 0;
            }
        }