Symetrical re-use of objects in scene, should be basic pythag?

Hi,

I’m trying to work out how to re-use lots of objects in my scene so that any 1 object that moves past a certain distance comes back into the viewport on the symetrical opposite side. Like the asteroids game does in 2D, rock goes out 1 side, comes back in the other, however the 3D version of this calculation is baffling me.

http://dev.aftc.io/webgl/threejs/Q%26A/Q1

  1. The camera is the thing that is moving as I need this to be a first person camera.

  2. If you rotate the camera in the link (not too much) then you will see that the cube moves up or down the browser Y axies in 2D and needs to re-appear when the limit has been reached on the other side at that Y but I’m not sure how to make that calculation between camera location, rotation and scene objects.

View source, lines 247 is where I tried apply pythag but the values I got resulted in an incorrect value to add to the z position of the cube…

Any ideas?