Greetings, esteemed community members,
For the past few days, I have been struggling with an issue related to updating the View Matrix (4x4) of my camera. This update is crucial for positioning objects within an AR-Scene created using three.js.
The custom matrix contains data from Direct Sparse Odometry (DSO), which is retrieved as a string via the WebView's JavaScript interface. This string provides information about my current pose and needs to be converted into a 4x4 matrix. However, when attempting to set:
- the matrixWorldInverse or ViewMatrix, no updates occur even after using the common update functions
- the projectionMatrix causes the scene to zoom in and out without any actual movement or rotation. It seems to only affect certain characteristics?
Is there another method to adjust the camera's position and orientation within the scene?
Despite trying various update functions provided by three.js like Matrix.set() or fromArray(), there has been no change in the outcome.
Thank you in advance!
var renderer, scene, camera, box, geometry, material, poseMatrix;
init();
animate();
render();
function init() {
// Setting up the renderer
renderer = new THREE.WebGLRenderer({
canvas: document.getElementById("mCanvas"),
alpha: true
});
renderer.setClearColor(0xffffff, 0);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Initializing the scene
scene = new THREE.Scene();
// Creating the camera
camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
1,
1000
);
scene.add(camera);
scene.add(new THREE.AxesHelper(100));
placeBox();
initPose();
}
function render() {
renderer.render(scene, camera);
}
function placeBox()
{
// Using a test object which needs to have an absolute position in world coordinates
geometry = new THREE.BoxBufferGeometry(3, 5, 3 );
material = new THREE.MeshLambertMaterial({color: 0xfece46, wireframe: true, wireframeLinewidth: 3.1});
box = new THREE.Mesh(geometry, material);
// Positioning the box in global coordinates
box.position.set(0, 0, -10);
scene.add(box);
}
function animate() {
setCurrentPose();
renderer.render(scene, camera);
}
function initPose(){
// Default value provided by DSO
var mTmpPose = "1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1"; //initial point of DSO
var mDefaultPose = mTmpPose.split(',');
// Applying DSO Standard Pose 4x4 Matrix
camera.matrixAutoUpdate = false;
camera.matrixWorldInverse.fromArray(mDefaultPose);
camera.updateWorldMatrix();
//camera.updateProjectionMatrix(); <- does not work
//camera.updateMatrix(); <- same issue
}
function setCurrentPose(){
//Acquiring a string with current pose values
var tmp = Android.getCurrentPose(); // example: 0.8953773, 0.39648485, 0.20272951, 0.0,
// -0.3792577, 0.44037524, 0.81377715, 0.0,
// 0.23337325,-0.8055243, 0.5446719, 0.0,
// . -2.5238492, 13.470952, 0.715593, 1.0
var pose = tmp[0].split(',');
camera.matrixWorldInverse.fromArray(pose);
// camera.projectionMatrix.fromArray(pose);
camera.updateWorldMatrix();
// camera.updateProjectionMatrix(); <- does not work
// camera.updateMatrix(); <- same issue
}