载入中...
搜索中...
未找到
SceneLinks.cpp
浏览该文件的文档.
1// Registers the scene link kinds backed by graphics: 2D and 3D renderables and
2// the 3D camera.
3//
4// The world-matrix decomposition used to live in scene/TransformSystem.cpp,
5// which forced scene to include graphics. Keeping it here puts the casts where
6// the types are complete and lets scene stay unaware of what it is driving.
7
8#include "common/ECS.h"
12#include "scene/SceneHost.h"
13#include "scene/SceneLink.h"
14
15#include <cmath>
16#include <glm/gtc/matrix_transform.hpp>
17#include <glm/gtc/quaternion.hpp>
18
19namespace eve::graphics {
20namespace {
21
24
25void pushRenderable3D(const SceneNode &n, void *target) {
26 auto *r = static_cast<Renderable3D *>(target);
27 // Borrow only for this synchronous update; no structural mutations or
28 // callbacks occur while the component is in use.
29 auto *t = r->transform().operator->();
30 const glm::mat4 &w = n.world;
31 t->linkedWorld = w;
32 t->hasLinkedWorld = true;
33 t->x = w[3][0];
34 t->y = w[3][1];
35 t->z = w[3][2];
36
37 glm::vec3 c0(w[0]);
38 glm::vec3 c1(w[1]);
39 glm::vec3 c2(w[2]);
40 t->sx = glm::length(c0);
41 t->sy = glm::length(c1);
42 t->sz = glm::length(c2);
43 if (t->sx > 1e-8f) c0 /= t->sx;
44 if (t->sy > 1e-8f) c1 /= t->sy;
45 if (t->sz > 1e-8f) c2 /= t->sz;
46
47 glm::mat3 rot(c0, c1, c2);
48 // Must invert the order modelFromTransform() recomposes (see TransformEuler.h).
49 eve::eulerYxzFromMatrix(glm::mat4(rot), t->yaw, t->pitch, t->roll);
50
51 r->meshRenderer()->visible = n.visible;
52}
53
54void pushRenderable2D(const SceneNode &n, void *target) {
55 auto *r = static_cast<Renderable2D *>(target);
56 auto t = r->transform();
57 const glm::mat4 &w = n.world;
58 t->x = w[3][0];
59 t->y = w[3][1];
60
61 glm::vec3 c0(w[0]);
62 glm::vec3 c1(w[1]);
63 t->sx = glm::length(c0);
64 t->sy = glm::length(c1);
65 if (t->sx > 1e-8f) c0 /= t->sx;
66 // 2D rotation from first column in XY
67 t->rot = std::atan2(c0.y, c0.x);
68
69 r->sprite()->visible = n.visible;
70}
71
72void pushCamera3D(const SceneNode &n, void *target) {
73 auto *c = static_cast<Camera3D *>(target);
74 c->setEye(n.world[3][0], n.world[3][1], n.world[3][2]);
75}
76
78template <class T>
79bool entityAlive(const void *target) {
80 return ecs::is_entity_visible(static_cast<const ecs::Entity *>(static_cast<const T *>(target)));
81}
82
83struct Register {
84 Register() {
86 {"renderable2d", &pushRenderable2D, nullptr, &entityAlive<Renderable2D>});
88 {"renderable3d", &pushRenderable3D, nullptr, &entityAlive<Renderable3D>});
90 {"camera3d", &pushCamera3D, nullptr, &entityAlive<Camera3D>});
91 }
92} g_register;
93
94} // namespace
95} // namespace eve::graphics
LogicalId target
float w
Definition AnimClip.cpp:738
glm::vec3 n
Definition Grass.cpp:63
double r
std::int32_t c
float t
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
int registerLinkKind(const LinkOps &ops)
Registers link kind.
void eulerYxzFromMatrix(const glm::mat< 4, 4, T, glm::defaultp > &m, T &yaw, T &pitch, T &roll)
Yaw/pitch/roll for the engine's transform order T * Ry * Rx * Rz * S.
LinkOps public API.
Definition SceneLink.h:28
Retained scene node (arena). Conceptual GameObject; isomorphic to eve::ui::UINode.
Definition SceneHost.h:46