Browse Source

ground base; added textures; random rotation/textures on cube add

develop
Robin Thoni 7 years ago
parent
commit
822cd2f7ee

BIN
TheGame/assets/textures/companion.png View File


BIN
TheGame/assets/textures/dice.png View File


+ 33
- 6
TheGame/renderwidget.cpp View File

@@ -2,6 +2,7 @@
2 2
 #include <QTimer>
3 3
 #include <math.h>
4 4
 #include <QDebug>
5
+#include <QDir>
5 6
 #include "entities/ugeentitycube.h"
6 7
 #include "entities/ugeentityaxes.h"
7 8
 #include "utils/wavefrontobj.h"
@@ -37,10 +38,10 @@ RenderWidget::RenderWidget(QWidget *parent) :
37 38
 //    }
38 39
 
39 40
 
40
-//    int xmax = 25;
41
-//    int zmax = 25;
42
-    int xmax = 1;
43
-    int zmax = 1;
41
+    int xmax = 25;
42
+    int zmax = 25;
43
+//    int xmax = 1;
44
+//    int zmax = 1;
44 45
     for (int x = 0; x < xmax; ++x) {
45 46
         for (int z = 0; z < zmax; ++z) {
46 47
             UGEEntityCube* cube = new UGEEntityCube(_engine);
@@ -59,11 +60,21 @@ RenderWidget::RenderWidget(QWidget *parent) :
59 60
 
60 61
 void RenderWidget::initializeGL()
61 62
 {
63
+    srand(time(0));
62 64
     makeCurrent();
63 65
     _engine->setClearColor(Qt::gray);
64 66
     _engine->initialize(70, width(), height());
65 67
 
66
-    _engine->loadTextureFromFile("rubiks", _assetsPath + "textures/rubiks.png");
68
+    _textures.clear();
69
+    QDir texturesDir(_assetsPath + "textures");
70
+    QFileInfoList files = texturesDir.entryInfoList(QStringList() << "*.png" << "*.jpg" << "*.jpeg");
71
+    for (int i = 0; i < files.size(); ++i)
72
+    {
73
+        QFileInfo file = files[i];
74
+
75
+        _engine->loadTextureFromFile(file.baseName(), file.absoluteFilePath());
76
+        _textures.append(file.baseName());
77
+    }
67 78
 }
68 79
 
69 80
 void RenderWidget::paintGL()
@@ -103,9 +114,25 @@ void RenderWidget::mousePressEvent(QMouseEvent *event)
103 114
                 else if (fmod(fabs(diff.getZ()), 0.5) == 0) {
104 115
                     pos.add(Vector3D(0, 0, 1 * (diff.getZ() < 0 ? 1 : -1)));
105 116
                 }
117
+
118
+                QList<UGEEntity*> entities = _engine->getEntities();
119
+                for (int i = 0; i < entities.size(); ++i) {
120
+                    UGEEntity* e = entities[i];
121
+                    if (e->getPosition() == pos) {
122
+                        return;
123
+                    }
124
+                }
125
+
126
+                int x = (rand() >= RAND_MAX / 2 ? 90 : 0) * (rand() >= RAND_MAX / 2 ? -1 : 1);
127
+                int y = (rand() >= RAND_MAX / 2 ? 90 : 0) * (rand() >= RAND_MAX / 2 ? -1 : 1);
128
+                int z = (rand() >= RAND_MAX / 2 ? 90 : 0) * (rand() >= RAND_MAX / 2 ? -1 : 1);
129
+                QString texture = _textures[rand() / (double)RAND_MAX * _textures.size()];
130
+
131
+
106 132
                 UGEEntityCube* cube = new UGEEntityCube(_engine);
107 133
                 cube->move(pos);
108
-                cube->setTextureId("rubiks");
134
+                cube->rotate(Vector3D(x, y, z));
135
+                cube->setTextureId(texture);
109 136
             }
110 137
         }
111 138
     }

+ 2
- 0
TheGame/renderwidget.h View File

@@ -45,6 +45,8 @@ private:
45 45
     AbstractCamera* _camera;
46 46
 
47 47
     QString _assetsPath;
48
+
49
+    QStringList _textures;
48 50
 };
49 51
 
50 52
 #endif // RENDERWIDGET_H

+ 0
- 1
UGameEngine/engine/abstractrenderdevice.cpp View File

@@ -47,7 +47,6 @@ void AbstractRenderDevice::lookAt(const Vector3D &eye, const Vector3D &center, c
47 47
 void AbstractRenderDevice::loadTextureFromFile(const QVariant &id, const QString &filename)
48 48
 {
49 49
     QImage img;
50
-    qDebug() << QDir::currentPath() << filename;
51 50
     if (img.load(filename)) {
52 51
         loadTexture(id, img);
53 52
     }

Loading…
Cancel
Save