MINIATURE / STUDY / LEVEL 4 OF 5
Walking
and the door.
In mode 2 the camera still cannot move, so a thumbstick cannot carry me forward. It moves the origin instead. The origin is the T(origin) at the front of the world's matrix, so moving it back slides the whole grown world back, and I seem to walk forward. My point on the table moves too, by one twelfth as much. The door checks that point, in table inches, and swings open within three feet. It turns about its hinge, not its middle: the same pivot trick as the shrink, now in one dimension.
The table from above, and what I see
drag the pad or use the arrow keys · A / D turnTable, from above, in inches
Mode 2, from my eyes
Thumbstick
The page runs walkOrigin, nearDoor and the door easing on every animation frame, as the scene does.
Walking: moving the origin
miniatureModel.js · miniature.jsForward is the head's −z column, flattened onto the floor. Right is that direction turned a quarter about the vertical. Either stick works: the scene uses whichever is pushed further. That is the reason this works with one controller.
The door: a hinge node, and easing
house.js · miniature.jsThe door cube sits half a door's width away from an empty hinge node, so turning the hinge swings the door about its edge. The angle is not set directly. Each frame it covers a share of the remaining distance, so the door eases open and shut.
What you should be able to explain
- Moving the origin walks me. The origin sits in the world's T(origin). Subtract a step from it, and the world moves back by a step while the camera stays put.
- The model walks with me, for free. The same origin appears in M, so switching to mode 1 shows the model where I walked to. Nothing has to be synchronised.
- Distances in one unit. The door test compares two points in table coordinates. Comparing my real head with the door would mix metres with table inches.
- Hinges are pivots. move to the hinge, turn, and the door hangs half its width away. Tick the box to see a door turning about its own centre: half of it swings into the house.
- Easing with dt.
angle += (goal − angle) · min(1, 6·dt)reaches the goal at the same speed on a 72 Hz headset and a 120 Hz laptop.
Exercises: ① At 4 ft/s, how many seconds does the model take to cross the 60 ft table? ② Why does pushing the stick up give a negative number, and where does the code flip it? ③ The door opens at 3 ft. In mode 1, the scene doesn't open it however close the model stands. Which condition in the scene makes that so?