• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     using Super = IntroduceInterfaces;
29     META_IMPLEMENT_OBJECT_TYPE_INTERFACE(ClassId::CameraNode)
30     META_DEFINE_OBJECT_TYPE_INFO(CameraNode, ClassId::CameraNode)
31 public:
32     SCENE_USE_COMPONENT_PROPERTY(float, FoV, "CameraComponent")
33     SCENE_USE_COMPONENT_PROPERTY(float, AspectRatio, "CameraComponent")
34     SCENE_USE_COMPONENT_PROPERTY(float, NearPlane, "CameraComponent")
35     SCENE_USE_COMPONENT_PROPERTY(float, FarPlane, "CameraComponent")
36     SCENE_USE_COMPONENT_PROPERTY(float, XMagnification, "CameraComponent")
37     SCENE_USE_COMPONENT_PROPERTY(float, YMagnification, "CameraComponent")
38     SCENE_USE_COMPONENT_PROPERTY(float, XOffset, "CameraComponent")
39     SCENE_USE_COMPONENT_PROPERTY(float, YOffset, "CameraComponent")
40     SCENE_USE_COMPONENT_PROPERTY(SceneCameraProjection, Projection, "CameraComponent")
41     SCENE_USE_COMPONENT_PROPERTY(SceneCameraCulling, Culling, "CameraComponent")
42     SCENE_USE_COMPONENT_PROPERTY(SceneCameraPipeline, RenderingPipeline, "CameraComponent")
43     SCENE_USE_COMPONENT_PROPERTY(uint32_t, SceneFlags, "CameraComponent")
44     SCENE_USE_COMPONENT_PROPERTY(uint32_t, PipelineFlags, "CameraComponent")
45     SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Vec4, Viewport, "CameraComponent")
46     SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Vec4, Scissor, "CameraComponent")
47     SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::UVec2, RenderTargetSize, "CameraComponent")
48     SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Color, ClearColor, "CameraComponent")
49     SCENE_USE_COMPONENT_PROPERTY(float, ClearDepth, "CameraComponent")
50     SCENE_USE_COMPONENT_PROPERTY(IPostProcess::Ptr, PostProcess, "CameraComponent")
51     SCENE_USE_COMPONENT_PROPERTY(uint64_t, LayerMask, "CameraComponent")
52     SCENE_USE_COMPONENT_PROPERTY(ColorFormat, ColorTargetCustomization, "CameraComponent")
53     SCENE_USE_COMPONENT_PROPERTY(BASE_NS::Math::Mat4X4, CustomProjectionMatrix, "CameraComponent")
54 
55     Future<bool> SetActive(bool active = true) override;
56     bool IsActive() const override;
57     Future<bool> SetRenderTarget(const IRenderTarget::Ptr&) override;
58 
59     bool SetEcsObject(const IEcsObject::Ptr&) override;
60 public:
61     Future<NodeHits> CastRay(const BASE_NS::Math::Vec2& pos, const RayCastOptions& options) const override;
62     Future<BASE_NS::Math::Vec3> ScreenPositionToWorld(const BASE_NS::Math::Vec3& pos) const override;
63     Future<BASE_NS::Math::Vec3> WorldPositionToScreen(const BASE_NS::Math::Vec3& pos) const override;
64 
65 public:
66     bool Build(const META_NS::IMetadata::Ptr&) override;
67 
68     CORE_NS::Entity CreateEntity(const IInternalScene::Ptr& scene) override;
69 
70 private:
71     ICamera::Ptr camera_;
72 };
73 
74 SCENE_END_NAMESPACE()
75 
76 #endif