Browse Source

textured cube

develop
Robin Thoni 7 years ago
parent
commit
f4c3c52515

+ 63
- 1
TheGame/openglrenderdevice.cpp View File

1
 #include "openglrenderdevice.h"
1
 #include "openglrenderdevice.h"
2
+#include <QRgb>
2
 #include "GL/gl.h"
3
 #include "GL/gl.h"
3
 #include "GL/glu.h"
4
 #include "GL/glu.h"
4
 
5
 
38
     return Vector3D(gx, gy, gz);
39
     return Vector3D(gx, gy, gz);
39
 }
40
 }
40
 
41
 
42
+void OpenGLRenderDevice::loadTexture(const QVariant &id, const QImage &texture)
43
+{
44
+    OpenGLTextureData data;
45
+    data.id = 0;
46
+    data.image = texture;
47
+    data.rawData = new char[texture.width() * texture.height() * 4];
48
+
49
+    for (int y = 0; y < texture.height(); ++y) {
50
+        for(int x = 0; x < texture.width(); ++x) {
51
+            int p = (y * texture.height() * 4) + x * 4;
52
+            QColor px = QColor(texture.pixel(x, y));
53
+            data.rawData[p] = px.red();
54
+            data.rawData[p + 1] = px.green();
55
+            data.rawData[p + 2] = px.blue();
56
+            data.rawData[p + 3] = 255;
57
+        }
58
+    }
59
+
60
+
61
+    glGenTextures(1, &data.id);
62
+    glBindTexture(GL_TEXTURE_2D, data.id);
63
+
64
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.width(), texture.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, data.rawData);
65
+
66
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
67
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
68
+
69
+    _textures.insert(id, data);
70
+}
71
+
41
 void OpenGLRenderDevice::initialize(int fov, int width, int height)
72
 void OpenGLRenderDevice::initialize(int fov, int width, int height)
42
 {
73
 {
43
     _fov = fov;
74
     _fov = fov;
47
     glClearColor(_clearColor.redF(), _clearColor.greenF(),
78
     glClearColor(_clearColor.redF(), _clearColor.greenF(),
48
                  _clearColor.blueF(), _clearColor.alphaF());
79
                  _clearColor.blueF(), _clearColor.alphaF());
49
 
80
 
81
+//    glShadeModel(GL_SMOOTH);
82
+//    glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
83
+//    glColorMaterial(GL_FRONT,GL_SPECULAR);
84
+//    glCullFace(GL_BACK);
85
+
86
+//    glEnable(GL_LIGHTING);
87
+//    glEnable(GL_LIGHT0);
88
+//    glEnable(GL_COLOR_MATERIAL);
89
+//    glEnable(GL_CULL_FACE);
90
+    glEnable(GL_TEXTURE_2D);
91
+
92
+//    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
93
+
50
 
94
 
51
 //    GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0};  /* Red diffuse light. */
95
 //    GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0};  /* Red diffuse light. */
52
 //    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};  /* Infinite light location. */
96
 //    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};  /* Infinite light location. */
55
 //    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, light_diffuse);
99
 //    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, light_diffuse);
56
 //    glEnable(GL_LIGHT0);
100
 //    glEnable(GL_LIGHT0);
57
 //    glEnable(GL_LIGHTING);
101
 //    glEnable(GL_LIGHTING);
58
-    glDisable(GL_LIGHTING);
59
 
102
 
60
     glEnable(GL_DEPTH_TEST);
103
     glEnable(GL_DEPTH_TEST);
104
+//    glDisable(GL_BLEND);
105
+//    glDisable(GL_POLYGON_SMOOTH);
106
+//    glEnable(GL_TEXTURE_2D);
107
+//    glColorMaterial(GL_FRONT,GL_SPECULAR);
108
+//    glEnable(GL_COLOR_MATERIAL);
109
+//    glEnable(GL_CULL_FACE);
61
 
110
 
62
     glMatrixMode(GL_PROJECTION);
111
     glMatrixMode(GL_PROJECTION);
63
     gluPerspective(_fov, _width / _height, 0.1, 100.0);
112
     gluPerspective(_fov, _width / _height, 0.1, 100.0);
120
     }
169
     }
121
     glEnd();
170
     glEnd();
122
 }
171
 }
172
+
173
+void OpenGLRenderDevice::drawPolygonTexture(const QList<TextureVector3D> &points, const QVariant &textureId)
174
+{
175
+    const OpenGLTextureData& data = _textures[textureId];
176
+    glBindTexture(GL_TEXTURE_2D, data.id);
177
+    glBegin(GL_POLYGON);
178
+    for (int i = 0; i < points.size(); ++i) {
179
+        TextureVector3D p = points[i];
180
+        glTexCoord2d(p.getTextureCoord().getX(), p.getTextureCoord().getY());
181
+        drawVertex(p);
182
+    }
183
+    glEnd();
184
+}

+ 13
- 0
TheGame/openglrenderdevice.h View File

3
 
3
 
4
 #include "engine/abstractrenderdevice.h"
4
 #include "engine/abstractrenderdevice.h"
5
 
5
 
6
+struct OpenGLTextureData
7
+{
8
+    unsigned id;
9
+    QImage image;
10
+    char* rawData;
11
+};
12
+
6
 class OpenGLRenderDevice : public AbstractRenderDevice
13
 class OpenGLRenderDevice : public AbstractRenderDevice
7
 {
14
 {
8
     Q_OBJECT
15
     Q_OBJECT
17
 
24
 
18
 public slots:
25
 public slots:
19
 
26
 
27
+    virtual void loadTexture(const QVariant& id, const QImage& texture);
28
+
20
     virtual void initialize(int fov, int width, int height);
29
     virtual void initialize(int fov, int width, int height);
21
 
30
 
22
     virtual void resize(int width, int height);
31
     virtual void resize(int width, int height);
33
 
42
 
34
     virtual void drawPolygon(const QList<ColorVector3D>& points);
43
     virtual void drawPolygon(const QList<ColorVector3D>& points);
35
 
44
 
45
+    virtual void drawPolygonTexture(const QList<TextureVector3D>& points, const QVariant& textureId);
46
+
36
 private:
47
 private:
37
     int _width;
48
     int _width;
38
 
49
 
40
 
51
 
41
     int _fov;
52
     int _fov;
42
 
53
 
54
+    QMap<QVariant, OpenGLTextureData> _textures;
55
+
43
 };
56
 };
44
 
57
 
45
 #endif // OPENGLRENDERDEVICE_H
58
 #endif // OPENGLRENDERDEVICE_H

+ 7
- 4
TheGame/renderwidget.cpp View File

15
 {
15
 {
16
     _device = new OpenGLRenderDevice(this);
16
     _device = new OpenGLRenderDevice(this);
17
     _engine = new UGameEngine(_device);
17
     _engine = new UGameEngine(_device);
18
+
18
     UGEEntityCube* cube = new UGEEntityCube(_engine);
19
     UGEEntityCube* cube = new UGEEntityCube(_engine);
20
+    cube->setTextureId("test");
19
 //    cube->move(Vector3D(0, 1, 0));
21
 //    cube->move(Vector3D(0, 1, 0));
20
-    cube->hide();
22
+//    cube->hide();
21
     _engine->addEntity(cube);
23
     _engine->addEntity(cube);
22
     _engine->addEntity(new UGEEntityAxes(_engine));
24
     _engine->addEntity(new UGEEntityAxes(_engine));
23
     setMouseTracking(true);
25
     setMouseTracking(true);
28
 
30
 
29
     UGEEntityWaveFrontObj* obj = new UGEEntityWaveFrontObj(wavefrontObj, this);
31
     UGEEntityWaveFrontObj* obj = new UGEEntityWaveFrontObj(wavefrontObj, this);
30
     _engine->addEntity(obj);
32
     _engine->addEntity(obj);
31
-//    obj->hide();
33
+    obj->hide();
32
 
34
 
33
 }
35
 }
34
 
36
 
38
     _device->setClearColor(Qt::gray);
40
     _device->setClearColor(Qt::gray);
39
     _device->initialize(70, width(), height());
41
     _device->initialize(70, width(), height());
40
 
42
 
43
+    _device->loadTextureFromFile("test", "/home/robin/Downloads/test.png");
41
 }
44
 }
42
 
45
 
43
 void RenderWidget::paintGL()
46
 void RenderWidget::paintGL()
51
                 );
54
                 );
52
     _device->lookAt(center, Vector3D(0.0f, 0.0f, 0.0f));
55
     _device->lookAt(center, Vector3D(0.0f, 0.0f, 0.0f));
53
     _engine->draw();
56
     _engine->draw();
54
-    _device->drawLine(ColorVector3D(Qt::black, 0, 0, 0), ColorVector3D(Qt::black, pos));
55
-    _device->drawPoint(ColorVector3D(Qt::magenta, 0.5, 0.5, 0.5));
57
+//    _device->drawLine(ColorVector3D(Qt::black, 0, 0, 0), ColorVector3D(Qt::black, pos));
58
+//    _device->drawPoint(ColorVector3D(Qt::magenta, 0.5, 0.5, 0.5));
56
 }
59
 }
57
 
60
 
58
 void RenderWidget::resizeGL(int width, int height)
61
 void RenderWidget::resizeGL(int width, int height)

+ 7
- 7
UGameEngine/engine/abstractrenderdevice.cpp View File

43
     _lookUp = up;
43
     _lookUp = up;
44
 }
44
 }
45
 
45
 
46
-//void AbstractRenderDevice::loadTextureFromFile(const QVariant &id, const QString &filename)
47
-//{
48
-//    QImage img;
49
-//    if (img.load(filename)) {
50
-//        loadTexture(id, img);
51
-//    }
52
-//}
46
+void AbstractRenderDevice::loadTextureFromFile(const QVariant &id, const QString &filename)
47
+{
48
+    QImage img;
49
+    if (img.load(filename)) {
50
+        loadTexture(id, img);
51
+    }
52
+}
53
 
53
 
54
 QColor AbstractRenderDevice::getClearColor() const
54
 QColor AbstractRenderDevice::getClearColor() const
55
 {
55
 {

+ 5
- 3
UGameEngine/engine/abstractrenderdevice.h View File

3
 
3
 
4
 #include <QObject>
4
 #include <QObject>
5
 #include <QColor>
5
 #include <QColor>
6
+#include <QImage>
6
 #include "utils/colorvector3d.h"
7
 #include "utils/colorvector3d.h"
8
+#include "utils/texturevector3d.h"
7
 
9
 
8
 class AbstractRenderDevice : public QObject
10
 class AbstractRenderDevice : public QObject
9
 {
11
 {
34
 
36
 
35
     virtual void lookAt(const Vector3D& eye, const Vector3D& center, const Vector3D& up = Vector3D(0.0, 1.0, 0.0));
37
     virtual void lookAt(const Vector3D& eye, const Vector3D& center, const Vector3D& up = Vector3D(0.0, 1.0, 0.0));
36
 
38
 
37
-//    void loadTextureFromFile(const QVariant& id, const QString& filename);
39
+    void loadTextureFromFile(const QVariant& id, const QString& filename);
38
 
40
 
39
-//    virtual void loadTexture(const QVariant& id, const QImage& texture) = 0;
41
+    virtual void loadTexture(const QVariant& id, const QImage& texture) = 0;
40
 
42
 
41
     virtual void initialize(int fov, int width, int height) = 0;
43
     virtual void initialize(int fov, int width, int height) = 0;
42
 
44
 
52
 
54
 
53
     virtual void drawPolygon(const QList<ColorVector3D>& points) = 0;
55
     virtual void drawPolygon(const QList<ColorVector3D>& points) = 0;
54
 
56
 
55
-//    virtual void drawPolygonTexture(const QList<ColorVector3D>& points) = 0;
57
+    virtual void drawPolygonTexture(const QList<TextureVector3D>& points, const QVariant& textureId) = 0;
56
 
58
 
57
 protected:
59
 protected:
58
     QColor _clearColor;
60
     QColor _clearColor;

+ 13
- 0
UGameEngine/entities/ugeentity.cpp View File

99
     return ColorVector3D(pos.getColor(), getRealPoint((Vector3D)pos));
99
     return ColorVector3D(pos.getColor(), getRealPoint((Vector3D)pos));
100
 }
100
 }
101
 
101
 
102
+TextureVector3D UGEEntity::getRealPoint(const TextureVector3D &pos)
103
+{
104
+    return TextureVector3D(pos.getTextureCoord(), getRealPoint((ColorVector3D)pos));
105
+}
106
+
102
 void UGEEntity::drawPoint(AbstractRenderDevice *device, const ColorVector3D &point)
107
 void UGEEntity::drawPoint(AbstractRenderDevice *device, const ColorVector3D &point)
103
 {
108
 {
104
     device->drawPoint(getRealPoint(point));
109
     device->drawPoint(getRealPoint(point));
116
     }
121
     }
117
     device->drawPolygon(points);
122
     device->drawPolygon(points);
118
 }
123
 }
