Browse Source

begin uge entity; begin vector 3d; begin tests

develop
Robin Thoni 7 years ago
parent
commit
a62c67cd7b

+ 2
- 1
UGameEngine.pro View File

@@ -4,4 +4,5 @@ CONFIG += ordered
4 4
 
5 5
 SUBDIRS += \
6 6
     UGameEngine \
7
-    TheGame
7
+    TheGame \
8
+    tests

+ 6
- 2
UGameEngine/UGameEngine.pro View File

@@ -11,10 +11,14 @@ TEMPLATE = lib
11 11
 
12 12
 DEFINES += UGAMEENGINE_LIBRARY
13 13
 
14
-SOURCES += ugameengine.cpp
14
+SOURCES += ugameengine.cpp \
15
+    ugeentity.cpp \
16
+    vector3d.cpp
15 17
 
16 18
 HEADERS += ugameengine.h\
17
-        ugameengine_global.h
19
+        ugameengine_global.h \
20
+    ugeentity.h \
21
+    vector3d.h
18 22
 
19 23
 unix {
20 24
     target.path = /usr/lib

+ 6
- 0
UGameEngine/ugeentity.cpp View File

@@ -0,0 +1,6 @@
1
+#include "ugeentity.h"
2
+
3
+UGEEntity::UGEEntity(QObject *parent) :
4
+    QObject(parent)
5
+{
6
+}

+ 23
- 0
UGameEngine/ugeentity.h View File

@@ -0,0 +1,23 @@
1
+#ifndef UGEENTITY_H
2
+#define UGEENTITY_H
3
+
4
+#include <QObject>
5
+#include <QPoint>
6
+#include "vector3d.h"
7
+
8
+class UGEEntity : public QObject
9
+{
10
+    Q_OBJECT
11
+public:
12
+    explicit UGEEntity(QObject *parent = 0);
13
+
14
+signals:
15
+
16
+public slots:
17
+
18
+private:
19
+    Vector3D _position;
20
+
21
+};
22
+
23
+#endif // UGEENTITY_H

+ 115
- 0
UGameEngine/vector3d.cpp View File

@@ -0,0 +1,115 @@
1
+#include "vector3d.h"
2
+#include <math.h>
3
+
4
+Vector3D::Vector3D(double x, double y, double z)
5
+    : _x(x)
6
+    , _y(y)
7
+    , _z(z)
8
+{
9
+}
10
+
11
+Vector3D::Vector3D(const Vector3D &other)
12
+    : _x(other._x)
13
+    , _y(other._y)
14
+    , _z(other._z)
15
+{
16
+}
17
+
18
+double Vector3D::getX() const
19
+{
20
+    return _x;
21
+}
22
+
23
+Vector3D& Vector3D::setX(double x)
24
+{
25
+    _x = x;
26
+    return *this;
27
+}
28
+double Vector3D::getY() const
29
+{
30
+    return _y;
31
+}
32
+
33
+Vector3D& Vector3D::setY(double y)
34
+{
35
+    _y = y;
36
+    return *this;
37
+}
38
+double Vector3D::getZ() const
39
+{
40
+    return _z;
41
+}
42
+
43
+Vector3D& Vector3D::setZ(double z)
44
+{
45
+    _z = z;
46
+    return *this;
47
+}
48
+
49
+bool Vector3D::isNull() const
50
+{
51
+    return _x == 0 && _y == 0 && _z == 0;
52
+}
53
+
54
+Vector3D &Vector3D::add(double x, double y, double z)
55
+{
56
+    return add(Vector3D(x, y, z));
57
+}
58
+
59
+Vector3D& Vector3D::add(const Vector3D &other)
60
+{
61
+    _x += other._x;
62
+    _y += other._y;
63
+    _z += other._z;
64
+    return *this;
65
+}
66
+
67
+Vector3D &Vector3D::sub(double x, double y, double z)
68
+{
69
+    return sub(Vector3D(x, y, z));
70
+}
71
+
72
+Vector3D& Vector3D::sub(const Vector3D &other)
73
+{
74
+    _x -= other._x;
75
+    _y -= other._y;
76
+    _z -= other._z;
77
+    return *this;
78
+}
79
+
80
+Vector3D &Vector3D::mult(double k)
81
+{
82
+    _x *= k;
83
+    _y *= k;
84
+    _z *= k;
85
+    return *this;
86
+}
87
+
88
+Vector3D &Vector3D::div(double k)
89
+{
90
+    _x /= k;
91
+    _y /= k;
92
+    _z /= k;
93
+    return *this;
94
+}
95
+
96
+double Vector3D::dotProduct(double x, double y, double z) const
97
+{
98
+    return dotProduct(Vector3D(x, y, z));
99
+}
100
+
101
+double Vector3D::dotProduct(const Vector3D &other) const
102
+{
103
+    return (_x * other._x) + (_y * other._y) + (_z * other._z);
104
+}
105
+
106
+double Vector3D::norm() const
107
+{
108
+    return sqrt((_x * _x) + (_y * _y) + (_z * _z));
109
+}
110
+
111
+
112
+Vector3D &operator+(const Vector3D &v1, const Vector3D &v2)
113
+{
114
+    return Vector3D(v1).add(v2);
115
+}

+ 44
- 0
UGameEngine/vector3d.h View File

@@ -0,0 +1,44 @@
1
+#ifndef VECTOR3D_H
2
+#define VECTOR3D_H
3
+
4
+class Vector3D
5
+{
6
+public:
7
+    Vector3D(double x = 0.0, double y = 0.0, double z = 0.0);
8
+    Vector3D(const Vector3D& other);
9
+
10
+    double getX() const;
11
+    Vector3D& setX(double x);
12
+
13
+    double getY() const;
14
+    Vector3D& setY(double y);
15
+
16
+    double getZ() const;
17
+    Vector3D& setZ(double z);
18
+
19
+    bool isNull() const;
20
+
21
+    Vector3D& add(double x, double y, double z);
22
+    Vector3D& add(const Vector3D& other);
23
+
24
+    Vector3D& sub(double x, double y, double z);
25
+    Vector3D& sub(const Vector3D& other);
26
+
27
+    Vector3D& mult(double k);
28
+
29
+    Vector3D& div(double k);
30
+
31
+    double dotProduct(double x, double y, double z) const;
32
+    double dotProduct(const Vector3D& other) const;
33
+
34
+    double norm() const;
35
+
36
+private:
37
+    double _x;
38
+    double _y;
39
+    double _z;
40
+};
41
+
42
+Vector3D& operator+(const Vector3D& v1, const Vector3D& v2);
43
+
44
+#endif // VECTOR3D_H

BIN
tests/tests View File


+ 27
- 0
tests/tests.pro View File

@@ -0,0 +1,27 @@
1
+#-------------------------------------------------
2
+#
3
+# Project created by QtCreator 2016-08-31T17:54:11
4
+#
5
+#-------------------------------------------------
6
+
7
+QT       += core gui testlib
8
+
9
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10
+
11
+TARGET = tests
12
+TEMPLATE = app
13
+
14
+
15
+SOURCES += \
16
+    testvector3d.cpp
17
+
18
+HEADERS  +=
19
+
20
+FORMS    +=
21
+
22
+win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../UGameEngine/release/ -lUGameEngine
23
+else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../UGameEngine/debug/ -lUGameEngine
24
+else:unix: LIBS += -L$$OUT_PWD/../UGameEngine/ -lUGameEngine
25
+
26
+INCLUDEPATH += $$PWD/../UGameEngine
27
+DEPENDPATH += $$PWD/../UGameEngine

+ 30
- 0
tests/testvector3d.cpp View File

@@ -0,0 +1,30 @@
1
+#include <QtTest/QtTest>
2
+#include "vector3d.h"
3
+
4
+class TestVector3D : public QObject
5
+{
6
+    Q_OBJECT
7
+
8
+private slots:
9
+    void gettersSetters1();
10
+    void gettersSetters2();
11
+};
12
+
13
+void TestVector3D::gettersSetters1()
14
+{
15
+    Vector3D v;
16
+    QCOMPARE(v.getX(), 0.0);
17
+    QCOMPARE(v.getY(), 0.0);
18
+    QCOMPARE(v.getZ(), 0.0);
19
+}
20
+
21
+void TestVector3D::gettersSetters2()
22
+{
23
+    Vector3D v(1.42, 2.0, 3.0);
24
+    QCOMPARE(v.getX(), 1.42);
25
+    QCOMPARE(v.getY(), 2.0);
26
+    QCOMPARE(v.getZ(), 3.0);
27
+}
28
+
29
+QTEST_MAIN(TestVector3D)
30
+#include "testvector3d.moc"

+ 95
- 0
tests/testvector3d.moc View File

@@ -0,0 +1,95 @@
1
+/****************************************************************************
2
+** Meta object code from reading C++ file 'testvector3d.cpp'
3
+**
4
+** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.6)
5
+**
6
+** WARNING! All changes made in this file will be lost!
7
+*****************************************************************************/
8
+
9
+#if !defined(Q_MOC_OUTPUT_REVISION)
10
+#error "The header file 'testvector3d.cpp' doesn't include <QObject>."
11
+#elif Q_MOC_OUTPUT_REVISION != 63
12
+#error "This file was generated using the moc from 4.8.6. It"
13
+#error "cannot be used with the include files from this version of Qt."
14
+#error "(The moc has changed too much.)"
15
+#endif
16
+
17
+QT_BEGIN_MOC_NAMESPACE
18
+static const uint qt_meta_data_TestVector3D[] = {
19
+
20
+ // content:
21
+       6,       // revision
22
+       0,       // classname
23
+       0,    0, // classinfo
24
+       2,   14, // methods
25
+       0,    0, // properties
26
+       0,    0, // enums/sets
27
+       0,    0, // constructors
28
+       0,       // flags
29
+       0,       // signalCount
30
+
31
+ // slots: signature, parameters, type, tag, flags
32
+      14,   13,   13,   13, 0x08,
33
+      32,   13,   13,   13, 0x08,
34
+
35
+       0        // eod
36
+};
37
+
38
+static const char qt_meta_stringdata_TestVector3D[] = {
39
+    "TestVector3D\0\0gettersSetters1()\0"
40
+    "gettersSetters2()\0"
41
+};
42
+
43
+void TestVector3D::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
44
+{
45
+    if (_c == QMetaObject::InvokeMetaMethod) {
46
+        Q_ASSERT(staticMetaObject.cast(_o));
47
+        TestVector3D *_t = static_cast<TestVector3D *>(_o);
48
+        switch (_id) {
49
+        case 0: _t->gettersSetters1(); break;
50
+        case 1: _t->gettersSetters2(); break;
51
+        default: ;
52
+        }
53
+    }
54
+    Q_UNUSED(_a);
55
+}
56
+
57
+const QMetaObjectExtraData TestVector3D::staticMetaObjectExtraData = {
58
+    0,  qt_static_metacall 
59
+};
60
+
61
+const QMetaObject TestVector3D::staticMetaObject = {
62
+    { &QObject::staticMetaObject, qt_meta_stringdata_TestVector3D,
63
+      qt_meta_data_TestVector3D, &staticMetaObjectExtraData }
64
+};
65
+
66
+#ifdef Q_NO_DATA_RELOCATION
67
+const QMetaObject &TestVector3D::getStaticMetaObject() { return staticMetaObject; }
68
+#endif //Q_NO_DATA_RELOCATION
69
+
70
+const QMetaObject *TestVector3D::metaObject() const
71
+{
72
+    return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
73
+}
74
+
75
+void *TestVector3D::qt_metacast(const char *_clname)
76
+{
77
+    if (!_clname) return 0;
78
+    if (!strcmp(_clname, qt_meta_stringdata_TestVector3D))
79
+        return static_cast<void*>(const_cast< TestVector3D*>(this));
80
+    return QObject::qt_metacast(_clname);
81
+}
82
+
83
+int TestVector3D::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
84
+{
85
+    _id = QObject::qt_metacall(_c, _id, _a);
86
+    if (_id < 0)
87
+        return _id;
88
+    if (_c == QMetaObject::InvokeMetaMethod) {
89
+        if (_id < 2)
90
+            qt_static_metacall(this, _c, _id, _a);
91
+        _id -= 2;
92
+    }
93
+    return _id;
94
+}
95
+QT_END_MOC_NAMESPACE

Loading…
Cancel
Save