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
 //    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
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
 //    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};  /* Infinite light location. */
101
 //    GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};  /* Infinite light location. */
102
 //    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
102
 //    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
103
 //    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
103
 //    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
174
 void OpenGLRenderDevice::drawPolygon(const QList<ColorVector3D> &points)
174
 void OpenGLRenderDevice::drawPolygon(const QList<ColorVector3D> &points)
175
 {
175
 {
176
     glBegin(GL_POLYGON);
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
 //    Vector3D n2 = p2.crossProduct(p1);
180
 //    Vector3D n2 = p2.crossProduct(p1);
181
 //    qDebug() << n.getX() << n.getY() << n.getZ() << n2.getX() << n2.getY() << n2.getZ();
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
     for (int i = 0; i < points.size(); ++i) {
183
     for (int i = 0; i < points.size(); ++i) {
184
         drawVertex(points[i]);
184
         drawVertex(points[i]);
185
     }
185
     }

+ 28
- 7
TheGame/renderwidget.cpp View File

25
 
25
 
26
     _engine = new UGameEngine(new OpenGLRenderDevice(this));
26
     _engine = new UGameEngine(new OpenGLRenderDevice(this));
27
     _camera = new FreeFlyCamera(_engine, this);
27
     _camera = new FreeFlyCamera(_engine, this);
28
+    _camera->setPosition(Vector3D(0, 1.5, 0));
28
 
29
 
29
     //_engine->addEntity(new UGEEntityAxes(_engine));
30
     //_engine->addEntity(new UGEEntityAxes(_engine));
30
 
31
 
40
 
41
 
41
     int xmax = 25;
42
     int xmax = 25;
42
     int zmax = 25;
43
     int zmax = 25;
43
-//    int xmax = 1;
44
-//    int zmax = 1;
45
     for (int x = 0; x < xmax; ++x) {
44
     for (int x = 0; x < xmax; ++x) {
46
         for (int z = 0; z < zmax; ++z) {
45
         for (int z = 0; z < zmax; ++z) {
47
             UGEEntityCube* cube = new UGEEntityCube(_engine);
46
             UGEEntityCube* cube = new UGEEntityCube(_engine);
53
     WaveFrontObj* wavefrontObj = new WaveFrontObj(this);
52
     WaveFrontObj* wavefrontObj = new WaveFrontObj(this);
54
     wavefrontObj->openFile(_assetsPath + "objs/enterprise/USSEnterprise.obj");
53
     wavefrontObj->openFile(_assetsPath + "objs/enterprise/USSEnterprise.obj");
55
     UGEEntityWaveFrontObj* obj = new UGEEntityWaveFrontObj(wavefrontObj, _engine);
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
     animate();
74
     animate();
59
 }
75
 }
60
 
76
 
97
         Vector3D bestp;
113
         Vector3D bestp;
98
         UGEEntity* entity = _engine->getVectorNearestIntesection(_camera->getDirection(), _camera->getPosition(), &bestp);
114
         UGEEntity* entity = _engine->getVectorNearestIntesection(_camera->getDirection(), _camera->getPosition(), &bestp);
99
         if (entity) {
115
         if (entity) {
116
+            for (int i = 0; i < _entities.size(); ++i) {
117
+                if (_entities[i] == entity) {
118
+                    return;
119
+                }
120
+            }
100
 //            UGEEntity* axe = new UGEEntityAxes(_engine);
121
 //            UGEEntity* axe = new UGEEntityAxes(_engine);
101
 //            axe->move(bestp);
122
 //            axe->move(bestp);
102
             if (right) {
123
             if (right) {
183
 
204
 
184
 void RenderWidget::animate()
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
     QTimer::singleShot(20, this, SLOT(animate()));
210
     QTimer::singleShot(20, this, SLOT(animate()));
190
     update();
211
     update();
191
 }
212
 }

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

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

Loading…
Cancel
Save