简体   繁体   中英

Move camera to sides and rotate it [Autodesk forge viewer]

I'm trying to move the camera to left, right, backward and forward and to rotate it left and right.

This is what I tried for rotation:

function onRotateLeftButtonClicked(event) {
    event.preventDefault();
    var target = viewer.navigation.getTarget();
    var q = new THREE.Quaternion();
    q.setFromAxisAngle(new THREE.Vector3(0, 0, 1), 0.1);

    target.applyQuaternion(q);
    viewer.navigation.setTarget(target);
    orientUp();
}

Move left:

function onLeftButtonClicked(event) {
    event.preventDefault();
    _camera.translateX(-1);
    orientUp();
}

Foward:

function onForwardButtonClicked(event) {
    event.preventDefault();
    _camera.translateZ(-1);
    orientUp();
}

But this only works sometimes and other times the rotation is completely messed up and left and right rotate along the z axis and forward and backward is flipping the camera 180 degrees along the z axis.

So how are you supposed to control the camera like this?

PS: I do this in first person view.

Notes the opposite directions are obviously symmetric. _camera is viewer.getCamera() .

It looks in each of your manipulation of camera, navigation.setView is not called? In the other thread, camera manipulation is also discussed: Controlling camera in Forge viewer

In the thread,our colleague Cyrille mentioned about the sample he produced , in which camera of a mobile works well for VR. you can find the related code at: https://github.com/cyrillef/google-cardboard-vr/blob/2015c7e9c653422d1c466ff129dc1d503f8218c0/www/js/VRTool.js

I also mentioned a small sample I produced, where I manipulated the camera by mobile . The related codes https://github.com/xiaodongliang/Forge-Viewer-Mobile-Sensor/blob/master/www/main-js/MobileGyro.js

Could you check if these would help a bit for your problem? If it does not work, could you provide a small sample of your code project? you can contact us by emailing forge.help@autodesk.com if there is any private data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM