目录

Camera

Class Info

class Camera : public IComponent

相机类,主要提供相机的位置、投影类型、视场角、近裁平面、远裁平面的设置和获取。

Public Constructor Summary

Constructor Name

Camera(SceneObject* sceneObject = nullptr)

构造函数。

Public Destructor Summary

Destructor Name

virtual ~Camera()

析构函数。

Public Method Summary

Qualifier and Type

Method Name and Description

virtual void

Start() override

初始化相机的视锥体。

virtual void

Update(f32 deltaTime) override

更新相机视口、投影矩阵、视图矩阵和视锥体。

void

SetProjectionType(ProjectionType projectionType)

设置相机投影类型。

void

SetPerspective(f32 fov, f32 aspectRatio, f32 zNear, f32 zFar)

设置视场角、宽高比、相机距近裁平面距离、相机距远裁平面距离。

void

SetOrthogonal(f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar)

设置相机正交投影参数。

void

SetZNear(f32 zNear)

设置相机到近裁平面的距离。

void

SetZFar(f32 zFar)

设置相机到远裁平面的距离。

void

SetFOV(f32 fov)

设置视场角。

void

SetViewport(u32 x, u32 y, u32 width, u32 height, f32 minDepth = 0.0f, f32 maxDepth = 1.0f)

设置视口。

void

SetEyePos(const Vector3& eyePos)

设置相机位置。

void

SetTarget(const Vector3& targetPos)

设置相机目标位置。

void

SetPreRotation(const Matrix4& preRotation)

设置相机旋转角度。

const Frustum*

GetFrustum() const

获取相机的视锥体。

const Matrix4&

GetProjectionMatrix() const

获取相机投影矩阵。

const Matrix4&

GetViewMatrix() const

获取相机视图矩阵。

ProjectionType

GetProjectionType() const

获取相机投影类型,如正投影、透视投影。

f32

GetAspectRatio() const

获取宽高比。

f32

GetFOV() const

获取视场角。

f32

GetZNear() const

获取相机到近裁平面的距离。

f32

GetZFar() const

获取相机到远裁平面的距离。

f32

GetLeft() const

获取相机距左边界平面距离。

f32

GetRight() const

获取相机距右边界平面距离。

f32

GetBottom() const

获取相机距下边界平面距离。

f32

GetTop() const

获取相机距上边界平面距离。

const Vector3&

GetEyePos() const

获取相机位置。

const Vector3&

GetTarget() const

获取相机移动的目标位置。

const Vector3&

GetLookDir() const

获取相机的向前方向向量。

const Vector3&

GetUpDir() const

获取相机的向上方向向量。

const Vector3&

GetRightDir() const

获取相机的向右方向向量。

void

SetMainCamera(bool bMain)

设置相机是否为主相机。

bool

IsMainCamera() const

判断相机是否为主相机。

u32

GetLayerMask() const

获取相机的渲染对象类型掩码。

void

SetLayerMask(u32 layerMask)

设置相机的渲染对象类型掩码。

void

SetRenderingPath(RenderingPathType type, RenderTargetType targetType =RenderTargetType::FROM_SWAPCHAIN)

设置相机的渲染路径以及渲染目标类型。

const Viewport&

GetViewPort() const

获取相机的渲染视口。

virtual void

PostUpdate(f32 deltaTime) override

更新相机的资源裁剪信息以及渲染路径。

void

Resize(u32 width, u32 height)

重置相机渲染目标的宽度和高度。

virtual void

Render()

执行相机渲染流程。

void

Pause()

暂停相机渲染流程操作。

void

Resume()

恢复相机渲染流程操作。

void

SetScreenRatio(const Vector4& ratio)

设置相机占据屏幕位置的比例。

RenderTargetType

GetRenderTargetType() const

获取渲染目标的类型。

virtual void

SetMultiSampleInfo(const MultiSampleInfo& sampleInfo)

设置多重采样抗锯齿参数。

const MultiSampleInfo&

GetMultiSampleInfo() const

获取多重采样抗锯齿参数。

void

SetClearColor(const Color& color)

设置清屏色参数。

const RenderingPath*

GetRenderingPath() const

获取相机的渲染路径。

template <typename T> T*

AddPostProcess()

添加后处理到camera,并返回已添加的后处理的指针变量。

template <typename T> void

RemovePostProcess()

删除某个已添加的后处理。

Public Constructors

[h2]Camera

Constructor

Camera(SceneObject* sceneObject = nullptr)

构造函数。

Parameters

Name

Description

sceneObject

指定初始化的场景对象。

Public Destructors

[h2]~Camera

Destructor

virtual ~Camera()

析构函数。

Public Methods

[h2]Start

Method

virtual void Start() override

初始化相机的视锥体。

[h2]Update

Method

virtual void Update(f32 deltaTime) override