124
+
125
+void UGEEntity::drawPolygonTexture(AbstractRenderDevice *device, QList<TextureVector3D> points, const QVariant &textureId)
126
+{
127
+    for (int i = 0; i < points.size(); ++i) {
128
+        points[i] = getRealPoint(points[i]);
129
+    }
130
+    device->drawPolygonTexture(points, textureId);
131
+}

+ 3
- 0
UGameEngine/entities/ugeentity.h View File

37
 
37
 
38
     Vector3D getRealPoint(const Vector3D& pos);
38
     Vector3D getRealPoint(const Vector3D& pos);
39
     ColorVector3D getRealPoint(const ColorVector3D& pos);
39
     ColorVector3D getRealPoint(const ColorVector3D& pos);
40
+    TextureVector3D getRealPoint(const TextureVector3D& pos);
40
 
41
 
41
     virtual void drawPoint(AbstractRenderDevice* device, const ColorVector3D& point);
42
     virtual void drawPoint(AbstractRenderDevice* device, const ColorVector3D& point);
42
 
43
 
44
 
45
 
45
     virtual void drawPolygon(AbstractRenderDevice* device, QList<ColorVector3D> points);
46
     virtual void drawPolygon(AbstractRenderDevice* device, QList<ColorVector3D> points);
46
 
47
 
48
+    virtual void drawPolygonTexture(AbstractRenderDevice *device, QList<TextureVector3D> points, const QVariant& textureId);
49
+
47
     virtual void draw(AbstractRenderDevice* device) = 0;
50
     virtual void draw(AbstractRenderDevice* device) = 0;
48
 
51
 
49
 private:
52
 private:

+ 52
- 10
UGameEngine/entities/ugeentitycube.cpp View File

13
 
13
 
14
 void UGEEntityCube::draw(AbstractRenderDevice *device)
14
 void UGEEntityCube::draw(AbstractRenderDevice *device)
15
 {
15
 {
16
-    QColor color = Qt::red;
17
     float r = _size / 2;
16
     float r = _size / 2;
18
-    QList<ColorVector3D> points;
19
-    points << ColorVector3D(color, -r, -r, r) << ColorVector3D(color, -r, r, r) << ColorVector3D(color, r, r, r) << ColorVector3D(color, r, -r, r);
20
-    points << ColorVector3D(color, -r, -r, -r) << ColorVector3D(color, -r, r, -r) << ColorVector3D(color, r, r, -r) << ColorVector3D(color, r, -r, -r);
21
-    drawPolygon(device, QList<ColorVector3D>() << points[3] << points[2] << points[1] << points[0]);
22
-    drawPolygon(device, QList<ColorVector3D>() << points[2] << points[3] << points[7] << points[6]);
23
-    drawPolygon(device, QList<ColorVector3D>() << points[6] << points[7] << points[4] << points[5]);
24
-    drawPolygon(device, QList<ColorVector3D>() << points[5] << points[4] << points[0] << points[1]);
25
-    drawPolygon(device, QList<ColorVector3D>() << points[1] << points[2] << points[6] << points[5]);
26
-    drawPolygon(device, QList<ColorVector3D>() << points[4] << points[7] << points[3] << points[0]);
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]);
30
+    }
31
+    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);
57
+    }
58
+}
59
+
60
+QVariant UGEEntityCube::getTextureId() const
61
+{
62
+    return _textureId;
27
 }
