Browse Source

best collision

develop
Pierre-Antoine 'ZHAJOR' Tible 7 years ago
parent
commit
cd8af21ad9
1 changed files with 20 additions and 20 deletions
  1. 20
    20
      TheGame/renderwidget.cpp

+ 20
- 20
TheGame/renderwidget.cpp View File

@@ -28,28 +28,28 @@ RenderWidget::RenderWidget(QWidget *parent) :
28 28
 
29 29
     //_engine->addEntity(new UGEEntityAxes(_engine));
30 30
 
31
-    for (int i = 0; i < 1; ++i) {
32
-        UGEEntityCube* cube = new GameCube(_engine);
33
-        cube->setTextureId("rubiks");
34
-//        cube->rotate(Vector3D(0.0, 45.0, 45.0));
35
-        cube->move(Vector3D(0, i, i));
36
-//        cube->setScale(Vector3D(1.0, 2.0, 1.0));
37
-        _engine->addEntity(cube);
38
-        _entities.append(cube);
39
-    }
40
-
41
-//    for(int i = 0,j = 0; i * j< 626;){
31
+//    for (int i = 0; i < 1; ++i) {
42 32
 //        UGEEntityCube* cube = new GameCube(_engine);
43 33
 //        cube->setTextureId("rubiks");
44
-//        cube->move(Vector3D(i, 0, j++));
34
+////        cube->rotate(Vector3D(0.0, 45.0, 45.0));
35
+//        cube->move(Vector3D(0, i, i));
36
+////        cube->setScale(Vector3D(1.0, 2.0, 1.0));
45 37
 //        _engine->addEntity(cube);
46 38
 //        _entities.append(cube);
47
-//        if(j == 26){
48
-//            j = 0;
49
-//            i++;
50
-//        }
51 39
 //    }
52 40
 
41
+    for(int i = 0,j = 0; i * j< 626;){
42
+        UGEEntityCube* cube = new GameCube(_engine);
43
+        cube->setTextureId("rubiks");
44
+        cube->move(Vector3D(i, 0, j++));
45
+        _engine->addEntity(cube);
46
+        _entities.append(cube);
47
+        if(j == 26){
48
+            j = 0;
49
+            i++;
50
+        }
51
+    }
52
+
53 53
     WaveFrontObj* wavefrontObj = new WaveFrontObj(this);
54 54
     wavefrontObj->openFile(_assetsPath + "objs/enterprise/USSEnterprise.obj");
55 55
     UGEEntityWaveFrontObj* obj = new UGEEntityWaveFrontObj(wavefrontObj, this);
@@ -84,15 +84,15 @@ void RenderWidget::mousePressEvent(QMouseEvent *event)
84 84
     _camera->mousePressEvent(event);
85 85
     if (event->buttons() & Qt::LeftButton) {
86 86
 //        Vector3D pos = _engine->get3DFrom2D(Vector2D(event->x(), height() - event->y()));
87
-        Vector3D pos = _camera->getDirection();
87
+        Vector3D pos = _camera->getPosition();
88 88
         qDebug() << pos.getX() << pos.getY() << pos.getZ();
89 89
         Vector3D bestp;
90
-        bool ok;
90
+        bool ok = false;
91 91
         for (int i = 0; i < _engine->getEntities().size(); i++) {
92 92
             UGEEntity* entity = _engine->getEntities()[i];
93 93
             bool provi;
94
-            Vector3D collision = entity->getVectorNearestIntesection(_camera->getDirection(), _camera->getPosition(), &provi);
95
-            if (provi) {
94
+            Vector3D collision = entity->getVectorNearestIntesection(_camera->getDirection(), pos, &provi);
95
+            if (provi && (!ok || (pos - bestp).norm() > (pos - collision).norm())) {
96 96
                 bestp = collision;
97 97
                 UGEEntityAxes* axe = new UGEEntityAxes(_engine);
98 98
                 axe->move(bestp);

Loading…
Cancel
Save