hello ,
in pointerLockControl if i move mouse camera change direction , in most case “shoulder” keep horizontal but sometime -when lot of processing or low power computer - i can lost horizontal so i write a case to correct that which work fine ,and as you can see in code below i use camera.applyQuaternion .
i would like to change way to keep horizontal by setting directly camera.matrix with camera.matrix.makeBasis(camera_axe_x_init,camera_axe_y_init,camera_axe_z_init);
but it doesnt work . It is like there is no update , dont understand what happen in this case .
question : how can i update direction of camera after i have directly setted her matrix ?
thank .
var camera_axe_z = new THREE.Vector3();
var camera_axe_y = new THREE.Vector3();
var camera_axe_x= new THREE.Vector3();
var camera_axe_x_plan=new THREE.Vector3();
var camera_axe_x_ortho=new THREE.Vector3();
var camera_axe_z_init=new THREE.Vector3();
var camera_x_origin = new THREE.Vector3(1,0,0);
var vec = new THREE.Vector3();
//rotation around camera_axe_x
var rotateX = new THREE.Quaternion();
//rotation around camera.up
var rotateZ = new THREE.Quaternion();
//rotation correction to get shoulder horizontal
var rotate_correction = new THREE.Quaternion();
var angle=0;
var angle_correction=0;
function onMouseMove( event ) {
if ( scope.isLocked === false ) return;
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
camera_axe_z.setFromMatrixColumn( camera.matrix, 2 );
camera_axe_y.setFromMatrixColumn(camera.matrix , 1 );
camera_axe_x.setFromMatrixColumn( camera.matrix, 0 );
angle = camera_axe_z.angleTo( camera.up );
var newAngle = angle - movementY*0.002;
if ( newAngle>0 && newAngle<Math.PI ) { rotateX.setFromAxisAngle(camera_axe_x,-movementY*0.002);
camera.applyQuaternion(rotateX);
}
rotateZ.setFromAxisAngle(camera.up,-movementX*0.002);
camera.applyQuaternion(rotateZ);
// scope.dispatchEvent( changeEvent );
// to keep shoulder horizontal
if( Math.abs(camera_axe_x.z) > 0.001 ){
console.log('problem');
console.log( camera_axe_x.x+":"+camera_axe_x.y+":"+camera_axe_x.z );
camera_axe_x_plan.set(camera_axe_x.x,camera_axe_x.y,0);
camera_axe_x_ortho.crossVectors(camera_axe_x,camera_axe_x_plan);
camera_axe_x_ortho.normalize();
angle_correction = camera_axe_x.angleTo( camera_axe_x_plan );
rotate_correction.setFromAxisAngle(camera_axe_x_ortho,angle_correction);
camera.applyQuaternion(rotate_correction);
console.log('correction made');
console.log( ' start control axe' );
camera_axe_z.setFromMatrixColumn( camera.matrix, 2 );
camera_axe_y.setFromMatrixColumn(camera.matrix , 1 );
camera_axe_x.setFromMatrixColumn( camera.matrix, 0 );
console.log( camera_axe_x.x+":"+camera_axe_x.y+":"+camera_axe_x.z );
console.log( camera_axe_y.x+":"+camera_axe_y.y+":"+camera_axe_y.z );
console.log( camera_axe_z.x+":"+camera_axe_z.y+":"+camera_axe_z.z );
console.log( ' end control axe' );
}
}