1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef SCENE_SRC_NODE_CAMERA_NODE_H
17 #define SCENE_SRC_NODE_CAMERA_NODE_H
18
19 #include <scene/ext/intf_create_entity.h>
20 #include <scene/interface/intf_camera.h>
21 #include <scene/interface/intf_raycast.h>
22
23 #include "node.h"
24
SCENE_BEGIN_NAMESPACE()25 SCENE_BEGIN_NAMESPACE()
26
27 class CameraNode : public META_NS::IntroduceInterfaces<Node, ICamera, ICreateEntity, ICameraRayCast> {
28 META_OBJECT(CameraNode, SCENE_NS::ClassId::CameraNode, IntroduceInterfaces)
29
30 public:
31 META_BEGIN_STATIC_DATA()
32 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, FoV)
33 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, AspectRatio)
34 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, NearPlane)
35 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, FarPlane)
36 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, XMagnification)
37 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, YMagnification)
38 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, XOffset)
39 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, YOffset)
40 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, CameraProjection, Projection)
41 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, CameraCulling, Culling)
42 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, CameraPipeline, RenderingPipeline)
43 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, uint32_t, SceneFlags)
44 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, uint32_t, PipelineFlags)
45 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, BASE_NS::Math::Vec4, Viewport)
46 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, BASE_NS::Math::Vec4, Scissor)
47 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, BASE_NS::Math::UVec2, RenderTargetSize)
48 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, BASE_NS::Math::Vec4, ClearColor)
49 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, float, ClearDepth)
50 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, IPostProcess::Ptr, PostProcess)
51 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, uint64_t, LayerMask)
52 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, ColorFormat, ColorTargetCustomization)
53 META_STATIC_FORWARDED_PROPERTY_DATA(ICamera, BASE_NS::Math::Mat4X4, CustomProjectionMatrix)
54 META_END_STATIC_DATA()
55
56 SCENE_USE_COMPONENT_PROPERTY(float, FoV, "CameraComponent")
57 SCENE_USE_COMPONENT_PROPERTY(float, AspectRatio, "CameraComponent")
58 SCENE_USE_COMPONENT_PROPERTY(float, NearPlane, "CameraComponent")
59 SCENE_USE_COMPONENT_PROPERTY(float, FarPlane, "CameraComponent")
60 SCENE_USE_COMPONENT_PROPERTY(float, XMagnification, "CameraComponent")
61 SCENE_USE_COMPONENT_PROPERTY(float, YMagnification, "CameraComponent")
62 SCENE_USE_COMPONENT_PROPERTY(float, XOffset, "CameraComponent")
63 SCENE_USE_COMPONENT_PROPERTY(float, YOffset, "CameraComponent")
64 SCENE_USE_COMPONENT_PROPERTY(CameraProjection, Projection, "CameraComponent")
65 SCENE_USE_COMPONENT_PROPERTY(CameraCulling, Culling, "CameraComponent")
66 SCENE_USE_COMPONENT_PROPERTY(CameraPipeline, RenderingPipeline, "CameraComponent")
67 SCENE_USE_COMPONENT_PROPERTY(uint32_t, SceneFlags, "CameraComponent")
68 SCENE_USE_COMPONENT_PROPERTY(uint32_t, PipelineFlags, "CameraComponent")
69 SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Vec4, Viewport, "CameraComponent")
70 SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Vec4, Scissor, "CameraComponent")
71 SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::UVec2, RenderTargetSize, "CameraComponent")
72 SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Vec4, ClearColor, "CameraComponent")
73 SCENE_USE_COMPONENT_PROPERTY(float, ClearDepth, "CameraComponent")
74 SCENE_USE_COMPONENT_PROPERTY(IPostProcess::Ptr, PostProcess, "CameraComponent")
75 SCENE_USE_COMPONENT_PROPERTY(uint64_t, LayerMask, "CameraComponent")
76 SCENE_USE_COMPONENT_PROPERTY(ColorFormat, ColorTargetCustomization, "CameraComponent")
77 SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Mat4X4, CustomProjectionMatrix, "CameraComponent")
78
79 Future<bool> SetActive(bool active = true) override;
80 bool IsActive() const override;
81 Future<bool> SetRenderTarget(const IRenderTarget::Ptr&) override;
82
83 bool SetEcsObject(const IEcsObject::Ptr&) override;
84
85 void SendInputEvent(PointerEvent& event) override;
86
87 public:
88 Future<NodeHits> CastRay(const BASE_NS::Math::Vec2& pos, const RayCastOptions& options) const override;
89 Future<BASE_NS::Math::Vec3> ScreenPositionToWorld(const BASE_NS::Math::Vec3& pos) const override;
90 Future<BASE_NS::Math::Vec3> WorldPositionToScreen(const BASE_NS::Math::Vec3& pos) const override;
91
92 public:
93 bool Build(const META_NS::IMetadata::Ptr&) override;
94
95 CORE_NS::Entity CreateEntity(const IInternalScene::Ptr& scene) override;
96
97 private:
98 ICamera::Ptr camera_;
99 };
100
101 SCENE_END_NAMESPACE()
102
103 #endif
104