在Forge Viewer中控制相机 [英] Controlling camera in Forge viewer

查看:297
本文介绍了在Forge Viewer中控制相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Autodesk Forge Viewer中控制相机.设置目标和位置似乎可以正常工作,但是如果我尝试设置旋转或四元数,则没有任何效果.

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.

要获取相机,请使用getCamera函数,然后在尝试设置参数后应用applyCamera.

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

我想要实现的是使用手持设备上的设备方向来旋转模型.仅使用alpha和beta来设置目标并不是一种流畅的体验.

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);

推荐答案

您需要使用setView()方法

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) ;

这篇关于在Forge Viewer中控制相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