MINIATURE / STUDY / LEVEL 5 OF 5

Grabbing
and the switch.

The two interactions the assignment asks for are size-appropriate in opposite directions. In mode 1 the house is a toy: the beam finds its box, and from then on the house keeps the offset it had from my hand when I caught it, and stays on the table top. In mode 2 the switch is a thing on a wall. Its position comes from its global matrix, so the world's ×12 is already in it, but the size of the box the beam must hit is a number written in table inches. That number has to grow too.

press on the houseoffset = house − hand, kept while held
→
each framehouse = clampHouse(hand + offset)
|
press in mode 2switch at its global matrix, box half-size ÷ SCALE
→
lampOnone boolean: lamp, switch and windows in both modes

Mode 1 and mode 2

drag the house on the left · point and click the switch on the right

Mode 1: the table from above, the mouse is my hand

Mode 2: inside the house, the mouse is my beam

What the code sees

On the left, the dashed rectangle is where the house's centre can go: clampHouse keeps the whole house on the table. On the right, the orange box is the hit box the scene tests and the grey box is the forgotten one. Both are drawn from their real corners.

Grabbing

miniature.js · miniatureModel.js

The press records the offset. The release drops the house back to the table's height. Each frame in between, the house follows the hand plus the offset, clamped to the table. It may rise above the table but never sink into it.


      

The switch

miniature.js

In mode 1 the switch is half an inch wide, so it is not offered as a target at all. In mode 2 its centre is read from the engine's global matrix, which already includes the world's growth. The half-size is divided by SCALE, so the box grows the same twelve times.


      
    

What you should be able to explain

  1. Grab with an offset. Without it, the house jumps so that its centre sits in your hand the moment you press. With it, the house moves only as much as your hand does.
  2. Clamp the centre, not the corners. The allowed region is the table minus half the house on each side. The house is turned a quarter, so its width runs along z and its depth along x.
  3. Positions come scaled, sizes do not. A global matrix carries the world's growth into every position, but a half-size written as a constant knows nothing about it. Anything you measure in table units has to be divided by SCALE in mode 2.
  4. One state, two views. The lamp is one boolean. Mode 2 sets it and mode 1 shows it: the windows glow from outside, because drawHouse reads the same flag in both.

Exercises: ① Tick "forget to grow": how wide is the box you are now aiming at, in real centimetres, and why is it so hard to hit? ② Push the house into a corner: which numbers in clampHouse stop it? ③ What would you change so the house can also be carried in mode 2, like a giant would?