27: Moving with gaze
This post was published in 2016 and is kept here for reference. It may contain information that's outdated or inaccurate.
Today’s hack is more an aside while I’m focussing on yet another Tevris rewrite.
I thought I’d play with an idea for controlling the left/right movement of the active piece based on where you’re looking.
Now, knowing where you’re looking in 3D space is both a hard thing to Google, and a hard thing to explain. So take this solution with a grain of salt:
var getpos = function (obj) {
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
var mat = new THREE.Matrix4().multiplyMatrices( camera.matrixWorldInverse, obj.matrixWorld );
var pos = obj.position.clone().applyProjection(mat);
return pos;
};
var getLooking = function () {
var pos = getpos(board[0][Math.floor(cols/2)]);
// MAGIC 💩
if (pos.x - pos.z > 180) {
return 'left';
}
if (pos.x - pos.z < 120) {
return 'right';
}
};
There’s a lot going on there, and some MAGIC, and it’s not going to scale, but it sort of works.

I’m not completely happy with this, so you may have noticed the poop emoji (💩) all over the place. I’ll definitely throw this away with the re-write I’m working on, but it’s nice to explore the idea.
Cardboctober day 27
View this Cardboctober hack • View the source code on Github
View the other submissions for day 27 on the Cardboctober website.
Part of the "Cardboctober" series
- Announcing Cardboctober
- 01: Basic VR
- 02: Raycaster based look interaction
- 03: Even better gazed based look interaction
- 04: Skyboxes and generating meshes
- 05: Loading external models
- 06: VR Pairs Game
- 07: Cardboard hardware (cardware?)
- 08: Playing sounds
- 09: Speech recognition
- 10: HTML5 Video
- 11: Webaudio Beat Sequencer
- 12: AAAAH! Zombies
- 13: AAAAH! More Zombies
- 14: Debugging your Cardboard with Chrome
- 15: The Hierarchy of Needs in Quick Google Cardboard Hacks
- 16: Getting in and out of Fullscreen
- 17: Displaying Pertinent Information
- 18: Moving around in VR
- 19: Which way is North? Part 1
- 20: Which way is North? Part 2
- 21: One size doesn't fit all
- 22: Putting it all together
- 23: Planning Tetrominoes in VR
- 24: Basic Game Board
- 25: Creating and Moving Pieces
- 26: Rotating Pieces
- 27: Moving with gaze
- 28: Planning Revisited
- 29: Blocks out of the pram
- 30: Github Contributions
- 31: Something in the Shadows
Want to reply? I've hooked up Webmentions, so give it a go!