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
 #include <QTimer>
2
 #include <QTimer>
3
 #include <math.h>
3
 #include <math.h>
4
 #include <QDebug>
4
 #include <QDebug>
5
+#include <QDir>
5
 #include "entities/ugeentitycube.h"
6
 #include "entities/ugeentitycube.h"
6
 #include "entities/ugeentityaxes.h"
7
 #include "entities/ugeentityaxes.h"
7
 #include "utils/wavefrontobj.h"
8
 #include "utils/wavefrontobj.h"
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
     for (int x = 0; x < xmax; ++x) {
45
     for (int x = 0; x < xmax; ++x) {
45
         for (int z = 0; z < zmax; ++z) {
46
         for (int z = 0; z < zmax; ++z) {
46
             UGEEntityCube* cube = new UGEEntityCube(_engine);
47
             UGEEntityCube* cube = new UGEEntityCube(_engine);
59
 
60
 
60
 void RenderWidget::initializeGL()
61
 void RenderWidget::initializeGL()
61
 {
62
 {
63
+    srand(time(0));
62
     makeCurrent();
64
     makeCurrent();
63
     _engine->setClearColor(Qt::gray);
65
     _engine->setClearColor(Qt::gray);
64
     _engine->initialize(70, width(), height());
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
 void RenderWidget::paintGL()
80
 void RenderWidget::paintGL()
103
                 else if (fmod(fabs(diff.getZ()), 0.5) == 0) {
114
                 else if (fmod(fabs(diff.getZ()), 0.5) == 0) {
104
                     pos.add(Vector3D(0, 0, 1 * (diff.getZ() < 0 ? 1 : -1)));
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
                 UGEEntityCube* cube = new UGEEntityCube(_engine);
132
                 UGEEntityCube* cube = new UGEEntityCube(_engine);
107
                 cube->move(pos);
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
     AbstractCamera* _camera;
45
     AbstractCamera* _camera;
46
 
46
 
47
     QString _assetsPath;
47
     QString _assetsPath;
48
+
49
+    QStringList _textures;
48
 };
50
 };
49
 
51
 
50
 #endif // RENDERWIDGET_H
52
 #endif // RENDERWIDGET_H

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

47
 void AbstractRenderDevice::loadTextureFromFile(const QVariant &id, const QString &filename)
47
 void AbstractRenderDevice::loadTextureFromFile(const QVariant &id, const QString &filename)
48
 {
48
 {
49
     QImage img;
49
     QImage img;
50
-    qDebug() << QDir::currentPath() << filename;
51
     if (img.load(filename)) {
50
     if (img.load(filename)) {
52
         loadTexture(id, img);
51
         loadTexture(id, img);
53
     }
52
     }

Loading…
Cancel
Save