哪些参数负责摄像机的位置及其角度?

时间:2012-08-08 12:54:06

标签: web webgl three.js vtk

我尝试将在服务器上呈现的图片与在Web客户端呈现的边界框连接起来。 我在web-client上使用极地系统,所以当天使phi超过90时,camera.Up从(0,1,0)变为(0,-1,0),但当我将这些选项设置为Vtk相机时它正常工作直到矢量Up变为(0,-1,0)之后,服务器上的摄像头开始工作,就像网络客户端一样,如果没有相机的变化。上传真。

这里有一些代码示例:

JS:

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;


            if (phi<0)  phi=2*180+phi;
            if (phi>2*180)  phi=phi-2*180;
        if (theta>2*180)    theta=theta-2*180;
        if (theta<-2*180)   theta=theta+2*180;
            if ((phi>180/2)&&(phi<3*180/2))
                camera.up.y=-1;
            else
                camera.up.y=1;


            camera.lookAt(new THREE.Vector3(0,0,0));

            //trace('data_move');trace(FocalPoint);trace(camera.up);    
        trace('data_move');trace(camera.position);trace(camera.up); 
            camera.updateMatrix();

        $('#info').html('<div>Up.X:'+camera.up.x+' Up.Y:'+camera.up.y+' Up.Z:'+camera.up.z+'</div><div>X:'+camera.position.x+' Y:'+camera.position.y+' Z:'+camera.position.z+'</div><div>Phi:'+phi+' Theta:'+theta+' Radious:'+radious+'</div><div>'+FocalPoint+'</div>')

        });
        renderer.domElement.addEventListener('mousedown', function(e) {
            paused = false;
            lastLeft = e.clientX;
            lastTop = e.clientY;
            onMouseDownTheta = theta;
            onMouseDownPhi = phi;
             //$('#vtkPic').show();
        });
        renderer.domElement.addEventListener('mouseup', function(e) {
            moving = paused = true;
            counter = 0
            trace('data_move');trace(camera.position);trace(camera.up); 
        //$('#vtkPic').hide();
        if(camera.up.y == 1)
            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()

            self.renderer.ResetCameraClippingRange()
            self.renderer.ResetCamera()   

我解决了这个问题,但知道绕Y

旋转有问题

enter image description here

0 个答案:

没有答案