Three.js rotate vector and screen edge detection

Multi tool use
Three.js rotate vector and screen edge detection
I have a vector that I'm trying to keep length but rotate 90deg on colliding with the screen edge, but it gives me a weird out effect… don't know what I can be doing worn but it happens when I try to apply a Matrix and a Euler transform… Also for the screen detection, what I have is okj for detecting on and off screen, but it would be handy to know if it's the bottom, top, righ or left edge… Any clues? Thanks!
var direction = new THREE.Vector3(-0.2, -0.2, 0);
var a = new THREE.Euler( (Math.PI/2), 0, 0, 'XYZ' );
direction.applyEuler(a);
For the collision; I'm using the following:
camera.updateMatrixWorld(); // make sure the camera matrix is updated
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
cameraViewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromMatrix( cameraViewProjectionMatrix );
console.log(frustum.intersectsObject(textMesh));
1 Answer
1
I removed the line to get the reversed camera projection matrix.
The screen edges effectively became an object "outside" my view frustum
, with whom my objects can now actively collide. By being now a negative view frustum, everything but that which we see is a 'walled object' that confines the frustum itself.
view frustum
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The final result can be seen at nelsonvassalo.com
– nvassalo
Jul 1 at 23:10