|  | @@ -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 |      }
 |