载入中...
搜索中...
未找到
ScenePicking.cpp
浏览该文件的文档.
1// Provides the scene camera projection capability.
2//
3// scene/Scene.cpp used to implement pickScreenAt / collectFrustumIdsAt, which
4// forced scene (L1) to include graphics headers (L3) -- an upward dependency.
5// The camera math those entry points need (screen ray, clip matrix) is still
6// graphics' business, but defining scene's members here also made scene's own
7// object files reference a symbol only graphics defines, which a per-layer DLL
8// split cannot link. So scene keeps the entry points and this file provides
9// ISceneCameraProjection instead; scene queries it through common/Capability.h.
10//
11// The file is excluded from the build when scene is disabled (same rule as
12// SceneLinks.cpp), so graphics keeps working without scene.
13
14#include "graphics/ClipSpace.h"
17
18#include "common/Capability.h"
19
20#include <glm/gtc/matrix_transform.hpp>
21
22#include <optional>
23
24namespace eve::graphics {
25namespace {
26
27class CameraProjection final : public eve::scene::ISceneCameraProjection {
28public:
29 std::optional<eve::scene::ScreenRay> screenRay(Camera3D &cam, float screenX, float screenY, float viewW,
30 float viewH) const override {
31 cam.screenToRay(screenX, screenY, viewW, viewH);
33 ray.origin = {cam.getScreenRayOriginX(), cam.getScreenRayOriginY(), cam.getScreenRayOriginZ()};
34 ray.direction = {cam.getScreenRayDirX(), cam.getScreenRayDirY(), cam.getScreenRayDirZ()};
35 return ray;
36 }
37
38 std::optional<eve::scene::CameraClip> clipForViewport(Camera3D &cam, float viewW, float viewH) const override {
39 if (!(viewW > 0.f) || !(viewH > 0.f)) return std::nullopt;
40 auto d = cam.data();
41 const glm::mat4 view =
42 glm::lookAtRH(glm::vec3(d->eyeX, d->eyeY, d->eyeZ), glm::vec3(d->targetX, d->targetY, d->targetZ),
43 glm::vec3(d->upX, d->upY, d->upZ));
44 const glm::mat4 projection = graphics::cameraProjectionVulkanRH_ZO(
45 d->orthographic, glm::radians(d->fovYDeg), d->orthoHeight, viewW / viewH, d->nearZ, d->farZ);
47 clip.clip = projection * view;
48 clip.inverse = glm::inverse(clip.clip);
49 return clip;
50 }
51};
52
53CameraProjection g_cameraProjection;
54
55// A static registrar, like the link-kind registration right next door in
56// SceneLinks.cpp: the picking entry points must work for callers that build a
57// Camera3D without constructing the Graphics module (test/scene.cpp does), and
58// the adapter holds no state, so there is nothing to tear down.
59struct RegisterCameraProjection {
60 RegisterCameraProjection() { eve::cap::provide<eve::scene::ISceneCameraProjection>(&g_cameraProjection); }
61} g_registerCameraProjection;
62
63} // namespace
64} // namespace eve::graphics
glm::vec4 clip
float d
glm::mat4 view
Camera projection queries answered by the module that owns Camera3D.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
glm::mat4 cameraProjectionVulkanRH_ZO(bool orthographic, float fovyRad, float orthoHeight, float aspect, float zNear, float zFar)
Camera projection shared by rendering, picking, and diagnostic passes.
Definition ClipSpace.h:38
Camera view-projection matrix and its inverse for one viewport.
World-space ray through one screen pixel.