src/gl/common.h

changeset 33
4c41bfe2ec6e
parent 26
3a9e761e4faa
child 34
1de2b8d64e9f
equal deleted inserted replaced
32:767592024ec5 33:4c41bfe2ec6e
20 #include <QColor> 20 #include <QColor>
21 #include <QOpenGLFunctions> 21 #include <QOpenGLFunctions>
22 #include <QGenericMatrix> 22 #include <QGenericMatrix>
23 #include "basics.h" 23 #include "basics.h"
24 #include "colors.h" 24 #include "colors.h"
25 #include "vertex.h"
26 25
27 namespace gl 26 namespace gl
28 { 27 {
29 // Transformation matrices for projection cameras. 28 // Transformation matrices for projection cameras.
30 static const QMatrix4x4 topCameraMatrix = {}; 29 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}; 30 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}; 31 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}; 32 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}; 33 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}; 34 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; 35 static constexpr QRgb BlackRgb = 0xff000000;
41 static constexpr GLfloat near = 1.0f;
42 static constexpr GLfloat far = 10000.0f;
43 struct Polygon; 36 struct Polygon;
44 } 37 }
45 38
46 struct gl::Polygon 39 struct gl::Polygon
47 { 40 {
51 Triangle, 44 Triangle,
52 Quadrilateral, 45 Quadrilateral,
53 ConditionalEdge 46 ConditionalEdge
54 }; 47 };
55 Type type; 48 Type type;
56 Point3D vertices[4]; 49 glm::vec3 vertices[4];
57 Color color; 50 Color color;
58 linetypes::Id id; 51 linetypes::Id id;
59 52
60 /** 53 /**
61 * @return amount of vertices used for geometry 54 * @return amount of vertices used for geometry
89 82
90 Q_DECLARE_METATYPE(gl::Polygon) 83 Q_DECLARE_METATYPE(gl::Polygon)
91 84
92 namespace gl 85 namespace gl
93 { 86 {
94 inline Polygon edgeLine(const Point3D& v_1, const Point3D& v_2, Color color, linetypes::Id id) 87 inline Polygon edgeLine(const glm::vec3& v_1, const glm::vec3& v_2, Color color, linetypes::Id id)
95 { 88 {
96 return {Polygon::EdgeLine, {v_1, v_2}, color, id}; 89 return {Polygon::EdgeLine, {v_1, v_2}, color, id};
97 } 90 }
98 91
99 inline Polygon triangle( 92 inline Polygon triangle(
100 const Point3D& v_1, 93 const glm::vec3& v_1,
101 const Point3D& v_2, 94 const glm::vec3& v_2,
102 const Point3D& v_3, 95 const glm::vec3& v_3,
103 Color color, 96 Color color,
104 linetypes::Id id) 97 linetypes::Id id)
105 { 98 {
106 return {Polygon::Triangle, {v_1, v_2, v_3}, color, id}; 99 return {Polygon::Triangle, {v_1, v_2, v_3}, color, id};
107 } 100 }
108 101
109 inline Polygon quadrilateral( 102 inline Polygon quadrilateral(
110 const Point3D& v_1, 103 const glm::vec3& v_1,
111 const Point3D& v_2, 104 const glm::vec3& v_2,
112 const Point3D& v_3, 105 const glm::vec3& v_3,
113 const Point3D& v_4, 106 const glm::vec3& v_4,
114 Color color, 107 Color color,
115 linetypes::Id id) 108 linetypes::Id id)
116 { 109 {
117 return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id}; 110 return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id};
118 } 111 }
119 112
120 inline Polygon conditionalEdge( 113 inline Polygon conditionalEdge(
121 const Point3D& v_1, 114 const glm::vec3& v_1,
122 const Point3D& v_2, 115 const glm::vec3& v_2,
123 const Point3D& control_1, 116 const glm::vec3& control_1,
124 const Point3D& control_2, 117 const glm::vec3& control_2,
125 Color color, 118 Color color,
126 linetypes::Id id) 119 linetypes::Id id)
127 { 120 {
128 return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id}; 121 return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id};
129 } 122 }

mercurial