跳转至

5. 相机对象

相机

VRP相机主要功能是用来浏览场景,分为默认相机,跟随相机,地图相机和旋转相机。

跟随相机:在VR场景中,跟随相机是用来通过相机跟随目标物体(如车、人等)的移动来实现浏览场景。跟随相机的特点是相机和相机的目标点随着目标物体一起移动。

地图相机:在浏览VR场景时,地图相机可为当前场景的整个外貌提供一个全局鸟瞰视图。

旋转相机:在浏览VR场景时,有时候会需要锁定一个目标建筑物然后围绕这个建筑物体对其进行环绕浏览。这时,用户就需要在场景中创建一个旋转相机,利用旋转相机对建筑物进行环绕浏览。

属性列表

属性 属性名 类型 默认值/可选值 说明
启用为主相机 main boolean true、false 启用默认/跟随/地图/旋转相机为主相机。
启用 enabled boolean true、false 启用默认/跟随/地图/旋转相机。
视角 fieldOfView number 相机观察的视角的大小。视角越大,能看到的视野也越大,对应的焦距也越短。
近截面 nearClipPlane number 相机观察范围内最近的截面。
远截面 farClipPlane number 相机观察范围内最远的截面。
旋转物体 target string 可选择需要围绕其进行环绕浏览的物体。
旋转速度 rotationSpeed number 可设置相机旋转速度。
旋转轴 rotationAxis number 0、1、2 可选择旋转轴的方向。
0=X轴;1=Y轴;2=Z轴。

示例代码

    // 是否启用默认相机为主相机|main
    camera.main = true;
    // 修改视角|fieldOfView
    camera.fieldOfView = 150;
    // 修改近截面|nearClipPlane
    camera.nearClipPlane = 0.0005f;
    // 修改远截面|farClipPlane
    camera.farClipPlane = 1000;

示例案例

    // 1-默认相机
    DefaultCamera_Demo() {
        // 获取默认相机
        Actor camera_actor = VrpCoreScene.SceneManager.singleton.Find("Camera");
        // 获取默认相机组件
        CameraComponent camera = camera_actor.GetComponent<CameraComponent>();
        // 修改默认相机属性的位置/旋转/缩放
        camera_actor.localPosition = new Vector3(0, 0, -15f);
        camera_actor.localEulerAngles = Vector3.zero;
        camera_actor.localScale = new Vector3(1, 1, 1);
        // 是否启用默认相机为主相机|main
        camera.main = true;
        // 修改视角|fieldOfView
        camera.fieldOfView = 150;
        // 修改近截面|nearClipPlane
        camera.nearClipPlane = 0.0005f;
        // 修改远截面|farClipPlane
        camera.farClipPlane = 1000;
    }

    // 2-跟随相机
    FollowCamera_Demo() {
        // 获取跟随相机
        Actor followcamera_actor = VrpCoreScene.SceneManager.singleton.Find("Follow Camera");
        // 获取跟随相机组件
        FollowCamera followcamera = followcamera_actor.GetComponent<FollowCamera>();
        // 修改跟随相机属性的位置/旋转/缩放
        followcamera_actor.localPosition = Vector3.zero;
        followcamera_actor.localEulerAngles = new Vector3(20, 1, 0);
        followcamera_actor.localScale = Vector3.one;
        // 获取默认相机组件
        CameraComponent default_followcamera = followcamera_actor.GetComponent<CameraComponent>();
        // 是否启用跟随相机为主相机|main
        default_followcamera.main = true;
        // 是否启用跟随相机|enabled
        followcamera.enabled = true;
        // 选择跟随物体|target  
        followcamera.target = "Box";
    }

    // 3-地图相机
    MapCamera_Demo() {
        // 获取地图相机
        Actor mapcamera_actor = VrpCoreScene.SceneManager.singleton.Find("Map Camera");
        // 获取地图相机组件
        MapCamera mapcamera = mapcamera_actor.GetComponent<MapCamera>();
        // 获取默认相机组件
        CameraComponent default_mapcamera = mapcamera_actor.GetComponent<CameraComponent>();
        // 是否启用地图相机为主相机|main
        default_mapcamera.main = true;
        // 是否启用地图相机|enabled
        mapcamera.enabled = true;
    }

    // 4-旋转相机
    RotateCamera_Demo() {
        // 获取旋转相机
        Actor rotatecamera_actor = VrpCoreScene.SceneManager.singleton.Find("Rotate Camera");
        // 获取旋转相机组件
        RotateCamera rotatecamera = rotatecamera_actor.GetComponent<RotateCamera>();
        // 获取默认相机组件
        CameraComponent default_rotatecamera = rotatecamera_actor.GetComponent<CameraComponent>();
        // 修改相机属性的位置/旋转/缩放
        rotatecamera_actor.localPosition = new Vector3(0, -0.2f, 0);
        rotatecamera_actor.localEulerAngles = new Vector3(10, 0, 0);
        rotatecamera_actor.localScale = Vector3.one;
        // 是否启用旋转相机为主相机|main
        default_rotatecamera.main = true;
        // 选择旋转物体|target  
        rotatecamera.target = "Box";
        // 修改旋转速度|rotationSpeed
        rotatecamera.rotationSpeed = 13;
        // 修改旋转轴|rotationAxis   
        rotatecamera.rotationAxis = 0;
    }