在三维建模中,相机是必不可少的元素。相机模拟了观众的眼睛,只有摆放在合适的位置才能看到对应角度的模型。
在Qt 3D中提供了Camera QML Type来创建相机。
它具有如下属性:
- aspectRatio : real – 相机纵横比
- farPlane : real – 远平面
- fieldOfView : real – 视野
- nearPlane : real – 近裁剪面
- position : vector3d – 相机初始位置
- projectionMatrix : matrix4x4 – 相机的当前投影矩阵
- projectionType : enumeration – 相机投影的类型
- CameraLens.OrthographicProjection – 正交投影
- CameraLens.PerspectiveProjection – 透视投影
- CameraLens.FrustumProjection – 截锥投影
- CameraLens.CustomProjection – 设置自定义的投影矩阵
- right : real
- top : real
- left : real
- bottom : real
- upVector : vector3d – 相机朝上的方向
- viewCenter : vector3d – 焦点矩阵
- viewVector : vector3d – 投影方向向量
由Qt官网给出的例子,可以得到创建相机时需要设置的主要参数,这样便可以声明一个简单的相机,注意相机需要创建在场景根实体(Entity)中,然后创建场景根实体的部件(components),而在此根实体的基础上,又可以创建需要渲染的实体。官网例子代码片段如下所示:
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0
import QtQuick 2.0 as QQ2
Entity {
id: sceneRoot
// 相机参数设置
Camera {
id: camera
projectionType: CameraLens.<