I am trying to create a gizmo (a 3D
cube) that shows rotation of camera in 3D
space. I am using three.js
.
I've created a cube and assigned it as a child of main camera. With that structure I can rotate cube in local world with subtracting global rotation of it. Therefore it eliminates effect of camera rotation on cube, and cube remains being oriented to world coordinates.
The issue is that I am using the perspective camera and my cube is at left bottom of the screen. This creates depth at view of cube and gives wrong information about orientation of camera in world space.
Here are some view examples
Here is the method that eleminates rotation of camera.
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material =
new THREE.MeshLambertMaterial({color: 0x282828, transparent: true, opacity:
0.4});
var cube = new THREE.Mesh( geometry, material );
camera.add(cube)
this.rotationUpdate=function(){
var worldRot=cube.getWorldRotation();
worldRot._x+=offset;
worldRot._y+=offset;
worldRot._z+=offset;
cube.rotateX(-worldRot._x);
cube.rotateY(-worldRot._y);
cube.rotateZ(-worldRot._z);
debugger;
}
So my question is, how can I manipulate rotation method in a way that cube will be seen as projected on orthographic camera.