63
 }
28
 
64
 
29
 void UGEEntityCube::setSize(float size)
65
 void UGEEntityCube::setSize(float size)
31
     _size = size;
67
     _size = size;
32
 }
68
 }
33
 
69
 
70
+void UGEEntityCube::setTextureId(const QVariant &textureId)
71
+{
72
+    _textureId = textureId;
73
+}
74
+
75
+

+ 4
- 0
UGameEngine/entities/ugeentitycube.h View File

13
 
13
 
14
     virtual void draw(AbstractRenderDevice* device);
14
     virtual void draw(AbstractRenderDevice* device);
15
 
15
 
16
+    QVariant getTextureId() const;
17
+
16
 signals:
18
 signals:
17
 
19
 
18
 public slots:
20
 public slots:
19
     void setSize(float size);
21
     void setSize(float size);
22
+    void setTextureId(const QVariant &textureId);
20
 
23
 
21
 private:
24
 private:
22
     float _size;
25
     float _size;
26
+    QVariant _textureId;
23
 
27
 
24
 };
28
 };
25
 
29
 

+ 14
- 2
UGameEngine/utils/colorvector3d.cpp View File

1
 #include "colorvector3d.h"
1
 #include "colorvector3d.h"
2
 
2
 
3
-ColorVector3D::ColorVector3D(QColor color, double x, double y, double z)
3
+ColorVector3D::ColorVector3D()
4
+    : Vector3D(0.0, 0.0, 0.0)
5
+    , _color(Qt::black)
6
+{
7
+}
8
+
9
+ColorVector3D::ColorVector3D(const QColor &color)
10
+    : Vector3D(0.0, 0.0, 0.0)
11
+    , _color(color)
12
+{
13
+}
14
+
15
+ColorVector3D::ColorVector3D(const QColor &color, double x, double y, double z)
4
     : Vector3D(x, y, z)
16
     : Vector3D(x, y, z)
5
     , _color(color)
17
     , _color(color)
6
 {
18
 {
7
 }
19
 }
8
 
20
 
9
-ColorVector3D::ColorVector3D(QColor color, const Vector3D &other)
21
+ColorVector3D::ColorVector3D(const QColor& color, const Vector3D &other)
10
     : Vector3D(other)
22
     : Vector3D(other)
11
     , _color(color)
23
     , _color(color)
