1

I'm trying to control the camera in the Autodesk Forge Viewer. Setting target and position seems to work fine, but if I try to set rotation or quaternion it do not have any effect.

To get the camera I use the getCamera function and then applyCamera after I have tried to set the parameters.

What I'm trying to achieve is to use the device orientation on a handheld device to rotate the model. Just using alpha and beta to set target is not a smooth experience.

// get camera
var cam = _viewer.getCamera();

// get position
var vecPos = cam.position;

// get view vector
var vecViewDir = new THREE.Vector3();
vecViewDir.subVectors(cam.target,cam.position);

// get length of view vector
var length = vecViewDir.length();

// rotate alpha
var vec = new THREE.Vector3();
vec.y = length;
var zAxis = new THREE.Vector3(0,0,1);
vec.applyAxisAngle(zAxis,THREE.Math.degToRad(alpha));

// rotate beta
var vec2 = new THREE.Vector3(vec.x,vec.y,vec.z);
vec2.normalize();
vec2.negate();
vec2.cross(zAxis);
vec.applyAxisAngle(vec2,THREE.Math.degToRad(beta) + Math.PI / 2);

// add to camera
cam.target.addVectors(vecPos,vec);
_viewer.applyCamera(cam,false);
2
  • Hi, last year, I did an experiment to drive camera of Viewer by mobile device. This is a blog about it. forge.autodesk.com/cloud_and_mobile/2016/11/… . I simply copied some Viewer3D.js code to rotate the camera. could you take a look if it could help a bit? If not, could you provide some code snippet you have played for us to investigate? Commented Feb 22, 2017 at 4:45
  • Hi. I have added a code snippet of what I first tried to my qestion. I also tried to change my code using quaternion, but it is still not good. The alpha and beta values from my device is very "jumpy". If run with simulated device orientation in Chrome it looks good. Commented Feb 22, 2017 at 14:00

1 Answer 1

4

You need to use the setView() method

_viewer.navigation.setView (pos, target) ;

and may also need to set the up vector to make sure you orient the camera the way you want.

_viewer.navigation.setCameraUpVector (upVector) ;
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried that, but the result is the same. Looks like the euler angles from a real device don't behave like the simulated ones in Chrome. You can test a simple example here: deviceorientationtest.azurewebsites.net
I can take a closer look to your code but I already have a sample posted here vr.autodesk.io - source code: github.com/cyrillef/google-cardboard-vr - let me know if that does not help, and I'll take a debut it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.