forked from Simple-XX/SimpleGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertex.hpp
More file actions
80 lines (63 loc) · 2.63 KB
/
Copy pathvertex.hpp
File metadata and controls
80 lines (63 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef SIMPLERENDER_SRC_INCLUDE_VERTEX_HPP_
#define SIMPLERENDER_SRC_INCLUDE_VERTEX_HPP_
#include <math.hpp>
#include "color.h"
namespace simple_renderer {
class Vertex {
public:
// Default constructor
// 默认构造函数
Vertex() = default;
// Copy constructor
// 拷贝构造函数
Vertex(const Vertex& vertex) = default;
// Copy assignment operator
// 拷贝赋值操作符
Vertex& operator=(const Vertex& vertex) = default;
// Move constructor
// 移动构造函数
Vertex(Vertex&& vertex) = default;
// Move assignment operator
// 移动赋值操作符
Vertex& operator=(Vertex&& vertex) = default;
// Destructor
// 析构函数
~Vertex() = default;
// Constructor with parameters 带参数的构造函数
explicit Vertex(const Vector4f& pos, const Vector3f& norm,
const Vector2f& tex, const Color& color_)
: position_(pos), normal_(norm), texCoords_(tex), color_(color_),
clip_position_(pos), has_clip_position_(false) {}
// 扩展构造函数:包含裁剪空间坐标
explicit Vertex(const Vector4f& pos, const Vector3f& norm,
const Vector2f& tex, const Color& color_,
const Vector4f& clip_pos)
: position_(pos), normal_(norm), texCoords_(tex), color_(color_),
clip_position_(clip_pos), has_clip_position_(true) {}
// Transform the vertex with a matrix 使用矩阵变换顶点
void transform(const Matrix4f& matrix) { position_ = matrix * position_; }
// Getter functions
// 获取函数
[[nodiscard]] inline Vector4f GetPosition() const { return position_; }
[[nodiscard]] inline Vector3f GetNormal() const { return normal_; }
[[nodiscard]] inline Vector2f GetTexCoords() const { return texCoords_; }
[[nodiscard]] inline Color GetColor() const { return color_; }
// 扩展坐标访问
[[nodiscard]] inline Vector4f GetClipPosition() const { return clip_position_; }
[[nodiscard]] inline bool HasClipPosition() const { return has_clip_position_; }
private:
Vector4f position_; // 3D position, 3D顶点坐标
Vector3f normal_; // Normal vector, 顶点法向量
Vector2f texCoords_; // Texture coordinates, 顶点纹理坐标
Color color_;
// 扩展坐标用于裁剪优化
Vector4f clip_position_; // 裁剪空间坐标 (用于视锥体裁剪)
bool has_clip_position_; // 是否包含裁剪坐标
};
inline Vertex operator*(const Matrix4f& matrix, const Vertex& vertex) {
return Vertex(matrix * vertex.GetPosition(),
Matrix3f(matrix) * vertex.GetNormal(), vertex.GetTexCoords(),
vertex.GetColor());
}
} // namespace simple_renderer
#endif