AI CHOREOGRAPHY / STUDY / LEVEL 2 OF 7

Placing the
targets.

A pose says "left hand up, 30 cm above the head". But whose left, and where is "up from the head" in the room? The game builds a small coordinate frame around you every frame: which way is forward (toward the coach), which way is right, and how tall you are. Then it turns the pose into two points in the room. Walk around the coach below and watch the targets follow you.

f: forwardfrom your head toward the coach, kept level
→
r: rightf turned 90° on the floor
→
mirrorcopy the hand on your side; swap if you are behind
→
toWorldhead + r·x + up·y + f·z, scaled to your height

Top view of the room

f = your forward, r = your right

You

the ghost player in coach.js
f (forward)
r (right)
aIsLeft
size
left target (x, y, z)
right target (x, y, z)

What you see

the coach from your position; dashed rings are where your hands must go

The real code

coach.js

The body frame (built once per frame from your head position), then the lines that pick each hand's pose and place it in the room. This page runs a copy of exactly these lines, because the scene itself needs a headset.


      
Full file: coach.js ↗ · the vector functions (normalize, dot, add, scale) are in cg.js ↗

What you should be able to explain

  1. A local coordinate frame. f points from your head to the coach with the height removed, so looking up or down does not tilt it. r = [−f.z, 0, f.x] is f turned 90° to the right. Together with "up" they form three axes around you.
  2. toWorld. A pose value [x, y, z] means "x metres along r, y up, z along f", starting at your head: head + r·x + up·y + f·z. This is a change of basis; toBody does the reverse with dot products.
  3. Mirroring. You copy the coach like a mirror: the hand that appears on your left is the one your left hand copies, so its outward value is negated (−1 ×). From behind, the coach's other hand appears on your left, and aIsLeft flips to swap them.
  4. Scaling to the player. size = standH ÷ 1.65, clamped between 0.6 and 1.2, so a tall player's targets are higher and wider, and a child's are closer. standH is the highest head position seen recently, which is why a squat does not shrink the targets.

Exercises: ① Walk in a circle around the coach. Do the targets always stay in front of you? ② Press "Walk behind the coach" and watch aIsLeft and the labels. Why is swapping the right thing to do? ③ Set your height to 1.2 m, then 2.0 m. Which target numbers change, and by how much?