-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlandscape.h
More file actions
205 lines (146 loc) · 5.49 KB
/
landscape.h
File metadata and controls
205 lines (146 loc) · 5.49 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef LANDSCAPE_H
#define LANDSCAPE_H
#include <functional>
#include <iostream>
// Qt includes
#include <QString>
#include <QVector>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QPair>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include "Model3D/node.h"
#include "Model3D/material.h"
#include "Model3D/vertexdata.h"
#include "transformational.h"
#include "landscapesculpttool.h"
#include "Model3D/material.h"
#include <QOpenGLTexture>
struct Border2D {
Border2D() :
IsValid(false)
{
}
Border2D(QVector2D topLeft, QVector2D topRight,
QVector2D downLeft, QVector2D downRight) :
TopLeft(topLeft), TopRight(topRight),
DownLeft(downLeft), DownRight(downRight),
IsValid(true)
{
}
Border2D& operator *=(uint value) {
TopLeft *= value;
TopRight *= value;
DownLeft *= value;
DownRight *= value;
return *this;
}
QVector2D TopLeft;
QVector2D TopRight;
QVector2D DownLeft;
QVector2D DownRight;
bool IsValid;
};
struct IndexBorder2D {
IndexBorder2D() :
IsValid(false)
{
}
IndexBorder2D(int topLeft, int downLeft, int topRight, int downRight) :
TopLeft(topLeft), DownLeft(downLeft),
TopRight(topRight), DownRight(downRight),
IsValid(true)
{
}
int TopLeft;
int DownLeft;
int TopRight;
int DownRight;
bool IsValid;
};
class LandscapeManager;
//using Mfunc = std::func
//using MFunc = QVector4D (LandscapeManager::*MFunc)(); // MFunc - тип указателя
class Landscape : public Transformational
{
public:
using Mfunc = std::function<QVector4D()>;
Landscape(uint width, uint height, uint blockSize, Mfunc generateId);
~Landscape();
struct PrimitivePointPositions {
QVector3D pointA;
QVector3D pointB;
QVector3D pointC;
};
// Transformational interface
public:
void rotate(const QQuaternion &rotation) override;
void translate(const QVector3D &translation) override;
void scale(const float scaleKoef) override;
void setGlobalTransform(const QMatrix4x4 &matrix) override;
void draw(QOpenGLShaderProgram *programm, QOpenGLFunctions *functions) override;
void objectPicking(QOpenGLShaderProgram *programm, QOpenGLFunctions *functions) override;
QVector3D getPosition() const override;
PrimitivePointPositions getTrianglePointGlobalPositions(
int triangleId, QMatrix4x4 projectionMatrix);
void addTexture(aiTextureType type, QOpenGLTexture *image);
void calculateNormals();
void resetBuffers();
void setSculptToolUsage(bool isLandscapeSculptToolUse);
void refreshByLandscapeTool();
void refreshByLandscapeTool(QVector2D center, float size);
private:
void clear();
void fillIndexes(uint width, uint height);
void fillVertexes(uint width, uint height, uint blockSize, Mfunc generateId);
void fillTextureCoords(uint width, uint height);
bool isCircleIntersectsLandscape(QVector2D circleCenter, float circleRadius);
int getShiftedIndexForPointOnBorderIntersects(int index); // If point is located on intersects function return new index for vector (which is not located on intersects)
// Otherwise function return -1
QVector3D getNormalByFaceIndex(uint index) const;
QVector3D calculateNormalByIndex(uint index) const;
IndexBorder2D getIndexBorderForToolBySize(QVector2D toolCenter, float size);
QPair<int, int> getStartAndXIndexes(const IndexBorder2D & border,
const QVector2D & toolCenter, float circleRadius) const;
uint getIndexByShiftFromCenter(int x, int y) const;
struct InformationForUpdate {
InformationForUpdate(QVector2D toolCenter, float toolRadius, int rowLength) :
ToolCenter(toolCenter), ToolRadius(toolRadius), RowLength(rowLength), CanUpdate(false)
{
}
int RowLength;
float ToolRadius;
QVector2D ToolCenter;
int StartIndex;
int CurrentIndex;
int PrevIndex;
IndexBorder2D IndexBorder;
uint LandscapeDownLeftIndex;
QVector<uint> IndexesForUpdateVertexes;
QVector<uint> IndexForUpdateNormalsOnIntersects;
bool IsNeedToCheckBorderIntersects;
bool CanUpdate;
bool statusNoErr = true;
};
void prepareInfoForUpdateOuterRing(InformationForUpdate & info);
void prepareInfoForUpdateInnerCircle(InformationForUpdate & info);
QVector<uint> getCircleDownSide(InformationForUpdate info);
QVector<uint> getCircleTopSide(InformationForUpdate info);
void updateVertexPositions(const QVector<uint> & side, const QVector<uint> & interiorSide, float toolStrength);
void updateVertexesNormals(const QVector<uint> & side);
void findAndUpdateVertexesOnBorderIntersects(InformationForUpdate const &info);
QPair<int, int> getBordersOnIntersects(const InformationForUpdate & info,
int low, int high, int step);
Material m_landscapeMaterial;
QOpenGLBuffer m_indexBuffer;
QOpenGLBuffer m_vertexBuffer;
QVector<VertexData> m_vertexes;
QVector<uint> m_indexes;
int m_width, m_length; // width - X. length - Z
uint m_blockSize;
QVector3D m_translate = QVector3D(0, 0, 0);
bool m_isSculpToolUse = false;
};
#endif // LANDSCAPE_H