LOOK AND TYPE / STUDY / LEVEL 1 OF 5
Where the
head points.
In this scene my hands stay on the laptop's keyboard, so they cannot point at anything. The head has to do the pointing. A headset reports the head as one 4×4 matrix, sixteen numbers. This level turns those numbers into a gaze ray: a starting point and a direction. The matrix holds the head's three axes and its position, column by column. The third axis points out of the back of the head, so straight ahead is minus that axis. That is the whole function. No eye tracking is used: the gaze is where the head points.
Turn the head
drag either picture, or use the slidersFrom the side
What the head sees
In the side view the three short lines are the head's axes: right (green), up (blue), back (grey). The long line is the gaze ray. The cross in the right picture is the middle of the view, which is where the ray goes.
The head matrix
one column per axisThe gaze ray
js/scenes/hw9/gazeType.jsThe matrix is stored as sixteen numbers in a row, column after column. Numbers 8, 9 and 10 are the third column, the back axis. Numbers 12, 13 and 14 are the position. The direction is divided by its own length, so a matrix that also scales still gives a direction one unit long.
Where the ray meets the desk top
js/scenes/hw9/gazeType.jsThe desk top is a flat plane at one height. t is how far along the ray that height is reached. If the point is on the desk (5 cm inside its edges) it is returned, otherwise null. deskPointNear does the same but pulls a point that is off the desk back to the nearest place on it.
Into the desk's coordinates
js/scenes/hw9/deskTyping.jsThe things on the desk are kept in table coordinates (Giant & Mini, level 1). The ray must be in the same coordinates before it is compared with them. A giant's ray is only moved by where the giant stands (giantAt). A mini's head goes through the shrinking matrix M: the head and a point one metre ahead of it are both transformed, and the new direction is the line between them.
What you should be able to explain
- What the columns are. Turn the head with the sliders and watch the first three columns change while the fourth stays. The first three are directions: where the head's right, up and back point in the room. The fourth is where the head is.
- Why minus. In WebXR a head that is not turned looks along −z, and its third axis is +z. Tick the mistake: the ray leaves through the back of the head and the cross no longer matches it.
- Why a ray and not a point. A ray does not say how far away the thing is. The next level uses only the angle between the ray and each thing. This level uses the ray once more, to find a place on the desk top.
- What a pure function buys.
gazeRaytakes sixteen numbers and returns six. It needs no headset, so it runs in a test file and on this page exactly as it runs in the scene.
Exercises: ① Set both sliders to 0. Read the back column and the direction. Why is the direction [0, 0, −1]? ② Tip the head down until the ray meets the desk. Which number of dir must be negative for deskPoint to answer at all, and which line checks it? ③ Look past the right edge of the desk. deskPoint says null. What does deskPointNear say, and which of its three numbers was clamped?