更新相机视口、投影矩阵、视图矩阵和视锥体。

Parameters

Name

Description

deltaTime

帧间隔时间,单位为秒。

[h2]SetProjectionType

Method

void SetProjectionType(ProjectionType projectionType)

设置相机投影类型。

Parameters

Name

Description

projectionType

ProjectionType枚举值,如正投影、透视投影。

[h2]SetPerspective

Method

void SetPerspective(f32 fov, f32 aspectRatio, f32 zNear, f32 zFar)

设置透视相机的视场角、宽高比、相机距近裁平面距离、相机距远裁平面距离。

Parameters

Name

Description

fov

视场角。

aspectRatio

宽高比。

zNear

相机距近裁平面距离。

zFar

相机距远裁平面距离。

[h2]SetOrthogonal

Method

void SetOrthogonal(f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar)

设置相机正交投影参数。

Parameters

Name

Description

left

相机距左边界平面距离。

right

相机距右边界平面距离。

bottom

相机距下边界平面距离。

top

相机距上边界平面距离。

zNear

相机距近边界平面距离。

zFar

相机距远边界平面距离。

[h2]SetFOV

Method

void SetFOV(f32 fov)

设置视场角。

Parameters

Name

Description

fov

待设置视场角,非弧度,fov指垂直视场角度。

[h2]SetViewport

Method

void SetViewport(u32 x, u32 y, u32 width, u32 height, f32 minDepth = 0.0f, f32 maxDepth = 1.0f)

设置视口。

Parameters

Name

Description

x

视口左上角X坐标。

y

视口左上角Y坐标。

width

视口宽度。

height

视口高度。

minDepth

视口最小深度,默认值为0.0f。

maxDepth

视口最大深度,默认值为1.0f。

[h2]SetZNear

Method

void SetZNear(f32 zNear)

设置相机到近裁平面的距离。

Parameters

Name

Description

zNear

相机到近裁平面的距离。

[h2]SetZFar

Method

void SetZFar(f32 zFar)

设置相机到远裁平面的距离。

Parameters

Name

Description

zFar

相机到远裁平面的距离。

[h2]SetEyePos

Method

void SetEyePos(const Vector3& eyePos)

设置相机位置。

Parameters

Name

Description

eyePos

相机位置。

[h2]SetTarget

Method

void SetTarget(const Vector3& targetPos)

设置相机目标位置。

Parameters

Name

Description

targetPos

相机目标位置。

[h2]SetPreRotation

Method

void SetPreRotation(const Matrix4& preRotation)

设置相机旋转角度。

Parameters

Name

Description

preRotation

相机角度。

[h2]GetFrustum

Method

const Frustum* GetFrustum() const

获取相机的视锥体。

Returns

Type

Description

const Frustum*

返回相机视锥体对象引用。

[h2]GetProjectionMatrix

Method

const Matrix4& GetProjectionMatrix() const

获取相机投影矩阵。

Returns

Type

Description

const Matrix4&

返回相机投影矩阵。

[h2]GetViewMatrix

Method

const Matrix4& GetViewMatrix() const

获取相机视图矩阵。

Returns

Type

Description

const Matrix4&

返回相机视图矩阵。

[h2]GetProjectionType

Method

ProjectionType GetProjectionType() const

获取相机投影类型,如正投影、透视投影。

Returns

Type

Description

ProjectionType

返回相机投影类型,如正投影、透视投影。

[h2]GetAspectRatio

Method

f32 GetAspectRatio() const

获取宽高比。

Returns

Type

Description

f32

返回宽高比。

[h2]GetFOV

Method

f32 GetFOV() const

获取视场角(指垂直视场角度),非弧度。

Returns

Type

Description

f32

返回相机的视场角。

[h2]GetZNear

Method

f32 GetZNear() const

获取相机到近裁平面的距离。

Returns

Type

Description

f32

返回相机到近裁平面的距离。

[h2]GetZFar

Method

f32 GetZFar() const

获取相机到远裁平面的距离。

Returns

Type

Description

f32

返回相机到远裁平面的距离。

[h2]GetLeft

Method

f32 GetLeft() const

获取相机距左边界平面距离。

Returns

Type

Description

f32

返回相机距左边界平面距离。

[h2]GetRight

Method

f32 GetRight const

获取相机距右边界平面距离。

Returns

Type

Description

f32

返回相机距右边界平面距离。

[h2]GetBottom

Method

f32 GetBottom() const

获取相机距下边界平面距离。

Returns

Type

Description

f32

返回相机距下边界平面距离。

[h2]GetTop

Method

f32 GetTop() const

获取相机距上边界平面距离。

Returns

Type

Description

f32

返回相机距上边界平面距离。

[h2]GetEyePos

Method

const Vector3& GetEyePos() const

