-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimitives.h
79 lines (57 loc) · 1.7 KB
/
Primitives.h
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
//
// Created by jeff2310 on 4/19/18.
//
#ifndef VKSOFTWARERENDER_PRIMITIVES_H
#define VKSOFTWARERENDER_PRIMITIVES_H
#include "MathUtility.h"
#include "ShaderVariables.h"
#include "VirtualDevice.h"
#include <vector>
namespace VkRenderer {
// primitives
class Vertex {
public:
Vector pos;
TextureCoordinate texCoord;
Color color;
Vector normal;
PhongVariables shaderVariables;
Vertex() : texCoord(), shaderVariables() {}
Vertex(const Vector &_pos, const TextureCoordinate &_texCoord, const Color &_color,
const Vector &_normal, const PhongVariables &_shaderVariables) :
pos(_pos), texCoord(_texCoord),
color(_color), normal(_normal),
shaderVariables(_shaderVariables) {}
};
struct Line {
// 注意, Line的p1在下 p2在上
Vertex p1, p2;
Line() : p1(), p2() {}
Line(const Vertex &_p1, const Vertex &_p2) : p1(_p1), p2(_p2) {}
};
struct Triangle {
Vertex p1, p2, p3;
};
// 分割用的子三角形
struct SubTriangle {
float top, bottom;
Line left, right;
};
class Mesh {
private:
std::vector<Vertex> vertices;
std::vector<Triangle> faces;
int vertexCount;
public:
Mesh();
Mesh(const Mesh &m);
int count();
void addVertex(const Vertex &v);
void build();
void render(VirtualDevice &device);
};
Mesh createCube(float length, const Color *colors);
Mesh createSphere(float radius, float angle_step);
Vertex interp(const Vertex &v1, const Vertex &v2, float t);
}
#endif //VKSOFTWARERENDER_PRIMITIVES_H