none
problem with player code below kinect RRS feed

  • Question

  •  Dim playeractive(5) As Boolean
                Dim i As Integer
                    Using skeletonFrameData As SkeletonFrame = e.OpenSkeletonFrame
                        If skeletonFrameData Is Nothing Then
                            Return
                        End If
                        Dim allSkeletons(skeletonFrameData.SkeletonArrayLength - 1) As Skeleton
                        skeletonFrameData.CopySkeletonDataTo(allSkeletons)
                End Using
                'get total kinect users
                'loop through each player in kinect also seeing if i identified them correctly
                'reset to 0 because active and passive count might be too high if we dont
                passiveCount = 0
                activeCount = 0
                For Each k In Microsoft.Kinect.KinectSensor.KinectSensors
                   
                    k.SkeletonStream.AppChoosesSkeletons = True
                    Using frame = k.SkeletonStream.OpenNextFrame(200)
                        If IsNothing(frame) = False Then
                            Dim s(frame.SkeletonArrayLength - 1) As Skeleton
                            frame.CopySkeletonDataTo(s)
                            For Each player As Skeleton In s
                                If player.TrackingState = SkeletonTrackingState.Tracked Then
                                    activeCount = activeCount + 1
                                End If
                                If player.TrackingState = SkeletonTrackingState.PositionOnly Then
                                    passiveCount = passiveCount + 1
                                    i = 0
                                    k.SkeletonStream.ChooseSkeletons(player.TrackingId)
                                    playeractive(i) = True
                                End If
                           
                                    ' the first found/tracked skeleton moves the mouse cursor
                                    If player.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
                                        Console.WriteLine("player:" + i.ToString)
                                        ' get the left and right hand Joints
                                        Dim jointRight As Joint = player.Joints(JointType.HandRight)
                                        Dim jointLeft As Joint = player.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)
                                        ' 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
                                        Else
                                            leftClick = False
                                        End If
                                        'if player count variable is less then the total amount of players then send players coordinates for person that is active.
                                        If i <= frame.SkeletonArrayLength - 1 Then
                                            Select Case i
                                                Case Is = 0
                                                    player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                                    Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                                Case Is = 1
                                                    player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                                    Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                                Case Is = 2
                                                    player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                                    Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                                Case Is = 3
                                                    player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                                    Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                                Case Is = 4
                                                    player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                                    Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                                Case Is = 5
                                                    player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                                    Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                            End Select
                                            'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick)
                                    End If
                                    If i < frame.SkeletonArrayLength - 1 And playeractive(i) = True Then
                                        i = i + 1
                                        playeractive(i) = False
                                    ElseIf i = frame.SkeletonArrayLength - 1 Then
                                        i = 0
                                    End If
                                    'End If
                                End If
                                'display total passive and active player count
                                totalplayers = passiveCount + activeCount
                                NumPlayers.Content = "Total players:" + totalplayers.ToString
                                NumPassive.Content = "Total passive players:" + passiveCount.ToString
                                Numactive.Content = "Total active players:" + activeCount.ToString
                            Next player
                        End If
                   
                    End Using
                    i = 0
                Next k

    Above i was trying to identify the player using a for each loop and i as a counter variable which identifys the player number. I dont know what im doing wrong but it keeps staying at player one and i want it to go to player 2, 3, and so on if theirs more then 1 person on the list.


    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda


    • Edited by The Thinker Wednesday, March 14, 2012 5:51 PM
    Wednesday, March 14, 2012 5:50 PM

Answers

  • Never mind with a little modification it appears to be switching fast between the skeletons if i do them one at a time and the output shows the player identification as correct but I will post here since i found the solution for someone trying to implement multiple players in a kinect project:

      Dim playeractive(5) As Boolean
                Dim i As Integer
                Dim cursorX, cursorY As Integer
                Dim leftClick As Boolean
                    Using skeletonFrameData As SkeletonFrame = e.OpenSkeletonFrame
                        If skeletonFrameData Is Nothing Then
                            Return
                        End If
                        Dim allSkeletons(skeletonFrameData.SkeletonArrayLength - 1) As Skeleton
                        skeletonFrameData.CopySkeletonDataTo(allSkeletons)
                End Using
                'get total kinect users
                'loop through each player in kinect also seeing if i identified them correctly
                'reset to 0 because active and passive count might be too high if we dont
                passiveCount = 0
                activeCount = 0
                For Each k In Microsoft.Kinect.KinectSensor.KinectSensors
                   
                    k.SkeletonStream.AppChoosesSkeletons = True
                    Using frame = k.SkeletonStream.OpenNextFrame(200)
                        If IsNothing(frame) = False Then
                            Dim s(frame.SkeletonArrayLength - 1) As Skeleton
                            frame.CopySkeletonDataTo(s)
                            For Each player As Skeleton In s
                                If player.TrackingState = SkeletonTrackingState.Tracked Then
                                    activeCount = activeCount + 1
                                End If
                                If player.TrackingState = SkeletonTrackingState.PositionOnly Then
                                    passiveCount = passiveCount + 1
                                    i = 0
                                    k.SkeletonStream.ChooseSkeletons(player.TrackingId)
                                    playeractive(i) = True
                                End If
                           
                                    ' the first found/tracked skeleton moves the mouse cursor
                                    If player.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
                                        Console.WriteLine("player:" + i.ToString)
                                        ' get the left and right hand Joints
                                        Dim jointRight As Joint = player.Joints(JointType.HandRight)
                                        Dim jointLeft As Joint = player.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)
                                        ' 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
                                        ' 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
                                        Else
                                            leftClick = False
                                        End If
                                  
                                    'End If
                                End If
                                'if player count variable is less then the total amount of players then send players coordinates for person that is active.
                                If i <= frame.SkeletonArrayLength - 1 Then
                                    Select Case i
                                        Case Is = 0
                                            player1xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                            Status.Text = "player1 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                        Case Is = 1
                                            player2xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                            Status.Text = "player2 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                        Case Is = 2
                                            player3xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                            Status.Text = "player3 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                        Case Is = 3
                                            player4xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                            Status.Text = "player4 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                        Case Is = 4
                                            player5xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                            Status.Text = "player5 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                        Case Is = 5
                                            player6xy.Content = cursorX & ", " & cursorY & ", " & leftClick
                                            Status.Text = "player6 identified" & cursorX.ToString & ", " & cursorY.ToString & ", " & leftClick.ToString
                                    End Select
                                    'NativeMethods.SendMouseInput(cursorX, cursorY, CInt(Fix(SystemParameters.PrimaryScreenWidth)), CInt(Fix(SystemParameters.PrimaryScreenHeight)), leftClick)
                                    If playeractive(i) = True Then
                                        i = i + 1
                                        playeractive(i) = False
                                    ElseIf i = frame.SkeletonArrayLength - 1 Then
                                        i = 0
                                    End If
                                End If
                                'display total passive and active player count
                                totalplayers = passiveCount + activeCount
                                NumPlayers.Content = "Total players:" + totalplayers.ToString
                                NumPassive.Content = "Total passive players:" + passiveCount.ToString
                                Numactive.Content = "Total active players:" + activeCount.ToString
                            Next player
                        End If
                   
                    End Using
                    i = 0
                Next k

    This only switches fasts between one player at a time to move the mouse but if someone recommends so code enhancements then Im all ears.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda


    • Edited by The Thinker Wednesday, March 14, 2012 6:14 PM
    • Marked as answer by The Thinker Wednesday, March 14, 2012 6:15 PM
    Wednesday, March 14, 2012 6:13 PM