获取相机位置。

Returns

Type

Description

const Vector3&

返回相机位置。

[h2]GetTarget

Method

const Vector3& GetTarget() const

获取相机移动的目标位置。

Returns

Type

Description

const Vector3&

返回相机移动的目标位置。

[h2]GetLookDir

Method

const Vector3& GetLookDir() const

获取相机的向前方向向量。

Returns

Type

Description

const Vector3&

返回相机的向前方向向量。

[h2]GetUpDir

Method

const Vector3& GetUpDir() const

获取相机的向上方向向量。

Returns

Type

Description

const Vector3&

返回相机的向上方向向量。

[h2]GetRightDir

Method

const Vector3& GetRightDir() const

获取相机的向右方向向量。

Returns

Type

Description

const Vector3&

返回相机的向右方向向量。

[h2]SetMainCamera

Method

void SetMainCamera(bool bMain)

设置相机是否为主相机。

Parameters

Name

Description

bMain

设置相机是否为主相机。

  • true:是。
  • false:不是。

[h2]IsMainCamera

Method

bool IsMainCamera() const

判断相机是否为主相机。

Returns

Type

Description

bool

  • true:是主相机。
  • false:不是主相机。

[h2]GetLayerMask

Method

u32 GetLayerMask() const

获取相机的渲染对象类型掩码。

Returns

Type

Description

u32

返回相机的渲染对象类型掩码,以位域形式表示,具体请参见LayerType。

[h2]SetLayerMask

Method

void SetLayerMask(u32 layerMask)

设置相机的渲染对象类型掩码。

Parameters

Name

Description

layerMask

相机的渲染对象类型掩码,以位域形式表示,掩码值请参考LayerType。例如要渲染天空盒和几何体类型的场景对象,调用方式为: SetLayerMask(LAYER_TYPE_GEOMETRY | LAYER_TYPE_SKYBOX)。

[h2]SetRenderingPath

Method

void SetRenderingPath(RenderingPathType type, RenderTargetType targetType = RenderTargetType::FROM_SWAPCHAIN)

设置相机的渲染路径以及渲染目标类型。

Parameters

Name

Description

type

渲染路径,具体请参见RenderingPathType。

targetType

渲染目标类型,默认值为FROM_SWAPCHAIN,具体请参见RenderTargetType。

[h2]GetViewPort

Method

const Viewport& GetViewPort() const

获取相机的渲染视口。

Returns

Type

Description

const Viewport&

返回Viewport类型的相机渲染视口指针。

[h2]PostUpdate

Method

virtual void PostUpdate(f32 deltaTime) override

更新相机的资源裁剪信息以及渲染路径。

Parameters

Name

Description

deltaTime

帧间隔时间,单位为秒。

[h2]Resize

Method

void Resize(u32 width, u32 height)

重置相机渲染目标的宽度和高度。

Parameters

Name

Description

width

视口宽度。

height

视口高度。

[h2]Render

Method

virtual void Render()

执行相机渲染流程。

[h2]Pause

Method

void Pause()

暂停相机渲染流程操作。

[h2]Resume

Method

void Resume()

恢复相机渲染流程操作。

[h2]SetScreenRatio

Method

void SetScreenRatio(const Vector4& ratio)

设置相机占据屏幕位置的比例。

Parameters

Name

Description

ratio

Vector4类型相机渲染目标在屏幕上的起始点与终点位置信息。

[h2]GetRenderTargetType

Method

RenderTargetType GetRenderTargetType() const

获取渲染目标的类型。

Returns

Type

Description

RenderTargetType

返回RenderTargetType类型的渲染目标的类型。

[h2]SetMultiSampleInfo

Method

virtual void SetMultiSampleInfo(const MultiSampleInfo& sampleInfo)

设置多重采样抗锯齿参数。

Parameters

Name

Description

sampleInfo

多重采样抗锯齿参数。

[h2]GetMultiSampleInfo

Method

const MultiSampleInfo& GetMultiSampleInfo() const

获取多重采样抗锯齿参数。

Returns

Type

Description

MultiSampleInfo

返回多重采样抗锯齿参数。

[h2]SetClearColor

Method

void SetClearColor(const Color& color)

设置清屏色参数。

Parameters

Name

Description

color

清屏色参数。

[h2]GetRenderingPath

Method

const RenderingPath* GetRenderingPath() const

获取相机的渲染路径。

Returns

Type

Description

RenderingPath*

返回相机的渲染路径。

[h2]AddPostProcess

Method

template <typename T> T* AddPostProcess()

添加后处理到camera,并返回已添加的后处理的指针变量。

Returns

Type

Description

template <typename T> T*

返回已添加到相机的后处理指针变量。

[h2]RemovePostProcess

Method

template <typename T> void RemovePostProcess()

删除某个已添加后处理。