xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
mobject.hpp
浏览该文件的文档.
1
11#pragma once
12#include <xcal/public.h>
13
14#include <memory>
19#include <xcmath/xcmath.hpp>
20
23
24namespace xcal::mobject {
25
32// class XCAL_API MObject : public AbsMObject {
33// public:
34// using vec4 = xcmath::vec4<float_t>; ///< 4维向量类型
35// using vec3 = xcmath::vec3<float_t>; ///< 3维向量类型
36// using mat4 = xcmath::mat4<float_t>; ///< 4x4矩阵类型
37// using mat3 = xcmath::mat3<float_t>; ///< 3x3矩阵类型
38// using mat2 = xcmath::mat3<
39// float_t>; ///< 2x2矩阵类型(注意:当前使用mat3,可能需要修正)
40
41// private:
42// virtual Type type_() const = 0;
43
44// private:
45// property::Position pos_{0.0, 0.0}; ///< 对象位置属性
46// property::Color stroke_color_{0.0, 0.0, 0.0, 1.0}; ///< 描边颜色属性
47// property::Color fill_color_{0.0, 0.0, 0.0, 1.0}; ///< 填充颜色属性
48// property::Scalar stroke_width_{1.0}; ///< 描边宽度属性
49// property::Scalar scale_x_{1.0}; ///< X轴缩放属性
50// property::Scalar scale_y_{1.0}; ///< Y轴缩放属性
51// property::Scalar rotation_{0.0}; ///< 旋转角度属性
52// property::Scalar depth_{0.0}; ///< 深度属性
53
54// public:
55// /**
56// * @brief 默认构造函数
57// * @note 使用默认位置 {0, 0} 初始化
58// */
59// MObject() : MObject({0, 0}) {};
60
61// /**
62// * @brief 带位置参数的构造函数
63// * @param pos 初始位置
64// */
65// MObject(const property::Position::data_t& pos) : AbsMObject(), pos_(pos)
66// {
67// register_properties(pos_, stroke_color_, fill_color_, stroke_width_,
68// scale_x_, scale_y_, rotation_, depth_);
69// }
70
71// const property::Position& pos() const { return pos_; }
72// property::Position& pos() { return pos_; }
73// const property::Color& stroke_color() const { return stroke_color_; }
74// property::Color& stroke_color() { return stroke_color_; }
75// const property::Color& fill_color() const { return fill_color_; }
76// property::Color& fill_color() { return fill_color_; }
77// const property::Scalar& stroke_width() const { return stroke_width_; }
78// property::Scalar& stroke_width() { return stroke_width_; }
79// const property::Scalar& scale_x() const { return scale_x_; }
80// property::Scalar& scale_x() { return scale_x_; }
81// const property::Scalar& scale_y() const { return scale_y_; }
82// property::Scalar& scale_y() { return scale_y_; }
83// const property::Scalar& rotation() const { return rotation_; }
84// property::Scalar& rotation() { return rotation_; }
85// const property::Scalar& depth() const { return depth_; }
86// property::Scalar& depth() { return depth_; }
87
88// MObject* set_pos(const property::Position::data_t& pos) {
89// pos_ = pos;
90// return this;
91// }
92// MObject* set_stroke_color(const property::Color::data_t& color) {
93// stroke_color_ = color;
94// return this;
95// }
96// MObject* set_fill_color(const property::Color::data_t& color) {
97// fill_color_ = color;
98// return this;
99// }
100// MObject* set_stroke_width(float_t width) {
101// stroke_width_ = width;
102// return this;
103// }
104// MObject* set_scale(float_t sx, float_t sy) {
105// scale_x_ = sx;
106// scale_y_ = sy;
107// return this;
108// }
109// MObject* set_rotation(float_t angle) {
110// rotation_ = angle;
111// return this;
112// }
113// MObject* set_depth(float_t depth) {
114// depth_ = depth;
115// return this;
116// }
117// MObject* translate(float_t x, float_t y) {
118// pos_.x() += x;
119// pos_.y() += y;
120// return this;
121// }
122// MObject* translate(const std::array<float_t, 2>& pos) {
123// pos_.x() += pos[0];
124// pos_.y() += pos[1];
125// return this;
126// }
127
128// MObject* rotate(float_t angle) {
129// rotation_ += angle;
130// return this;
131// }
132// MObject* scale(float_t x, float_t y) {
133// scale_x_ *= x;
134// scale_y_ *= y;
135// return this;
136// }
137
138// MObject* scale(const float_t& scale) {
139// scale_x_ *= scale;
140// scale_y_ *= scale;
141// return this;
142// }
143
144// vec4 local_to_global(const vec4& local) const {
145// if (rotation_ == 0.0 && scale_x_ == 1.0 && scale_y_ == 1.0)
146// return local + vec4(pos_.value().xy(), 0.0, 0.0);
147// else if (scale_x_ == 1.0 && scale_y_ == 1.0) {
148// return xcmath::translate(
149// xcmath::rotate(mat4::eye(), rotation_.value(),
150// {0.0f, 0.0f, 1.0f}),
151// vec3{pos_.value(), 0.0f}) ^
152// local;
153// }
154// return xcmath::translate(
155// xcmath::rotate(xcmath::scale(xcmath::mat4<float_t>::eye(),
156// {scale_x_.value(),
157// scale_y_.value(), 1.0f}),
158// rotation_.value(), {0.0f, 0.0f, 1.0f}),
159// vec3{pos_.value(), 0.0f}) ^
160// local;
161// }
162// vec4 global_to_local(const vec4& global) const {
163// if (rotation_ == 0.0 && scale_x_ == 1.0 && scale_y_ == 1.0) {
164// return global - vec4(pos_.value().xy(), 0.0, 0.0);
165// }
166// // Apply inverse transformations in reverse order
167// if (scale_x_ == 1.0 && scale_y_ == 1.0) {
168// return xcmath::rotate(xcmath::translate(mat4::eye(),
169// vec3{-pos_.value(),
170// 0.0f}),
171// -rotation_.value(), {0.0f, 0.0f, 1.0f}) ^
172// global;
173// }
174// return xcmath::scale(
175// xcmath::rotate(xcmath::translate(mat4::eye(),
176// vec3{-pos_.value(),
177// 0.0f}),
178// -rotation_.value(), {0.0f, 0.0f, 1.0f}),
179// {1.0f / scale_x_.value(), 1.0f / scale_y_.value(), 1.0f})
180// ^
181// global;
182// }
183// virtual ~MObject() = default;
184// };
185
186// using mobject_ptr = std::unique_ptr<mobject::MObject>;
187} // namespace xcal::mobject
抽象图形对象基类
Header file for mathematical functions
N-dimensional mathematical vector implementation with template metaprogramming support