Sun, 26 Jan 2020 01:06:27 +0200
fix default angle
19 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2018 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #pragma once | |
20 | #include <QColor> | |
21 | #include <QOpenGLFunctions> | |
22 | #include <QGenericMatrix> | |
23 | #include "basics.h" | |
24 | #include "colors.h" | |
25 | #include "vertex.h" | |
26 | ||
27 | namespace gl | |
28 | { | |
29 | // Transformation matrices for projection cameras. | |
30 | static const QMatrix4x4 topCameraMatrix = {}; | |
31 | static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; | |
32 | static const QMatrix4x4 leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; | |
33 | static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; | |
34 | static const QMatrix4x4 backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; | |
35 | static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; | |
36 | ||
37 | // Conversion matrix from LDraw to OpenGL coordinates. | |
38 | static const QMatrix4x4 ldrawToGL = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; | |
39 | ||
40 | static constexpr QRgb BlackRgb = 0xff000000; | |
41 | static constexpr GLfloat near = 1.0f; | |
42 | static constexpr GLfloat far = 10000.0f; | |
43 | struct Polygon; | |
44 | } | |
45 | ||
46 | struct gl::Polygon | |
47 | { | |
48 | enum Type : qint8 | |
49 | { | |
50 | EdgeLine, | |
51 | Triangle, | |
52 | Quadrilateral, | |
53 | ConditionalEdge | |
54 | }; | |
55 | Type type; | |
56 | Point3D vertices[4]; | |
57 | Color color; | |
21 | 58 | linetypes::Id id; |
19 | 59 | |
60 | /** | |
61 | * @return amount of vertices used for geometry | |
62 | */ | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
63 | inline unsigned int numPolygonVertices() const |
19 | 64 | { |
65 | if (type == Type::ConditionalEdge) | |
66 | return 2; | |
67 | else | |
68 | return numVertices(); | |
69 | } | |
70 | ||
71 | /** | |
72 | * @return amount of vertices | |
73 | */ | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
74 | inline unsigned int numVertices() const |
19 | 75 | { |
76 | switch (type) | |
77 | { | |
78 | case Type::EdgeLine: | |
79 | return 2; | |
80 | case Type::Triangle: | |
81 | return 3; | |
82 | case Type::ConditionalEdge: | |
83 | case Type::Quadrilateral: | |
84 | return 4; | |
85 | } | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
86 | return 0; |
19 | 87 | } |
88 | }; | |
89 | ||
90 | Q_DECLARE_METATYPE(gl::Polygon) | |
91 | ||
92 | namespace gl | |
93 | { | |
21 | 94 | inline Polygon edgeLine(const Point3D& v_1, const Point3D& v_2, Color color, linetypes::Id id) |
19 | 95 | { |
21 | 96 | return {Polygon::EdgeLine, {v_1, v_2}, color, id}; |
19 | 97 | } |
98 | ||
21 | 99 | inline Polygon triangle( |
100 | const Point3D& v_1, | |
101 | const Point3D& v_2, | |
102 | const Point3D& v_3, | |
103 | Color color, | |
104 | linetypes::Id id) | |
19 | 105 | { |
21 | 106 | return {Polygon::Triangle, {v_1, v_2, v_3}, color, id}; |
19 | 107 | } |
108 | ||
109 | inline Polygon quadrilateral( | |
110 | const Point3D& v_1, | |
111 | const Point3D& v_2, | |
112 | const Point3D& v_3, | |
113 | const Point3D& v_4, | |
21 | 114 | Color color, |
115 | linetypes::Id id) | |
19 | 116 | { |
21 | 117 | return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id}; |
19 | 118 | } |
119 | ||
120 | inline Polygon conditionalEdge( | |
121 | const Point3D& v_1, | |
122 | const Point3D& v_2, | |
123 | const Point3D& control_1, | |
124 | const Point3D& control_2, | |
21 | 125 | Color color, |
126 | linetypes::Id id) | |
19 | 127 | { |
21 | 128 | return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id}; |
19 | 129 | } |
130 | ||
131 | // Vbo names | |
26 | 132 | enum class ArrayClass : std::uint8_t |
19 | 133 | { |
134 | Lines, | |
135 | Triangles, | |
136 | Quads, | |
137 | ConditionalLines | |
138 | }; | |
26 | 139 | constexpr ArrayClass ARRAY_CLASSES[] = {ArrayClass::Lines, ArrayClass::Triangles, ArrayClass::Quads, ArrayClass::ConditionalLines}; |
140 | constexpr int NUM_ARRAY_CLASSES = countof(ARRAY_CLASSES); | |
141 | constexpr int FLOATS_PER_VERTEX = 7; | |
19 | 142 | |
143 | // Types of vbo per object | |
21 | 144 | enum class VboSubclass : std::uint8_t |
19 | 145 | { |
26 | 146 | VertexData, |
147 | Normals | |
19 | 148 | }; |
26 | 149 | constexpr int numVboSubclasses = 2; |
19 | 150 | |
151 | // Amount of vbos overall | |
26 | 152 | constexpr int numVbos = gl::NUM_ARRAY_CLASSES * gl::numVboSubclasses; |
19 | 153 | |
154 | enum class RenderStyle | |
155 | { | |
156 | Normal, | |
157 | Wireframe, | |
158 | BfcRedGreen, | |
159 | RandomColors | |
160 | }; | |
26 | 161 | |
162 | inline void* offset(const int n) | |
163 | { | |
164 | return reinterpret_cast<void*>(n); | |
165 | } | |
19 | 166 | } |