我正在开发一个 Web 应用程序,该应用程序允许您从服务器向客户端发送使用 VTK 制作的图片。但是你怎么知道互联网的速度取决于速度,嗯,文件系统。为了加快工作速度,我决定在客户端添加 webGL。现在问题出现在数据同步中。在VTK中围绕物体旋转相机,经过多次尝试,我无法在客户端做,相机工作良好(随着相机坐标的变化),但能够正确旋转物体。在此有一些问题: 1. 对相机有什么想法吗?2.或者在vtk中改变旋转很容易?
更新:
我制作了一个相机,它与 vtk 同步,但知道我的 viewUp 向量有问题,在客户端上,当 phi 上升超过 90 后,它变成了 (0,-1,0),当我制作 SetViewUp(0,-1,0 ) 没有改变
Javascript:
renderer.domElement.addEventListener('mousemove', function(e) {
e.preventDefault();
if ( paused ) {
return;
}
if ( !moving ) {
lastLeft = e.clientX;
lastTop = e.clientY;
moving = true;
}
// horizontal
theta = - ( ( event.clientX - lastLeft ) * 360 /window.innerWidth ) + onMouseDownTheta;
phi = ( ( event.clientY - lastTop ) * 360 /window.innerHeight ) + onMouseDownPhi;
//phi = Math.min( 90, Math.max( -90, phi ) );
var cosPhi = Math.cos( phi * Math.PI / 180 );
var sinPhi = Math.sin( phi * Math.PI / 180 );
var sinTheta = Math.sin( theta * Math.PI / 180 );
var cosTheta = Math.cos( theta * Math.PI / 180 );
//trace('data_move');trace(radious);trace(theta);trace(phi);trace(camera.up);
camera.position.x = radious * cosTheta * cosPhi;
camera.position.y = radious * sinPhi;
camera.position.z = radious * sinTheta * cosPhi;
var u;
if (phi<0) phi=2*180+phi;
if (phi>2*180) phi=phi-2*180;
if ((phi>180/2)&&(phi<3*180/2))
u=-1;
else
u=1;
camera.up = new THREE.Vector3(0, u, 0);
camera.lookAt(new THREE.Vector3(FocalPoint[0],FocalPoint[1],FocalPoint[2]))
trace('data_move');trace(FocalPoint);trace(camera.up);
camera.updateMatrix();
});
renderer.domElement.addEventListener('mousedown', function(e) {
paused = false;
lastLeft = e.clientX;
lastTop = e.clientY;
onMouseDownTheta = theta;
onMouseDownPhi = phi;
});
renderer.domElement.addEventListener('mouseup', function(e) {
moving = paused = true;
counter = 0
trace('data_move');trace(camera.position);trace(camera.up);
comm.makeRequest("vtk", {
mode: curVtkConf.mode,
command: "set_camera",
up: {'x': camera.up.x,'y': camera.up.y,'z': camera.up.z},
position: {'x': camera.position.x,'y': camera.position.y,'z': camera.position.z},
});
});
飞腾:
def set_camera(self, position, up):
'''
Поворот в жестко заданную позицию.
'''
self.move_to_origin()
bounds = self.src_actor.GetBounds()
camera = self.renderer.GetActiveCamera()
x, y, z = camera.GetPosition()
edge = None
camera.SetPosition(position['x'], position['y'], position['z'])
camera.SetViewUp(up['x'], up['y'], up['z'])
self.world_coords_to_pixel_ratio = self._get_world_coords_to_pixel_ratio()
camera.OrthogonalizeViewUp()
camera.SetRoll(0)
self.renderer.ResetCameraClippingRange()
self.renderer.ResetCamera()
更新2:
现在我也有一些旋转问题。模型只是在旋转时改变了它的大小