> For the complete documentation index, see [llms.txt](https://jorge-jgnz94.gitbook.io/hptk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jorge-jgnz94.gitbook.io/hptk/master/examples.md).

# Examples

## Avatar

How to access the **left hand of the first registered avatar**?

```csharp
HandView hand = HPTK.core.avatars[0].body.leftHand;
```

How to access the **Transform of the master representation of the tip of the pinky finger**?

```csharp
Transform tip = hand.pinky.tip.reprs[AvatarModel.key].transformRef;
```

*or*

```csharp
Transform tip = hand.pinky.tip.master.transformRef;
```

How to get the **avatar from a hand**?

```csharp
AvatarView a = hand.body.avatar;
```

How to get the **root bone of the parent part of the hand** (upper arm bone)?

```csharp
BoneView b = hand.parent.root;
```

## Input

How to **listen to tracking lost/recovery events**?

```csharp
InputView input = hand.GetRegisteredView<InputView>();
if (input != null)
{
	input.onHandTrackingLost.AddListener(myMethodA);
	input.onHandTrackingRecovered.AddListener(myMethodB);
}
```

## Contact detection

How to get the **list of objects that are at least being hovered**?

```csharp
ContactDetectionView detector = hand.GetRegisteredView<ContactDetectionView>();
if (detector != null)
{
	List<ContactableView> contactables = detector.contacts.FindAll(c => c.type >= ContactType.Entered).ConvertAll(c => c.contactable);
}
```

## Gesture detection

How to **do something only** **when the user is performing a gesture** (index pinch) **but not another one** (pose match)?

```csharp
GestureDetectionView detector = hand.GetRegisteredView<GestureDetectionView>();
if (detector != null)
{
	Gesture poseMatch = detector.extra.Find(g => g is HandPoseMatch);
	Gesture indexPinch = detector.index.pinch;

	// .lerp values goes from 0.0 to 1.0
	if (indexPinch.lerp > 0.8f && poseMatch.lerp < 0.2f)
	{
		// ...
	}
}
```

## Puppet

How to **make slave hand to fall dramatically** after 10 seconds?

```csharp
AsyncHelpers.DoAfterTime(this, 10.0f, () =>
{
	if (hand.wrist.reprs.ContainsKey(PuppetModel.key) && hand.wrist.reprs[PuppetModel.key] is PuppetReprView)
	{
		PuppetReprView puppetRepr = hand.wrist.reprs[PuppetModel.key] as PuppetReprView;
		
		puppetRepr.pheasy.rb.useGravity = true;
		
		ConfigurableJoint wristJoint = puppetRepr.constraint.joint;
		
		wristJoint.xDrive = new JointDrive();
		wristJoint.yDrive = new JointDrive();
		wristJoint.zDrive = new JointDrive();
		wristJoint.slerpDrive = new JointDrive();
	}
});
```

How to get the **maximum stregth for the rotation drive of the physical constraint** that drives the index root?

```csharp
BoneView indexRoot = hand.index.root;
if (indexRoot.point.reprs.ContainsKey("slave") && indexRoot.point.reprs["slave"] is PuppetReprView)
{
	PuppetReprView puppetRepr = indexRoot.point.reprs["slave"] as PuppetReprView;
	float strength = puppetRepr.constraint.settings.angularDrive.maxForce;
}
```

*or without hard-coded representation keys **(recommended)***

```csharp
BoneView indexRoot = hand.index.root;
if (indexRoot.point.reprs.ContainsKey(PuppetModel.key) && indexRoot.point.reprs[PuppetModel.key] is PuppetReprView)
{
	PuppetReprView puppetRepr = indexRoot.point.reprs[PuppetModel.key] as PuppetReprView;
	float strength = puppetRepr.constraint.settings.angularDrive.maxForce;
}
```
