Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Handle Disappear Event
Browse files Browse the repository at this point in the history
  • Loading branch information
ReiiYuki committed Jun 23, 2017
1 parent 3022cd5 commit fefe28b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Assets/Example/Scripts/HandPositionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,24 @@ void OnRightHandChange(Vector3 handPosition)
rightCursor.transform.position = Camera.main.transform.position + new Vector3(handPosition.x * 100, handPosition.y * 100, handPosition.z * 100) + Camera.main.transform.forward;
}

void OnLeftHandAppear()
{
leftCursor.SetActive(true);
}

void OnLeftHandDisappear()
{
leftCursor.SetActive(false);
}

void OnRightHandAppear()
{
rightCursor.SetActive(true);
}

void OnRightHandDisappear()
{
rightCursor.SetActive(false);
}

}
37 changes: 37 additions & 0 deletions Assets/IRToolkit/Scripts/HandPositionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
using Intel.RealSense;

public class HandPositionManager : Publisher {

enum State
{
Appear,
Lost
}

HandManager handManager;
State leftHandState, rightHandState;

// Update is called once per frame
void Update () {
Expand All @@ -19,17 +27,46 @@ void UpdateHandPosition()
if (GetComponent<DepthCameraManger>().isStart)
if (handManager.handData != null)
{
State isLeftAppear = State.Lost;
State isRightAppear = State.Lost;
for (int i = 0; i < handManager.handData.NumberOfHands; i++)
{
IHand hand;
if (handManager.handData.QueryHandData(AccessOrderType.ACCESS_ORDER_BY_TIME,i,out hand) == Status.STATUS_NO_ERROR)
{
if (hand.BodySide == BodySideType.BODY_SIDE_LEFT)
{
Boardcast("OnLeftHandChange", new Vector3(hand.MassCenterWorld.x, hand.MassCenterWorld.y, hand.MassCenterWorld.z));
isLeftAppear = State.Appear;
}
else if (hand.BodySide == BodySideType.BODY_SIDE_RIGHT)
{
Boardcast("OnRightHandChange", new Vector3(hand.MassCenterWorld.x, hand.MassCenterWorld.y, hand.MassCenterWorld.z));
isRightAppear = State.Appear;
}
}
}
CheckStateChange(isLeftAppear, isRightAppear);
}
}

void CheckStateChange(State isLeftHandAppear,State isRightHandAppear)
{
if (leftHandState != isLeftHandAppear)
{
if (isLeftHandAppear == State.Appear)
Boardcast("OnLeftHandAppear");
else
Boardcast("OnLeftHandDisappear");
leftHandState = isLeftHandAppear;
}
if (rightHandState != isRightHandAppear)
{
if (isRightHandAppear == State.Appear)
Boardcast("OnRightHandAppear");
else
Boardcast("OnRightHandDisappear");
rightHandState = isLeftHandAppear;
}
}
}

0 comments on commit fefe28b

Please sign in to comment.