Skip to main content
added 146 characters in body
Source Link
jeff
  • 131
  • 5
               For h = 0 To activeCount - 1
                    If h >= 2 Then
                        If activeCount - 1 > 0 Then
                            sensor.SkeletonStream.ChooseSkeletons(playerid(h), playerid(h + 1))
                        End If
                    End If
                Next
            Next

            ResetValues()

        End Using
                            sensor.SkeletonStream.ChooseSkeletons(playerid(h), playerid(h + 1))
                        End If
                    End If
                Next
            Next

            ResetValues()

        End Using
               For h = 0 To activeCount - 1
                    If h >= 2 Then
                        If activeCount - 1 > 0 Then
                            sensor.SkeletonStream.ChooseSkeletons(playerid(h), playerid(h + 1))
                        End If
                    End If
                Next
            Next

            ResetValues()

        End Using
deleted 1351 characters in body
Source Link
jeff
  • 131
  • 5
            'identify specific players by ID
            'ResetValues()

            'player #1
            playerid(0) = CInt(Rnd'ResetValues() * 4)
            'For playerid(0)j = 1
            allSkeletons(0).TrackingId =To playerid(0)
            Log("player#1 tracking: " + allSkeletons(0).TrackingId.ToString)
            'player #2
            playerid(1) = CInt(Rnd() * 4 + 5)  ' 5 Length -  9
            'playerid(1) = 2
            allSkeletons(1).TrackingId = playerid(1)
            'player'all #3players
            ' playerid(2) = 3
            playerid(2i) = CInt(Rnd() * 4 + 10) ' 10 - 14
            allSkeletons(2).TrackingId = playerid(2)
            'player #4
            playerid(3) = CInt(Rnd()i * 4 + 15) ' 15 - 19
            allSkeletons(35).TrackingId = playerid(3)
            'player #5
            playerid(4) = CInt(Rnd() * 4 + 20) ' 20 - 24
            allSkeletons(4i).TrackingId = playerid(4)
            'player #6
            playerid(5) = CInt(Rnd() * 4 + 250) ' 25 - 29
            allSkeletons(5).TrackingId =Next playerid(5)j
            'force each player to be moved to first blank spot 
            Dim tempList As New List(Of Skeleton)(allSkeletons)
            tempList.RemoveAll(Function(sk) IsNothing(sk))
            allSkeletons = tempList.ToArray
            Log("Tracking id for player#1: " + allSkeletons(0).TrackingId.ToString)
            Log("Tracking id for player#2: " + allSkeletons(1).TrackingId.ToString)
            Log("Tracking id for player#3: " + allSkeletons(2).TrackingId.ToString)
          
       
                If IsNothing(s) Then
                    Exit Sub
                End If
                If s.TrackingState = SkeletonTrackingState.Tracked Then
                    activeCount = activeCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.PositionOnly Then
                    passiveCount = passiveCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.NotTracked Then
                    nottracked = nottracked + 1
                End If
                totalplayers = activeCount + passiveCount + nottracked
                'Log("passive count: " + passiveCount.ToString + " date: " + Now.ToString)

                
                ' the first found/tracked skeleton moves the mouse cursor
                If s.TrackingState = SkeletonTrackingState.Tracked Then

                    ' make sure both hands are tracked
                    'If Skeleton.Joints(JointType.HandLeft).TrackingState = JointTrackingState.Tracked AndAlso Skeleton.Joints(JointType.HandRight).TrackingState = JointTrackingState.Tracked Then
                    Dim cursorX, cursorY As Integer

                    ' get the left and right hand Joints
                    Dim jointRight As Joint = s.Joints(JointType.HandRight)
                    Dim jointLeft As Joint = s.Joints(JointType.HandLeft)

                    ' scale those Joints to the primary screen width and height
                    Dim scaledRight As Joint = jointRight.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    Dim scaledLeft As Joint = jointLeft.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    ' relativemouselocation.Content = jointRight.Position

Figure out XPlayer x,Y coordinatesy display:

                     ' the first found/tracked skeleton moves the mouse cursor
                If s.TrackingState = SkeletonTrackingState.Tracked Then

                    ' make sure both hands are tracked
                    'If Skeleton.Joints(JointType.HandLeft).TrackingState = JointTrackingState.Tracked AndAlso Skeleton.Joints(JointType.HandRight).TrackingState = JointTrackingState.Tracked Then
                    Dim cursorX, cursorY As Integer

                    ' get the left and right hand Joints
                    Dim jointRight As Joint = s.Joints(JointType.HandRight)
                    Dim jointLeft As Joint = s.Joints(JointType.HandLeft)

                    ' scale those Joints to the primary screen width and height
                    Dim scaledRight As Joint = jointRight.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    Dim scaledLeft As Joint = jointLeft.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    ' relativemouselocation.Content = jointRight.Position
                    ' figure out the cursor position based on left/right handedness
                    If LeftHand.IsChecked.GetValueOrDefault() Then
                        cursorX = CInt(Fix(scaledLeft.Position.X))
                        cursorY = CInt(Fix(scaledLeft.Position.Y))
                    Else
                        cursorX = CInt(Fix(scaledRight.Position.X))
                        cursorY = CInt(Fix(scaledRight.Position.Y))
                    End If

                    Dim leftClick As Boolean
                    ' figure out whether the mouse button is down based on where the opposite hand is
                    If (LeftHand.IsChecked.GetValueOrDefault() AndAlso jointRight.Position.Y > ClickThreshold) OrElse ((Not LeftHand.IsChecked.GetValueOrDefault()) AndAlso jointLeft.Position.Y > ClickThreshold) Then
                        leftClick = True
                        '  MsgBox("clicked")
                    Else
                        leftClick = False
                    End If
                    For g = 0 To 5
                        allSkeletons(g).TrackingId = 0

                        For f = 0 To activeCount - 1
                          
                            Select Case f
                                Case Is = 0
                                    playerid(0) = CInt(Rnd() * 4)
                                    s.TrackingId = playerid(0)
                                Case Is = 1
                                    playerid(1) = CInt(Rnd() * 4 + 5)  ' 5  -  9
                                    'playerid(1) = 2
                                    s.TrackingId = playerid(1)
                                Case Is = 2
                                    ' playerid(2) = 3
                                    playerid(2) = CInt(Rnd() * 4 + 10) ' 10 - 14
                                    s.TrackingId = playerid(2)
                                Case Is = 3
                                    playerid(3) = CInt(Rnd() * 4 + 15) ' 15 - 19
                                    s.TrackingId = playerid(3)
                                Case Is = 4
                                    playerid(4) = CInt(Rnd() * 4 + 20) ' 20 - 24
                                    s.TrackingId = playerid(4)
                                Case Is = 5
                                    playerid(5) = CInt(Rnd() * 4 + 25) ' 25 - 29
                                    allSkeletons(5).TrackingId = playerid(5)
                            End Select
                         
                        Next
                    Next
                    'if i is less then the total amount of players then send players coordinates for person that is active.
                    If i <= 5 Then
                        Select Case True
                            Case Is = s.TrackingId >= 1 And s.TrackingId <= 4
                                i = 0
                                playeractive(i) = True
                                player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                ' sensor.SkeletonStream.ChooseSkeletons(1, 2)
                            Case Is = s.TrackingId >= 5 And s.TrackingId <= 9
                                i = 1
                                playeractive(i) = True
                                player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 10 And s.TrackingId <= 14
                                i = 2
                                playeractive(i) = True
                                player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 15 And s.TrackingId <= 19
                                i = 3
                                playeractive(i) = True
                                player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 20 And s.TrackingId <= 24
                                i = 4
                                playeractive(i) = True
                                player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 25 And s.TrackingId <= 29
                                i = 5
                                playeractive(i) = True
                                player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                        End Select
                        Log("person #: " + i.ToString + "Tracking ID: " + s.TrackingId.ToString)
                        currentperson.Content = i.ToString + "Tracking ID: " + s.TrackingId.ToString
                    End If
                    'If playeractive(i) = True And i >= 0 And frame.SkeletonArrayLength > 0 Then
                    'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick, totalplayers, i)

                    'End If

                    'if total players is 1 or greater send coordinate data.
                    If totalplayers >= 1 Then
                        DefineMouseData(cursorX, cursorY, leftClick)
                    End If
                    'make the below code active when I get multiple player tracking working
                    If playeractive(i) = True Then
                        ' Environment.SetEnvironmentVariable("Player" + i.ToString + "xcoords", player(i).bytex.ToString, EnvironmentVariableTarget.Machine)
                        ' Environment.SetEnvironmentVariable("Player" + i.ToString + "ycoords", player(i).bytey.ToString, EnvironmentVariableTarget.Machine)
                        'Environment.SetEnvironmentVariable("Player" + i.ToString + "leftclick", player(i).leftclick.ToString, EnvironmentVariableTarget.Machine)
                        'System.Threading.Thread.Sleep(300)
                    End If
                    If i <= 5 Then
                        If playeractive(5) = True Then
                            'if 6th player exit for loop and open next frame.
                            playeractive(5) = False
                            Exit For
                        Else
                            'd = d + 1
                        End If

                    End If
                End If
                NumPassive.Content = "passive count: " + passiveCount.ToString
                Numactive.Content = "active count: " + activeCount.ToString
                nottrackedplayers.Content = "not tracked players: " + nottracked.ToString
                playeractive(i) = False
                ' Next
                For h = 0 To activeCount - 1
                    If h >= 2 Then
                        If activeCount - 1 > 0 Then
            'identify specific players by ID
            'ResetValues()

            'player #1
            playerid(0) = CInt(Rnd() * 4)
            ' playerid(0) = 1
            allSkeletons(0).TrackingId = playerid(0)
            Log("player#1 tracking: " + allSkeletons(0).TrackingId.ToString)
            'player #2
            playerid(1) = CInt(Rnd() * 4 + 5)  ' 5  -  9
            'playerid(1) = 2
            allSkeletons(1).TrackingId = playerid(1)
            'player #3
            ' playerid(2) = 3
            playerid(2) = CInt(Rnd() * 4 + 10) ' 10 - 14
            allSkeletons(2).TrackingId = playerid(2)
            'player #4
            playerid(3) = CInt(Rnd() * 4 + 15) ' 15 - 19
            allSkeletons(3).TrackingId = playerid(3)
            'player #5
            playerid(4) = CInt(Rnd() * 4 + 20) ' 20 - 24
            allSkeletons(4).TrackingId = playerid(4)
            'player #6
            playerid(5) = CInt(Rnd() * 4 + 25) ' 25 - 29
            allSkeletons(5).TrackingId = playerid(5)
            'force each player to be moved to first blank spot 
            Dim tempList As New List(Of Skeleton)(allSkeletons)
            tempList.RemoveAll(Function(sk) IsNothing(sk))
            allSkeletons = tempList.ToArray
            Log("Tracking id for player#1: " + allSkeletons(0).TrackingId.ToString)
            Log("Tracking id for player#2: " + allSkeletons(1).TrackingId.ToString)
            Log("Tracking id for player#3: " + allSkeletons(2).TrackingId.ToString)
        
       
                If IsNothing(s) Then
                    Exit Sub
                End If
                If s.TrackingState = SkeletonTrackingState.Tracked Then
                    activeCount = activeCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.PositionOnly Then
                    passiveCount = passiveCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.NotTracked Then
                    nottracked = nottracked + 1
                End If
                totalplayers = activeCount + passiveCount + nottracked
                'Log("passive count: " + passiveCount.ToString + " date: " + Now.ToString)

                
                ' the first found/tracked skeleton moves the mouse cursor
                If s.TrackingState = SkeletonTrackingState.Tracked Then

                    ' make sure both hands are tracked
                    'If Skeleton.Joints(JointType.HandLeft).TrackingState = JointTrackingState.Tracked AndAlso Skeleton.Joints(JointType.HandRight).TrackingState = JointTrackingState.Tracked Then
                    Dim cursorX, cursorY As Integer

                    ' get the left and right hand Joints
                    Dim jointRight As Joint = s.Joints(JointType.HandRight)
                    Dim jointLeft As Joint = s.Joints(JointType.HandLeft)

                    ' scale those Joints to the primary screen width and height
                    Dim scaledRight As Joint = jointRight.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    Dim scaledLeft As Joint = jointLeft.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    ' relativemouselocation.Content = jointRight.Position

Figure out X,Y coordinates:

                    ' figure out the cursor position based on left/right handedness
                    If LeftHand.IsChecked.GetValueOrDefault() Then
                        cursorX = CInt(Fix(scaledLeft.Position.X))
                        cursorY = CInt(Fix(scaledLeft.Position.Y))
                    Else
                        cursorX = CInt(Fix(scaledRight.Position.X))
                        cursorY = CInt(Fix(scaledRight.Position.Y))
                    End If

                    Dim leftClick As Boolean
                    ' figure out whether the mouse button is down based on where the opposite hand is
                    If (LeftHand.IsChecked.GetValueOrDefault() AndAlso jointRight.Position.Y > ClickThreshold) OrElse ((Not LeftHand.IsChecked.GetValueOrDefault()) AndAlso jointLeft.Position.Y > ClickThreshold) Then
                        leftClick = True
                        '  MsgBox("clicked")
                    Else
                        leftClick = False
                    End If
                    For g = 0 To 5
                        allSkeletons(g).TrackingId = 0

                        For f = 0 To activeCount - 1
                          
                            Select Case f
                                Case Is = 0
                                    playerid(0) = CInt(Rnd() * 4)
                                    s.TrackingId = playerid(0)
                                Case Is = 1
                                    playerid(1) = CInt(Rnd() * 4 + 5)  ' 5  -  9
                                    'playerid(1) = 2
                                    s.TrackingId = playerid(1)
                                Case Is = 2
                                    ' playerid(2) = 3
                                    playerid(2) = CInt(Rnd() * 4 + 10) ' 10 - 14
                                    s.TrackingId = playerid(2)
                                Case Is = 3
                                    playerid(3) = CInt(Rnd() * 4 + 15) ' 15 - 19
                                    s.TrackingId = playerid(3)
                                Case Is = 4
                                    playerid(4) = CInt(Rnd() * 4 + 20) ' 20 - 24
                                    s.TrackingId = playerid(4)
                                Case Is = 5
                                    playerid(5) = CInt(Rnd() * 4 + 25) ' 25 - 29
                                    allSkeletons(5).TrackingId = playerid(5)
                            End Select
                         
                        Next
                    Next
                    'if i is less then the total amount of players then send players coordinates for person that is active.
                    If i <= 5 Then
                        Select Case True
                            Case Is = s.TrackingId >= 1 And s.TrackingId <= 4
                                i = 0
                                playeractive(i) = True
                                player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                ' sensor.SkeletonStream.ChooseSkeletons(1, 2)
                            Case Is = s.TrackingId >= 5 And s.TrackingId <= 9
                                i = 1
                                playeractive(i) = True
                                player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 10 And s.TrackingId <= 14
                                i = 2
                                playeractive(i) = True
                                player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 15 And s.TrackingId <= 19
                                i = 3
                                playeractive(i) = True
                                player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 20 And s.TrackingId <= 24
                                i = 4
                                playeractive(i) = True
                                player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 25 And s.TrackingId <= 29
                                i = 5
                                playeractive(i) = True
                                player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                        End Select
                        Log("person #: " + i.ToString + "Tracking ID: " + s.TrackingId.ToString)
                        currentperson.Content = i.ToString + "Tracking ID: " + s.TrackingId.ToString
                    End If
                    'If playeractive(i) = True And i >= 0 And frame.SkeletonArrayLength > 0 Then
                    'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick, totalplayers, i)

                    'End If

                    'if total players is 1 or greater send coordinate data.
                    If totalplayers >= 1 Then
                        DefineMouseData(cursorX, cursorY, leftClick)
                    End If
                    'make the below code active when I get multiple player tracking working
                    If playeractive(i) = True Then
                    
                    End If
                    If i <= 5 Then
                        If playeractive(5) = True Then
                            'if 6th player exit for loop and open next frame.
                            playeractive(5) = False
                            Exit For
                        Else
                            'd = d + 1
                        End If

                    End If
                End If
                NumPassive.Content = "passive count: " + passiveCount.ToString
                Numactive.Content = "active count: " + activeCount.ToString
                nottrackedplayers.Content = "not tracked players: " + nottracked.ToString
                playeractive(i) = False
                ' Next
                For h = 0 To activeCount - 1
                    If h >= 2 Then
                        If activeCount - 1 > 0 Then
            'identify specific players by ID
              'ResetValues()
            For j = 0 To playerid.Length - 1
                'all players
                playerid(i) = CInt(Rnd() * 4 + (i * 5))
                allSkeletons(i).TrackingId = playerid(0)
            Next j
            'force each player to be moved to first blank spot 
            Dim tempList As New List(Of Skeleton)(allSkeletons)
            tempList.RemoveAll(Function(sk) IsNothing(sk))
            allSkeletons = tempList.ToArray
            Log("Tracking id for player#1: " + allSkeletons(0).TrackingId.ToString)
            Log("Tracking id for player#2: " + allSkeletons(1).TrackingId.ToString)
            Log("Tracking id for player#3: " + allSkeletons(2).TrackingId.ToString)         
       
                If IsNothing(s) Then
                    Exit Sub
                End If
                If s.TrackingState = SkeletonTrackingState.Tracked Then
                    activeCount = activeCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.PositionOnly Then
                    passiveCount = passiveCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.NotTracked Then
                    nottracked = nottracked + 1
                End If
                totalplayers = activeCount + passiveCount + nottracked
                'Log("passive count: " + passiveCount.ToString + " date: " + Now.ToString)

               

Player x,y display:

                     ' the first found/tracked skeleton moves the mouse cursor
                If s.TrackingState = SkeletonTrackingState.Tracked Then

                    ' make sure both hands are tracked
                    'If Skeleton.Joints(JointType.HandLeft).TrackingState = JointTrackingState.Tracked AndAlso Skeleton.Joints(JointType.HandRight).TrackingState = JointTrackingState.Tracked Then
                    Dim cursorX, cursorY As Integer

                    ' get the left and right hand Joints
                    Dim jointRight As Joint = s.Joints(JointType.HandRight)
                    Dim jointLeft As Joint = s.Joints(JointType.HandLeft)

                    ' scale those Joints to the primary screen width and height
                    Dim scaledRight As Joint = jointRight.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    Dim scaledLeft As Joint = jointLeft.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    ' relativemouselocation.Content = jointRight.Position
                    ' figure out the cursor position based on left/right handedness
                    If LeftHand.IsChecked.GetValueOrDefault() Then
                        cursorX = CInt(Fix(scaledLeft.Position.X))
                        cursorY = CInt(Fix(scaledLeft.Position.Y))
                    Else
                        cursorX = CInt(Fix(scaledRight.Position.X))
                        cursorY = CInt(Fix(scaledRight.Position.Y))
                    End If

                    Dim leftClick As Boolean
                    ' figure out whether the mouse button is down based on where the opposite hand is
                    If (LeftHand.IsChecked.GetValueOrDefault() AndAlso jointRight.Position.Y > ClickThreshold) OrElse ((Not LeftHand.IsChecked.GetValueOrDefault()) AndAlso jointLeft.Position.Y > ClickThreshold) Then
                        leftClick = True
                        '  MsgBox("clicked")
                    Else
                        leftClick = False
                    End If

                    'if i is less then the total amount of players then send players coordinates for person that is active.
                    If i <= 5 Then
                        Select Case True
                            Case Is = s.TrackingId >= 1 And s.TrackingId <= 4
                                i = 0
                                playeractive(i) = True
                                player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                ' sensor.SkeletonStream.ChooseSkeletons(1, 2)
                            Case Is = s.TrackingId >= 5 And s.TrackingId <= 9
                                i = 1
                                playeractive(i) = True
                                player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 10 And s.TrackingId <= 14
                                i = 2
                                playeractive(i) = True
                                player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 15 And s.TrackingId <= 19
                                i = 3
                                playeractive(i) = True
                                player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 20 And s.TrackingId <= 24
                                i = 4
                                playeractive(i) = True
                                player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 25 And s.TrackingId <= 29
                                i = 5
                                playeractive(i) = True
                                player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                        End Select
                        Log("person #: " + i.ToString + "Tracking ID: " + s.TrackingId.ToString)
                        currentperson.Content = i.ToString + "Tracking ID: " + s.TrackingId.ToString
                    End If
                    'If playeractive(i) = True And i >= 0 And frame.SkeletonArrayLength > 0 Then
                    'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick, totalplayers, i)

                    'End If

                    'if total players is 1 or greater send coordinate data.
                    If totalplayers >= 1 Then
                        DefineMouseData(cursorX, cursorY, leftClick)
                    End If
                    'make the below code active when I get multiple player tracking working
                    If playeractive(i) = True Then
                        ' Environment.SetEnvironmentVariable("Player" + i.ToString + "xcoords", player(i).bytex.ToString, EnvironmentVariableTarget.Machine)
                        ' Environment.SetEnvironmentVariable("Player" + i.ToString + "ycoords", player(i).bytey.ToString, EnvironmentVariableTarget.Machine)
                        'Environment.SetEnvironmentVariable("Player" + i.ToString + "leftclick", player(i).leftclick.ToString, EnvironmentVariableTarget.Machine)
                        'System.Threading.Thread.Sleep(300)
                    End If
                    If i <= 5 Then
                        If playeractive(5) = True Then
                            'if 6th player exit for loop and open next frame.
                            playeractive(5) = False
                            Exit For
                        Else
                            'd = d + 1
                        End If

                    End If
                End If
                NumPassive.Content = "passive count: " + passiveCount.ToString
                Numactive.Content = "active count: " + activeCount.ToString
                nottrackedplayers.Content = "not tracked players: " + nottracked.ToString
                playeractive(i) = False
       
added 9151 characters in body
Source Link
jeff
  • 131
  • 5
                If IsNothing(s) Then
                    Exit Sub
                End If
                If s.TrackingState = SkeletonTrackingState.Tracked Then
                    activeCount = activeCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.PositionOnly Then
                    passiveCount = passiveCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.NotTracked Then
                    nottracked = nottracked + 1
                End If
                totalplayers = activeCount + passiveCount + nottracked
                'Log("passive count: " + passiveCount.ToString + " date: " + Now.ToString)

                
                ' the first found/tracked skeleton moves the mouse cursor
                If s.TrackingState = SkeletonTrackingState.Tracked Then

                    ' make sure both hands are tracked
                    'If Skeleton.Joints(JointType.HandLeft).TrackingState = JointTrackingState.Tracked AndAlso Skeleton.Joints(JointType.HandRight).TrackingState = JointTrackingState.Tracked Then
                    Dim cursorX, cursorY As Integer

                    ' get the left and right hand Joints
                    Dim jointRight As Joint = s.Joints(JointType.HandRight)
                    Dim jointLeft As Joint = s.Joints(JointType.HandLeft)

                    ' scale those Joints to the primary screen width and height
                    Dim scaledRight As Joint = jointRight.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    Dim scaledLeft As Joint = jointLeft.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    ' relativemouselocation.Content = jointRight.Position

Figure out X,Y coordinates:

                    ' figure out the cursor position based on left/right handedness
                    If LeftHand.IsChecked.GetValueOrDefault() Then
                        cursorX = CInt(Fix(scaledLeft.Position.X))
                        cursorY = CInt(Fix(scaledLeft.Position.Y))
                    Else
                        cursorX = CInt(Fix(scaledRight.Position.X))
                        cursorY = CInt(Fix(scaledRight.Position.Y))
                    End If

                    Dim leftClick As Boolean
                    ' figure out whether the mouse button is down based on where the opposite hand is
                    If (LeftHand.IsChecked.GetValueOrDefault() AndAlso jointRight.Position.Y > ClickThreshold) OrElse ((Not LeftHand.IsChecked.GetValueOrDefault()) AndAlso jointLeft.Position.Y > ClickThreshold) Then
                        leftClick = True
                        '  MsgBox("clicked")
                    Else
                        leftClick = False
                    End If
                    For g = 0 To 5
                        allSkeletons(g).TrackingId = 0

                        For f = 0 To activeCount - 1
                          
                            Select Case f
                                Case Is = 0
                                    playerid(0) = CInt(Rnd() * 4)
                                    s.TrackingId = playerid(0)
                                Case Is = 1
                                    playerid(1) = CInt(Rnd() * 4 + 5)  ' 5  -  9
                                    'playerid(1) = 2
                                    s.TrackingId = playerid(1)
                                Case Is = 2
                                    ' playerid(2) = 3
                                    playerid(2) = CInt(Rnd() * 4 + 10) ' 10 - 14
                                    s.TrackingId = playerid(2)
                                Case Is = 3
                                    playerid(3) = CInt(Rnd() * 4 + 15) ' 15 - 19
                                    s.TrackingId = playerid(3)
                                Case Is = 4
                                    playerid(4) = CInt(Rnd() * 4 + 20) ' 20 - 24
                                    s.TrackingId = playerid(4)
                                Case Is = 5
                                    playerid(5) = CInt(Rnd() * 4 + 25) ' 25 - 29
                                    allSkeletons(5).TrackingId = playerid(5)
                            End Select
                         
                        Next
                    Next
                    'if i is less then the total amount of players then send players coordinates for person that is active.
                    If i <= 5 Then
                        Select Case True
                            Case Is = s.TrackingId >= 1 And s.TrackingId <= 4
                                i = 0
                                playeractive(i) = True
                                player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                ' sensor.SkeletonStream.ChooseSkeletons(1, 2)
                            Case Is = s.TrackingId >= 5 And s.TrackingId <= 9
                                i = 1
                                playeractive(i) = True
                                player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 10 And s.TrackingId <= 14
                                i = 2
                                playeractive(i) = True
                                player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 15 And s.TrackingId <= 19
                                i = 3
                                playeractive(i) = True
                                player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 20 And s.TrackingId <= 24
                                i = 4
                                playeractive(i) = True
                                player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 25 And s.TrackingId <= 29
                                i = 5
                                playeractive(i) = True
                                player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                        End Select
                        Log("person #: " + i.ToString + "Tracking ID: " + s.TrackingId.ToString)
                        currentperson.Content = i.ToString + "Tracking ID: " + s.TrackingId.ToString
                    End If
                    'If playeractive(i) = True And i >= 0 And frame.SkeletonArrayLength > 0 Then
                    'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick, totalplayers, i)

                    'End If

                    'if total players is 1 or greater send coordinate data.
                    If totalplayers >= 1 Then
                        DefineMouseData(cursorX, cursorY, leftClick)
                    End If
                    'make the below code active when I get multiple player tracking working
                    If playeractive(i) = True Then
                    
                    End If
                    If i <= 5 Then
                        If playeractive(5) = True Then
                            'if 6th player exit for loop and open next frame.
                            playeractive(5) = False
                            Exit For
                        Else
                            'd = d + 1
                        End If

                    End If
                End If
                NumPassive.Content = "passive count: " + passiveCount.ToString
                Numactive.Content = "active count: " + activeCount.ToString
                nottrackedplayers.Content = "not tracked players: " + nottracked.ToString
                playeractive(i) = False
                ' Next
                For h = 0 To activeCount - 1
                    If h >= 2 Then
                        If activeCount - 1 > 0 Then
                If s           sensor.TrackingIdSkeletonStream.ChooseSkeletons(playerid(h), >playerid(h 0+ Then
1))
                    sensor.SkeletonStream.ChooseSkeletons(s.TrackingId)    End If
                    End If
                Next
            Next

            ResetValues()

        End Using
                If IsNothing(s) Then
                    Exit Sub
                End If
                If s.TrackingState = SkeletonTrackingState.Tracked Then
                    activeCount = activeCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.PositionOnly Then
                    passiveCount = passiveCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.NotTracked Then
                    nottracked = nottracked + 1
                End If
                totalplayers = activeCount + passiveCount + nottracked
                'Log("passive count: " + passiveCount.ToString + " date: " + Now.ToString)
                If s.TrackingId > 0 Then

                    sensor.SkeletonStream.ChooseSkeletons(s.TrackingId)
                End If
                If IsNothing(s) Then
                    Exit Sub
                End If
                If s.TrackingState = SkeletonTrackingState.Tracked Then
                    activeCount = activeCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.PositionOnly Then
                    passiveCount = passiveCount + 1
                End If
                If s.TrackingState = SkeletonTrackingState.NotTracked Then
                    nottracked = nottracked + 1
                End If
                totalplayers = activeCount + passiveCount + nottracked
                'Log("passive count: " + passiveCount.ToString + " date: " + Now.ToString)

                
                ' the first found/tracked skeleton moves the mouse cursor
                If s.TrackingState = SkeletonTrackingState.Tracked Then

                    ' make sure both hands are tracked
                    'If Skeleton.Joints(JointType.HandLeft).TrackingState = JointTrackingState.Tracked AndAlso Skeleton.Joints(JointType.HandRight).TrackingState = JointTrackingState.Tracked Then
                    Dim cursorX, cursorY As Integer

                    ' get the left and right hand Joints
                    Dim jointRight As Joint = s.Joints(JointType.HandRight)
                    Dim jointLeft As Joint = s.Joints(JointType.HandLeft)

                    ' scale those Joints to the primary screen width and height
                    Dim scaledRight As Joint = jointRight.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    Dim scaledLeft As Joint = jointLeft.ScaleTo(CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), SkeletonMaxX, SkeletonMaxY)
                    ' relativemouselocation.Content = jointRight.Position

