|
@@ -4,72 +4,100 @@ UGEEntityCube::UGEEntityCube(QObject *parent)
|
4
|
4
|
: UGEEntity(parent)
|
5
|
5
|
, _size(1.0)
|
6
|
6
|
{
|
|
7
|
+ updateFaces();
|
|
8
|
+ connect(this, SIGNAL(colorChanged()), this, SLOT(updateFaces()));
|
|
9
|
+ connect(this, SIGNAL(sizeChanged()), this, SLOT(updateFaces()));
|
|
10
|
+ connect(this, SIGNAL(textureChanged()), this, SLOT(updateFaces()));
|
7
|
11
|
}
|
8
|
12
|
|
9
|
|
-float UGEEntityCube::getSize() const
|
|
13
|
+double UGEEntityCube::getSize() const
|
10
|
14
|
{
|
11
|
15
|
return _size;
|
12
|
16
|
}
|
13
|
17
|
|
14
|
18
|
void UGEEntityCube::draw(AbstractRenderDevice *device)
|
15
|
19
|
{
|
16
|
|
- float r = _size / 2;
|
17
|
|
- if (_textureId.isNull()) {
|
18
|
|
- QColor color = Qt::red;
|
19
|
|
- QList<ColorVector3D> points;
|
20
|
|
- points << ColorVector3D(color, -r, -r, r) << ColorVector3D(color, -r, r, r)
|
21
|
|
- << ColorVector3D(color, r, r, r) << ColorVector3D(color, r, -r, r)
|
22
|
|
- << ColorVector3D(color, -r, -r, -r) << ColorVector3D(color, -r, r, -r)
|
23
|
|
- << ColorVector3D(color, r, r, -r) << ColorVector3D(color, r, -r, -r);
|
24
|
|
- drawPolygon(device, QList<ColorVector3D>() << points[3] << points[2] << points[1] << points[0]);
|
25
|
|
- drawPolygon(device, QList<ColorVector3D>() << points[2] << points[3] << points[7] << points[6]);
|
26
|
|
- drawPolygon(device, QList<ColorVector3D>() << points[6] << points[7] << points[4] << points[5]);
|
27
|
|
- drawPolygon(device, QList<ColorVector3D>() << points[5] << points[4] << points[0] << points[1]);
|
28
|
|
- drawPolygon(device, QList<ColorVector3D>() << points[1] << points[2] << points[6] << points[5]);
|
29
|
|
- drawPolygon(device, QList<ColorVector3D>() << points[4] << points[7] << points[3] << points[0]);
|
|
20
|
+ if (!_facesColor.empty()) {
|
|
21
|
+ for (int i = 0; i < _facesColor.size(); ++i) {
|
|
22
|
+ drawPolygon(device, _facesColor[i]);
|
|
23
|
+ }
|
30
|
24
|
}
|
31
|
25
|
else {
|
32
|
|
- QColor color = Qt::white;
|
33
|
|
- drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), color, r, -r, r)
|
34
|
|
- << TextureVector3D(Vector2D(0.25, 0.25), color, r, r, r)
|
35
|
|
- << TextureVector3D(Vector2D(0.00, 0.25), color, -r, r, r)
|
36
|
|
- << TextureVector3D(Vector2D(0.00, 0.50), color, -r, -r, r), _textureId);
|
37
|
|
- drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), color, r, r, r)
|
38
|
|
- << TextureVector3D(Vector2D(0.25, 0.25), color, r, -r, r)
|
39
|
|
- << TextureVector3D(Vector2D(0.50, 0.25), color, r, -r, -r)
|
40
|
|
- << TextureVector3D(Vector2D(0.50, 0.50), color, r, r, -r), _textureId);
|
41
|
|
- drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.25), color, r, r, -r)
|
42
|
|
- << TextureVector3D(Vector2D(0.50, 0.50), color, r, -r, -r)
|
43
|
|
- << TextureVector3D(Vector2D(0.75, 0.50), color, -r, -r, -r)
|
44
|
|
- << TextureVector3D(Vector2D(0.75, 0.25), color, -r, r, -r), _textureId);
|
45
|
|
- drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.75, 0.25), color, -r, r, -r)
|
46
|
|
- << TextureVector3D(Vector2D(0.75, 0.50), color, -r, -r, -r)
|
47
|
|
- << TextureVector3D(Vector2D(1.00, 0.50), color, -r, -r, r)
|
48
|
|
- << TextureVector3D(Vector2D(1.00, 0.25), color, -r, r, r), _textureId);
|
49
|
|
- drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.00), color, -r, r, r)
|
50
|
|
- << TextureVector3D(Vector2D(0.25, 0.25), color, r, r, r)
|
51
|
|
- << TextureVector3D(Vector2D(0.50, 0.25), color, r, r, -r)
|
52
|
|
- << TextureVector3D(Vector2D(0.50, 0.00), color, -r, r, -r), _textureId);
|
53
|
|
- drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.75), color, -r, -r, -r)
|
54
|
|
- << TextureVector3D(Vector2D(0.50, 0.50), color, r, -r, -r)
|
55
|
|
- << TextureVector3D(Vector2D(0.25, 0.5), color, r, -r, r)
|
56
|
|
- << TextureVector3D(Vector2D(0.25, 0.75), color, -r, -r, r), _textureId);
|
|
26
|
+ for (int i = 0; i < _facesTexture.size(); ++i) {
|
|
27
|
+ drawPolygonTexture(device, _facesTexture[i], _textureId);
|
|
28
|
+ }
|
57
|
29
|
}
|
58
|
30
|
}
|
59
|
31
|
|
60
|
|
-QVariant UGEEntityCube::getTextureId() const
|
|
32
|
+void UGEEntityCube::setSize(double size)
|
61
|
33
|
{
|
62
|
|
- return _textureId;
|
|
34
|
+ _size = size;
|
|
35
|
+ emit sizeChanged();
|
|
36
|
+ emit sizeChanged(_size);
|
63
|
37
|
}
|
64
|
38
|
|
65
|
|
-void UGEEntityCube::setSize(float size)
|
|
39
|
+void UGEEntityCube::increaseSize(double size)
|
66
|
40
|
{
|
67
|
|
- _size = size;
|
|
41
|
+ _size += size;
|
|
42
|
+ emit sizeChanged();
|
|
43
|
+ emit sizeChanged(_size);
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+QVariant UGEEntityCube::getTextureId() const
|
|
47
|
+{
|
|
48
|
+ return _textureId;
|
68
|
49
|
}
|
69
|
50
|
|
70
|
51
|
void UGEEntityCube::setTextureId(const QVariant &textureId)
|
71
|
52
|
{
|
72
|
53
|
_textureId = textureId;
|
|
54
|
+ setColor(Qt::white);
|
|
55
|
+ emit textureChanged();
|
|
56
|
+ emit textureChanged(_textureId);
|
73
|
57
|
}
|
74
|
58
|
|
75
|
|
-
|
|
59
|
+void UGEEntityCube::updateFaces()
|
|
60
|
+{
|
|
61
|
+ _facesColor.clear();
|
|
62
|
+ _facesTexture.clear();
|
|
63
|
+ double r = _size / 2;
|
|
64
|
+ if (_textureId.isNull()) {
|
|
65
|
+ QList<ColorVector3D> points;
|
|
66
|
+ points << ColorVector3D(getColor(), -r, -r, r) << ColorVector3D(getColor(), -r, r, r)
|
|
67
|
+ << ColorVector3D(getColor(), r, r, r) << ColorVector3D(getColor(), r, -r, r)
|
|
68
|
+ << ColorVector3D(getColor(), -r, -r, -r) << ColorVector3D(getColor(), -r, r, -r)
|
|
69
|
+ << ColorVector3D(getColor(), r, r, -r) << ColorVector3D(getColor(), r, -r, -r);
|
|
70
|
+ _facesColor.append(QList<ColorVector3D>() << points[3] << points[2] << points[1] << points[0]);
|
|
71
|
+ _facesColor.append(QList<ColorVector3D>() << points[2] << points[3] << points[7] << points[6]);
|
|
72
|
+ _facesColor.append(QList<ColorVector3D>() << points[6] << points[7] << points[4] << points[5]);
|
|
73
|
+ _facesColor.append(QList<ColorVector3D>() << points[5] << points[4] << points[0] << points[1]);
|
|
74
|
+ _facesColor.append(QList<ColorVector3D>() << points[1] << points[2] << points[6] << points[5]);
|
|
75
|
+ _facesColor.append(QList<ColorVector3D>() << points[4] << points[7] << points[3] << points[0]);
|
|
76
|
+ }
|
|
77
|
+ else {
|
|
78
|
+ _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), getColor(), r, -r, r)
|
|
79
|
+ << TextureVector3D(Vector2D(0.25, 0.25), getColor(), r, r, r)
|
|
80
|
+ << TextureVector3D(Vector2D(0.00, 0.25), getColor(), -r, r, r)
|
|
81
|
+ << TextureVector3D(Vector2D(0.00, 0.50), getColor(), -r, -r, r));
|
|
82
|
+ _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), getColor(), r, r, r)
|
|
83
|
+ << TextureVector3D(Vector2D(0.25, 0.25), getColor(), r, -r, r)
|
|
84
|
+ << TextureVector3D(Vector2D(0.50, 0.25), getColor(), r, -r, -r)
|
|
85
|
+ << TextureVector3D(Vector2D(0.50, 0.50), getColor(), r, r, -r));
|
|
86
|
+ _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.25), getColor(), r, r, -r)
|
|
87
|
+ << TextureVector3D(Vector2D(0.50, 0.50), getColor(), r, -r, -r)
|
|
88
|
+ << TextureVector3D(Vector2D(0.75, 0.50), getColor(), -r, -r, -r)
|
|
89
|
+ << TextureVector3D(Vector2D(0.75, 0.25), getColor(), -r, r, -r));
|
|
90
|
+ _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.75, 0.25), getColor(), -r, r, -r)
|
|
91
|
+ << TextureVector3D(Vector2D(0.75, 0.50), getColor(), -r, -r, -r)
|
|
92
|
+ << TextureVector3D(Vector2D(1.00, 0.50), getColor(), -r, -r, r)
|
|
93
|
+ << TextureVector3D(Vector2D(1.00, 0.25), getColor(), -r, r, r));
|
|
94
|
+ _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.00), getColor(), -r, r, r)
|
|
95
|
+ << TextureVector3D(Vector2D(0.25, 0.25), getColor(), r, r, r)
|
|
96
|
+ << TextureVector3D(Vector2D(0.50, 0.25), getColor(), r, r, -r)
|
|
97
|
+ << TextureVector3D(Vector2D(0.50, 0.00), getColor(), -r, r, -r));
|
|
98
|
+ _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.75), getColor(), -r, -r, -r)
|
|
99
|
+ << TextureVector3D(Vector2D(0.50, 0.50), getColor(), r, -r, -r)
|
|
100
|
+ << TextureVector3D(Vector2D(0.25, 0.5), getColor(), r, -r, r)
|
|
101
|
+ << TextureVector3D(Vector2D(0.25, 0.75), getColor(), -r, -r, r));
|
|
102
|
+ }
|
|
103
|
+}
|