载入中...
搜索中...
未找到
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"
11#include "scene/SceneHost.h"
12#include "scene/SceneLink.h"
13
14#include <cmath>
15#include <glm/gtc/matrix_transform.hpp>
16#include <glm/gtc/quaternion.hpp>
17
18namespace eve::graphics {
19namespace {
20
23
24void pushRenderable3D(const SceneNode &n, void *target) {
25 auto *r = static_cast<Renderable3D *>(target);
26 auto t = r->transform();
27 const glm::mat4 &w = n.world;
28 t->x = w[3][0];
29 t->y = w[3][1];
30 t->z = w[3][2];
31
32 glm::vec3 c0(w[0]);
33 glm::vec3 c1(w[1]);
34 glm::vec3 c2(w[2]);
35 t->sx = glm::length(c0);
36 t->sy = glm::length(c1);
37 t->sz = glm::length(c2);
38 if (t->sx > 1e-8f) c0 /= t->sx;
39 if (t->sy > 1e-8f) c1 /= t->sy;
40 if (t->sz > 1e-8f) c2 /= t->sz;
41
42 glm::mat3 rot(c0, c1, c2);
43 glm::quat q = glm::quat_cast(rot);
44 glm::vec3 euler = glm::eulerAngles(q); // pitch(x), yaw(y), roll(z)
45 t->pitch = euler.x;
46 t->yaw = euler.y;
47 t->roll = euler.z;
48
49 r->meshRenderer()->visible = n.visible;
50}
51
52void pushRenderable2D(const SceneNode &n, void *target) {
53 auto *r = static_cast<Renderable2D *>(target);
54 auto t = r->transform();
55 const glm::mat4 &w = n.world;
56 t->x = w[3][0];
57 t->y = w[3][1];
58
59 glm::vec3 c0(w[0]);
60 glm::vec3 c1(w[1]);
61 t->sx = glm::length(c0);
62 t->sy = glm::length(c1);
63 if (t->sx > 1e-8f) c0 /= t->sx;
64 // 2D rotation from first column in XY
65 t->rot = std::atan2(c0.y, c0.x);
66
67 r->sprite()->visible = n.visible;
68}
69
70void pushCamera3D(const SceneNode &n, void *target) {
71 auto *c = static_cast<Camera3D *>(target);
72 c->setEye(n.world[3][0], n.world[3][1], n.world[3][2]);
73}
74
76template <class T>
77bool entityAlive(const void *target) {
78 return ecs::is_entity_visible(static_cast<const ecs::Entity *>(static_cast<const T *>(target)));
79}
80
81struct Register {
82 Register() {
84 {"renderable2d", &pushRenderable2D, nullptr, &entityAlive<Renderable2D>});
86 {"renderable3d", &pushRenderable3D, nullptr, &entityAlive<Renderable3D>});
88 {"camera3d", &pushCamera3D, nullptr, &entityAlive<Camera3D>});
89 }
90} g_register;
91
92} // namespace
93} // namespace eve::graphics
glm::vec3 n
Definition Grass.cpp:64
int w
uint32_t c
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition AnimTrail.h:6
int registerLinkKind(const LinkOps &ops)
Definition SceneLink.cpp:27
Retained scene node (arena). Conceptual GameObject; isomorphic to eve::ui::UINode.
Definition SceneHost.h:39