Figure out X,Y coordinates:

                    ' figure out the cursor position based on left/right handedness
                    If LeftHand.IsChecked.GetValueOrDefault() Then
                        cursorX = CInt(Fix(scaledLeft.Position.X))
                        cursorY = CInt(Fix(scaledLeft.Position.Y))
                    Else
                        cursorX = CInt(Fix(scaledRight.Position.X))
                        cursorY = CInt(Fix(scaledRight.Position.Y))
                    End If

                    Dim leftClick As Boolean
                    ' figure out whether the mouse button is down based on where the opposite hand is
                    If (LeftHand.IsChecked.GetValueOrDefault() AndAlso jointRight.Position.Y > ClickThreshold) OrElse ((Not LeftHand.IsChecked.GetValueOrDefault()) AndAlso jointLeft.Position.Y > ClickThreshold) Then
                        leftClick = True
                        '  MsgBox("clicked")
                    Else
                        leftClick = False
                    End If
                    For g = 0 To 5
                        allSkeletons(g).TrackingId = 0

                        For f = 0 To activeCount - 1
                          
                            Select Case f
                                Case Is = 0
                                    playerid(0) = CInt(Rnd() * 4)
                                    s.TrackingId = playerid(0)
                                Case Is = 1
                                    playerid(1) = CInt(Rnd() * 4 + 5)  ' 5  -  9
                                    'playerid(1) = 2
                                    s.TrackingId = playerid(1)
                                Case Is = 2
                                    ' playerid(2) = 3
                                    playerid(2) = CInt(Rnd() * 4 + 10) ' 10 - 14
                                    s.TrackingId = playerid(2)
                                Case Is = 3
                                    playerid(3) = CInt(Rnd() * 4 + 15) ' 15 - 19
                                    s.TrackingId = playerid(3)
                                Case Is = 4
                                    playerid(4) = CInt(Rnd() * 4 + 20) ' 20 - 24
                                    s.TrackingId = playerid(4)
                                Case Is = 5
                                    playerid(5) = CInt(Rnd() * 4 + 25) ' 25 - 29
                                    allSkeletons(5).TrackingId = playerid(5)
                            End Select
                         
                        Next
                    Next
                    'if i is less then the total amount of players then send players coordinates for person that is active.
                    If i <= 5 Then
                        Select Case True
                            Case Is = s.TrackingId >= 1 And s.TrackingId <= 4
                                i = 0
                                playeractive(i) = True
                                player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                ' sensor.SkeletonStream.ChooseSkeletons(1, 2)
                            Case Is = s.TrackingId >= 5 And s.TrackingId <= 9
                                i = 1
                                playeractive(i) = True
                                player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 10 And s.TrackingId <= 14
                                i = 2
                                playeractive(i) = True
                                player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString

                            Case Is = s.TrackingId >= 15 And s.TrackingId <= 19
                                i = 3
                                playeractive(i) = True
                                player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 20 And s.TrackingId <= 24
                                i = 4
                                playeractive(i) = True
                                player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                            Case Is = s.TrackingId >= 25 And s.TrackingId <= 29
                                i = 5
                                playeractive(i) = True
                                player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                        End Select
                        Log("person #: " + i.ToString + "Tracking ID: " + s.TrackingId.ToString)
                        currentperson.Content = i.ToString + "Tracking ID: " + s.TrackingId.ToString
                    End If
                    'If playeractive(i) = True And i >= 0 And frame.SkeletonArrayLength > 0 Then
                    'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick, totalplayers, i)

                    'End If

                    'if total players is 1 or greater send coordinate data.
                    If totalplayers >= 1 Then
                        DefineMouseData(cursorX, cursorY, leftClick)
                    End If
                    'make the below code active when I get multiple player tracking working
                    If playeractive(i) = True Then
                    
                    End If
                    If i <= 5 Then
                        If playeractive(5) = True Then
                            'if 6th player exit for loop and open next frame.
                            playeractive(5) = False
                            Exit For
                        Else
                            'd = d + 1
                        End If

                    End If
                End If
                NumPassive.Content = "passive count: " + passiveCount.ToString
                Numactive.Content = "active count: " + activeCount.ToString
                nottrackedplayers.Content = "not tracked players: " + nottracked.ToString
                playeractive(i) = False
                ' Next
                For h = 0 To activeCount - 1
                    If h >= 2 Then
                        If activeCount - 1 > 0 Then
                            sensor.SkeletonStream.ChooseSkeletons(playerid(h), playerid(h + 1))
                        End If
                    End If
                Next
            Next

            ResetValues()

        End Using
deleted 537 characters in body
Source Link
jeff
  • 131
  • 5
Loading
deleted 537 characters in body
Source Link
jeff
  • 131
  • 5
Loading
deleted 537 characters in body
Source Link
jeff
  • 131
  • 5
Loading
corrections
Source Link
jeff
  • 131
  • 5
Loading
Source Link
jeff
  • 131
  • 5
Loading