Browse Source

get position/direction from camera

develop
Robin Thoni 8 years ago
parent
commit
1e2bfaa791

+ 2
- 1
TheGame/renderwidget.cpp View File

65
 {
65
 {
66
     _camera->mousePressEvent(event);
66
     _camera->mousePressEvent(event);
67
     if (event->buttons() & Qt::LeftButton) {
67
     if (event->buttons() & Qt::LeftButton) {
68
-        Vector3D pos = _engine->get3DFrom2D(Vector2D(event->x(), height() - event->y()));
68
+//        Vector3D pos = _engine->get3DFrom2D(Vector2D(event->x(), height() - event->y()));
69
+        Vector3D pos = _camera->getDirection();
69
         qDebug() << pos.getX() << pos.getY() << pos.getZ();
70
         qDebug() << pos.getX() << pos.getY() << pos.getZ();
70
     }
71
     }
71
 }
72
 }

+ 20
- 0
UGameEngine/cameras/abstractcamera.cpp View File

40
 {
40
 {
41
     (void) event;
41
     (void) event;
42
 }
42
 }
43
+Vector3D AbstractCamera::getDirection() const
44
+{
45
+    return _direction;
46
+}
47
+
48
+void AbstractCamera::setDirection(const Vector3D &direction)
49
+{
50
+    _direction = direction;
51
+}
52
+Vector3D AbstractCamera::getPosition() const
53
+{
54
+    return _position;
55
+}
56
+
57
+void AbstractCamera::setPosition(const Vector3D &position)
58
+{
59
+    _position = position;
60
+}
61
+
62
+
43
 
63
 

+ 10
- 0
UGameEngine/cameras/abstractcamera.h View File

25
 
25
 
26
     virtual void updateLookAt() = 0;
26
     virtual void updateLookAt() = 0;
27
 
27
 
28
+    Vector3D getDirection() const;
29
+    void setDirection(const Vector3D &getDirection);
30
+
31
+    Vector3D getPosition() const;
32
+    void setPosition(const Vector3D &getPosition);
33
+
28
 protected:
34
 protected:
29
     UGameEngine* _engine;
35
     UGameEngine* _engine;
30
 
36
 
31
     QWidget* _widget;
37
     QWidget* _widget;
38
+
39
+    Vector3D _direction;
40
+
41
+    Vector3D _position;
32
 };
42
 };
33
 
43
 
34
 #endif // ABSTRACTCAMERA_H
44
 #endif // ABSTRACTCAMERA_H

+ 0
- 3
UGameEngine/cameras/freeflycamera.h View File

19
     void rotate(float phi, float theta);
19
     void rotate(float phi, float theta);
20
 
20
 
21
 private:
21
 private:
22
-    Vector3D _direction;
23
-
24
-    Vector3D _position;
25
 
22
 
26
     Vector2D _speedVector;
23
     Vector2D _speedVector;
27
 
24
 

+ 3
- 2
UGameEngine/cameras/rotationcamera.cpp View File

50
 {
50
 {
51
     float theta = fabs(_theta / 180.0 * M_PI);
51
     float theta = fabs(_theta / 180.0 * M_PI);
52
     float phi = _phi / 180.0 * M_PI;
52
     float phi = _phi / 180.0 * M_PI;
53
-    Vector3D center = Vector3D(
53
+    _position = Vector3D(
54
                 _radius * sin(theta) * sin(phi),
54
                 _radius * sin(theta) * sin(phi),
55
                 _radius * cos(theta),
55
                 _radius * cos(theta),
56
                 _radius * sin(theta) * cos(phi)
56
                 _radius * sin(theta) * cos(phi)
57
                 );
57
                 );
58
-    _engine->lookAt(center, Vector3D(0.0f, 0.0f, 0.0f));
58
+    _direction = -_position;
59
+    _engine->lookAt(_position, Vector3D(0.0f, 0.0f, 0.0f));
59
 }
60
 }
60
 
61
 
61
 void RotationCamera::rotate(float phi, float theta)
62
 void RotationCamera::rotate(float phi, float theta)

Loading…
Cancel
Save