12
 {
24
 {

+ 4
- 2
UGameEngine/utils/colorvector3d.h View File

7
 class ColorVector3D : public Vector3D
7
 class ColorVector3D : public Vector3D
8
 {
8
 {
9
 public:
9
 public:
10
-    ColorVector3D(QColor color = Qt::black, double x = 0.0, double y = 0.0, double z = 0.0);
11
-    ColorVector3D(QColor color = Qt::black, const Vector3D& other = Vector3D());
10
+    ColorVector3D();
11
+    ColorVector3D(const QColor& color);
12
+    ColorVector3D(const QColor& color, double x, double y, double z);
13
+    ColorVector3D(const QColor& color, const Vector3D& other);
12
     ColorVector3D(const ColorVector3D& other);
14
     ColorVector3D(const ColorVector3D& other);
13
     virtual ~ColorVector3D();
15
     virtual ~ColorVector3D();
14
 
16
 

+ 1
- 1
UGameEngine/utils/parser-wavefront-obj.y View File

94
 face: F face_vertex_list { $$ = $2; };
94
 face: F face_vertex_list { $$ = $2; };
95
 
95
 
96
 face_vertex_list: { $$ = new QList<int>(); }
96
 face_vertex_list: { $$ = new QList<int>(); }
97
-            | face_vertex_list face_vertex { $1->append($2); };
97
+            | face_vertex_list face_vertex { $1->append($2); $$ = $1;};
98
 
98
 
99
 face_vertex: NUMBER { $$ = $1; }
99
 face_vertex: NUMBER { $$ = $1; }
100
             | NUMBER SLASH NUMBER { $$ = $1; }
100
             | NUMBER SLASH NUMBER { $$ = $1; }

+ 52
- 0
UGameEngine/utils/texturevector3d.cpp View File

1
 #include "texturevector3d.h"
1
 #include "texturevector3d.h"
2
 
2
 
3
+TextureVector3D::TextureVector3D()
4
+    : ColorVector3D(Qt::white, 0.0, 0.0, 0.0)
5
+    , _textureCoord(0.0, 0.0)
6
+{
7
+}
8
+
9
+TextureVector3D::TextureVector3D(const Vector2D &textureCoord)
10
+    : ColorVector3D(Qt::white, 0.0, 0.0, 0.0)
11
+    , _textureCoord(textureCoord)
12
+{
13
+}
14
+
15
+TextureVector3D::TextureVector3D(const Vector2D &textureCoord, const QColor &color)
16
+    : ColorVector3D(color, 0.0, 0.0, 0.0)
17
+    , _textureCoord(textureCoord)
18
+{
19
+}
20
+
21
+TextureVector3D::TextureVector3D(const Vector2D &textureCoord, const QColor &color, double x, double y, double z)
22
+    : ColorVector3D(color, x, y, z)
23
+    , _textureCoord(textureCoord)
24
+{
25
+}
26
+
27
+TextureVector3D::TextureVector3D(const Vector2D &textureCoord, const QColor& color, const Vector3D &other)
28
+    : ColorVector3D(color, other)
29
+    , _textureCoord(textureCoord)
30
+{
31
+}
32
+
33
+TextureVector3D::TextureVector3D(const Vector2D &textureCoord, const ColorVector3D &other)
34
+    : ColorVector3D(other)
35
+    , _textureCoord(textureCoord)
36
+{
37
+}
38
+
39
+TextureVector3D::TextureVector3D(const TextureVector3D &other)
40
+    : ColorVector3D(other)
41
+    , _textureCoord(other._textureCoord)
42
+{
43
+}
44
+
3
 TextureVector3D::~TextureVector3D()
45
 TextureVector3D::~TextureVector3D()
4
 {
46
 {
5
 }
47
 }
48
+
49
+Vector2D TextureVector3D::getTextureCoord() const
50
+{
51
+    return _textureCoord;
52
+}
53
+
54
+void TextureVector3D::setTextureCoord(const Vector2D &textureCoord)
55
+{
56
+    _textureCoord = textureCoord;
57
+}

+ 14
- 3
UGameEngine/utils/texturevector3d.h View File

2
 #define TEXTUREVECTOR3D_H
2
 #define TEXTUREVECTOR3D_H
3
 
3
 
4
 #include "colorvector3d.h"
4
 #include "colorvector3d.h"
5
+#include "vector2d.h"
5
 
6
 
6
 class TextureVector3D : public ColorVector3D
7
 class TextureVector3D : public ColorVector3D
7
 {
8
 {
8
 public:
9
 public:
9
-    TextureVector3D(QColor color = Qt::white, double x = 0.0, double y = 0.0, double z = 0.0);
10
-    TextureVector3D(QColor color = Qt::white, const Vector3D& other = Vector3D());
11
-    TextureVector3D(const ColorVector3D& other);
10
+    TextureVector3D();
11
+    TextureVector3D(const Vector2D& textureCoord);
12
+    TextureVector3D(const Vector2D& textureCoord, const QColor& color);
13
+    TextureVector3D(const Vector2D& textureCoord, const QColor& color, double x, double y, double z);
14
+    TextureVector3D(const Vector2D& textureCoord, const QColor& color, const Vector3D& other);
15
+    TextureVector3D(const Vector2D& textureCoord, const ColorVector3D& other);
16
+    TextureVector3D(const TextureVector3D& other);
12
     virtual ~TextureVector3D();
17
     virtual ~TextureVector3D();
18
+
19
+    Vector2D getTextureCoord() const;
20
+    void setTextureCoord(const Vector2D &textureCoord);
21
+
22
+private:
23
+    Vector2D _textureCoord;
13
 };
24
 };
14
 
25
 
15
 #endif // TEXTUREVECTOR3D_H
26
 #endif // TEXTUREVECTOR3D_H

Loading…
Cancel
Save