Browse Source

added enterprise and rotating cubes; restored face normal

develop
Robin Thoni 7 years ago
parent
commit
398adef33c
3 changed files with 35 additions and 14 deletions
  1. 5
    5
      TheGame/openglrenderdevice.cpp
  2. 28
    7
      TheGame/renderwidget.cpp
  3. 2
    2
      UGameEngine/cameras/freeflycamera.cpp

+ 5
- 5
TheGame/openglrenderdevice.cpp View File

@@ -97,7 +97,7 @@ void OpenGLRenderDevice::initialize(int fov, int width, int height)
97 97
 //    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
98 98
 
99 99
 
100
-//    GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0};  /* Red diffuse light. */
100
+//    GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};  /* Red diffuse light. */
101 101
 //    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};  /* Infinite light location. */
102 102
 //    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
103 103
 //    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
@@ -174,12 +174,12 @@ void OpenGLRenderDevice::drawLine(const ColorVector3D &begin, const ColorVector3
174 174
 void OpenGLRenderDevice::drawPolygon(const QList<ColorVector3D> &points)
175 175
 {
176 176
     glBegin(GL_POLYGON);
177
-//    Vector3D p1 = points[0];
178
-//    Vector3D p2 = points[1];
179
-//    Vector3D n = p1.crossProduct(p2);
177
+    Vector3D p1 = points[0] - points[1];
178
+    Vector3D p2 = points[0] - points[2];
179
+    Vector3D n = p1.crossProduct(p2);
180 180
 //    Vector3D n2 = p2.crossProduct(p1);
181 181
 //    qDebug() << n.getX() << n.getY() << n.getZ() << n2.getX() << n2.getY() << n2.getZ();
182
-//    glNormal3d(n.getX(), n.getY(), n.getZ());
182
+    glNormal3d(n.getX(), n.getY(), n.getZ());
183 183
     for (int i = 0; i < points.size(); ++i) {
184 184
         drawVertex(points[i]);
185 185
     }

+ 28
- 7
TheGame/renderwidget.cpp View File

@@ -25,6 +25,7 @@ RenderWidget::RenderWidget(QWidget *parent) :
25 25
 
26 26
     _engine = new UGameEngine(new OpenGLRenderDevice(this));
27 27
     _camera = new FreeFlyCamera(_engine, this);
28
+    _camera->setPosition(Vector3D(0, 1.5, 0));
28 29
 
29 30
     //_engine->addEntity(new UGEEntityAxes(_engine));
30 31
 
@@ -40,8 +41,6 @@ RenderWidget::RenderWidget(QWidget *parent) :
40 41
 
41 42
     int xmax = 25;
42 43
     int zmax = 25;
43
-//    int xmax = 1;
44
-//    int zmax = 1;
45 44
     for (int x = 0; x < xmax; ++x) {
46 45
         for (int z = 0; z < zmax; ++z) {
47 46
             UGEEntityCube* cube = new UGEEntityCube(_engine);
@@ -53,8 +52,25 @@ RenderWidget::RenderWidget(QWidget *parent) :
53 52
     WaveFrontObj* wavefrontObj = new WaveFrontObj(this);
54 53
     wavefrontObj->openFile(_assetsPath + "objs/enterprise/USSEnterprise.obj");
55 54
     UGEEntityWaveFrontObj* obj = new UGEEntityWaveFrontObj(wavefrontObj, _engine);
56
-    obj->hide();
57
-    _entities.append(obj);
55
+    obj->move(Vector3D(0, 15, 0));
56
+
57
+    UGEEntityCube* cube = new UGEEntityCube(_engine);
58
+    cube->move(Vector3D(5, 17, 5));
59
+    cube->setTextureId("dice");
60
+    _entities.append(cube);
61
+    cube = new UGEEntityCube(_engine);
62
+    cube->move(Vector3D(-5, 17, 5));
63
+    cube->setTextureId("dice");
64
+    _entities.append(cube);
65
+    cube = new UGEEntityCube(_engine);
66
+    cube->move(Vector3D(-5, 17, -5));
67
+    cube->setTextureId("dice");
68
+    _entities.append(cube);
69
+    cube = new UGEEntityCube(_engine);
70
+    cube->move(Vector3D(5, 17, -5));
71
+    cube->setTextureId("dice");
72
+    _entities.append(cube);
73
+
58 74
     animate();
59 75
 }
60 76
 
@@ -97,6 +113,11 @@ void RenderWidget::mousePressEvent(QMouseEvent *event)
97 113
         Vector3D bestp;
98 114
         UGEEntity* entity = _engine->getVectorNearestIntesection(_camera->getDirection(), _camera->getPosition(), &bestp);
99 115
         if (entity) {
116
+            for (int i = 0; i < _entities.size(); ++i) {
117
+                if (_entities[i] == entity) {
118
+                    return;
119
+                }
120
+            }
100 121
 //            UGEEntity* axe = new UGEEntityAxes(_engine);
101 122
 //            axe->move(bestp);
102 123
             if (right) {
@@ -183,9 +204,9 @@ void RenderWidget::paintEvent(QPaintEvent *event)
183 204
 
184 205
 void RenderWidget::animate()
185 206
 {
186
-//    for (int i = 0; i < _entities.size(); ++i) {
187
-//        _entities[i]->rotate(Vector3D(0.0, 2.0, 2.0));
188
-//    }
207
+    for (int i = 0; i < _entities.size(); ++i) {
208
+        _entities[i]->rotate(Vector3D(0.0, 2.0, 2.0));
209
+    }
189 210
     QTimer::singleShot(20, this, SLOT(animate()));
190 211
     update();
191 212
 }

+ 2
- 2
UGameEngine/cameras/freeflycamera.cpp View File

@@ -5,8 +5,8 @@
5 5
 FreeFlyCamera::FreeFlyCamera(UGameEngine *engine, QWidget* widget)
6 6
     : AbstractCamera(engine, widget)
7 7
     , _speed(0.2)
8
-    , _phi(45)
9
-    , _theta(45)
8
+    , _phi(270.0)
9
+    , _theta(90.0)
10 10
 {
11 11
     _widget->setCursor(Qt::BlankCursor);
12 12
     _lastPoint = QPoint(_widget->width()/2,_widget->height()/2);

Loading…
Cancel
Save