Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 2.4 — Coordinate Spaces
3D Web · Example 1 of 2

One point through every space

The frame (with its own axes) stands at x = 2 and is turned 90° around y; the orange wheel is its child. The camera numbers are for a picture twice as wide as tall.

A point has different numbers depending on what you measure it from. The same wheel is (1, 0, 0) from its frame and (2, 0, −1) from the world, and the GPU carries it through camera, clip and screen space before a pixel is lit.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

A group named pivot sits at (3, 0, 0). Add a ball to it at local (0, 1, 0). Print the ball's world position, then turn pivot 90° around z and print it again.

02

Write a function worldPositionOf(object) that returns a new Vector3, and explain why it is better than reading object.position.

Explain it without notes

01

A wheel is a child of a frame, and the frame is turned 90° and moved to x = 2. How do you get the wheel's position in world space, and what do you expect for a local position of (1, 0, 0)?

02

Explain the difference between parent.add(child) and parent.attach(child), with a case where you need attach.

One point through every space
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

1. local position  (1, 0, 0)
2. world position  (2, 0, -1)
   same, with localToWorld: (2, 0, -1)
   and back, with worldToLocal: (1, 0, 0)
3. camera (view) space  (0.207, -0.088, -7.155)   (the camera is the origin and looks down -z)
4. clip, after dividing by w (NDC)  (0.031, -0.026, 0.974)   (-1 to 1 is inside the picture)
5. screen pixels of a 300 x 150 picture  (155, 77)