ECHO GARDEN / STUDY / LEVEL 2 OF 7

Pointing
with a beam.

The panel is 1.5 m away, out of reach, so you point at it. A controller beam is a straight line: a starting point o and a direction d. Two questions are asked of that line all the time: where does it hit the panel? (to plant a note) and which note does it pass closest to? (to grab one). Both are a few lines of vector arithmetic, the same as in the course's beamSphere.js. This page draws the garden from the side and runs those lines with the game's cg.js.

the beamorigin o and unit direction d, from the controller matrix
→
hit the panelhow far along d until z reaches the panel: t = (z − o.z) / d.z
→
closest noteproject each note onto the beam with a dot product
→
within 8.5 cm?then the beam is "on" that note

The garden from the side

move the mouse to aim · drag the controller to walk

The panel is on the left; you stand on the right. Dashed lines are each note's shortest distance to the beam. A circle around a note is its 8.5 cm grab radius.

The numbers

aiming
origin o (y, z)
direction d (y, z)
t to the panel
hit point (y)
closest note
its distance

Try this: drag the controller to the left, past a note that sticks out of the panel, then aim away from the panel. Untick the box and see which note the beam "grabs".

The beam and the panel

gameKit.js

ray reads the beam from the controller: its origin is column 3 of the beam matrix and its direction is minus column 2, both turned into the garden's coordinates by the inverse of worldCoords. plane walks along the beam until z reaches the panel. pointsAt asks whether the beam passes within a radius of a point.


      

Where the scene uses them

echoGarden.js

pointOnPanel plants only where the beam meets the panel. nearestSeed is beamSphere.js's projectOntoBeam, done for every note, keeping the closest within 8.5 cm, and skipping notes behind the controller.


      
    

What you should be able to explain

  1. A beam is a line. Every point on it is o + d·t for some distance t. With d of length 1, t is in metres.
  2. Hitting the panel. The panel is the flat surface where z equals −1.455. Solving o.z + d.z·t = z gives t = (z − o.z) / d.z. A negative t means the panel is behind you, and a tiny d.z means the beam runs parallel to it: both give no hit.
  3. The closest point to a note. along = dot(note − o, d) is how far along the beam the note's "shadow" falls. The note's distance from the beam is the length of (note − o) − d·along. This is the projection from beamSphere.js.
  4. Why skip along ≤ 0? The projection works on the whole infinite line, including the part behind the controller. Without the check you could grab a note behind your hand by pointing away from it.

Exercises: ① Aim exactly level (d.y = 0): what is t, and why? ② Aim upward, away from the panel: why does the hit point disappear? ③ Change 8.5 cm to 3 cm in your head: what gets harder for a player whose hand shakes?