Browse Source

added vector cross product; added signals in ugeentities

develop
Robin Thoni 8 years ago
parent
commit
d62b6da1e5

+ 44
- 13
UGameEngine/entities/ugeentity.cpp View File

18
 void UGEEntity::setPosition(const Vector3D &position)
18
 void UGEEntity::setPosition(const Vector3D &position)
19
 {
19
 {
20
     _position = position;
20
     _position = position;
21
+    emit positionChanged();
22
+    emit positionChanged(_position);
21
 }
23
 }
22
 
24
 
23
 void UGEEntity::move(const Vector3D &move)
25
 void UGEEntity::move(const Vector3D &move)
24
 {
26
 {
25
     _position += move;
27
     _position += move;
28
+    emit positionChanged();
29
+    emit positionChanged(_position);
26
 }
30
 }
27
 
31
 
28
-Vector3D UGEEntity::getSpeed() const
29
-{
30
-    return _speed;
31
-}
32
+//Vector3D UGEEntity::getSpeed() const
33
+//{
34
+//    return _speed;
35
+//}
32
 
36
 
33
-void UGEEntity::setSpeed(const Vector3D &speed)
34
-{
35
-    _speed = speed;
36
-}
37
+//void UGEEntity::setSpeed(const Vector3D &speed)
38
+//{
39
+//    _speed = speed;
40
+//}
37
 
41
 
38
-void UGEEntity::accelerate(const Vector3D &speed)
39
-{
40
-    _speed += speed;
41
-}
42
+//void UGEEntity::accelerate(const Vector3D &speed)
43
+//{
44
+//    _speed += speed;
45
+//}
42
 
46
 
43
 Vector3D UGEEntity::getRotation() const
47
 Vector3D UGEEntity::getRotation() const
44
 {
48
 {
48
 void UGEEntity::setRotation(const Vector3D &rotation)
52
 void UGEEntity::setRotation(const Vector3D &rotation)
49
 {
53
 {
50
     _rotation = rotation;
54
     _rotation = rotation;
55
+    emit rotationChanged();
56
+    emit rotationChanged(rotation);
51
 }
57
 }
52
 
58
 
53
 void UGEEntity::rotate(const Vector3D &rotation)
59
 void UGEEntity::rotate(const Vector3D &rotation)
54
 {
60
 {
55
     _rotation += rotation;
61
     _rotation += rotation;
62
+    emit rotationChanged();
63
+    emit rotationChanged(rotation);
56
 }
64
 }
57
 
65
 
58
 Vector3D UGEEntity::getScale() const
66
 Vector3D UGEEntity::getScale() const
63
 void UGEEntity::setScale(const Vector3D &scale)
71
 void UGEEntity::setScale(const Vector3D &scale)
64
 {
72
 {
65
     _scale = scale;
73
     _scale = scale;
74
+    emit scaleChanged();
75
+    emit scaleChanged(_scale);
66
 }
76
 }
67
 
77
 
68
 void UGEEntity::scale(const Vector3D &scale)
78
 void UGEEntity::scale(const Vector3D &scale)
69
 {
79
 {
70
     _scale += scale;
80
     _scale += scale;
81
+    emit scaleChanged();
82
+    emit scaleChanged(_scale);
71
 }
83
 }
72
 bool UGEEntity::isVisible() const
84
 bool UGEEntity::isVisible() const
73
 {
85
 {
77
 void UGEEntity::setVisible(bool visible)
89
 void UGEEntity::setVisible(bool visible)
78
 {
90
 {
79
     _visible = visible;
91
     _visible = visible;
92
+    emit visibilityChanged();
93
+    emit visibilityChanged(_visible);
80
 }
94
 }
81
 
95
 
82
 void UGEEntity::show()
96
 void UGEEntity::show()
83
 {
97
 {
84
     _visible = true;
98
     _visible = true;
99
+    emit visibilityChanged();
100
+    emit visibilityChanged(_visible);
85
 }
101
 }
86
 
102
 
87
 void UGEEntity::hide()
103
 void UGEEntity::hide()
88
 {
104
 {
89
     _visible = false;
105
     _visible = false;
106
+    emit visibilityChanged();
107
+    emit visibilityChanged(_visible);
108
+}
109
+
110
+QColor UGEEntity::getColor() const
111
+{
112
+    return _color;
113
+}
114
+
115
+void UGEEntity::setColor(const QColor &color)
116
+{
117
+    _color = color;
118
+    emit colorChanged();
119
+    emit colorChanged(_color);
90
 }
120
 }
91
 
121
 
92
 Vector3D UGEEntity::getRealPoint(const Vector3D &pos)
122
 Vector3D UGEEntity::getRealPoint(const Vector3D &pos)
93
 {
123
 {
94
-    return pos + _position;
124
+    Vector3D p = pos + _position;
125
+    return p;
95
 }
126
 }
96
 
127
 
97
 ColorVector3D UGEEntity::getRealPoint(const ColorVector3D &pos)
128
 ColorVector3D UGEEntity::getRealPoint(const ColorVector3D &pos)

+ 25
- 4
UGameEngine/entities/ugeentity.h View File

18
     void setPosition(const Vector3D& position);
18
     void setPosition(const Vector3D& position);
19
     void move(const Vector3D& move);
19
     void move(const Vector3D& move);
20
 
20
 
21
-    Vector3D getSpeed() const;
22
-    void setSpeed(const Vector3D& speed);
23
-    void accelerate(const Vector3D& speed);
21
+//    Vector3D getSpeed() const;
22
+//    void setSpeed(const Vector3D& speed);
23
+//    void accelerate(const Vector3D& speed);
24
 
24
 
25
     Vector3D getRotation() const;
25
     Vector3D getRotation() const;
26
     void setRotation(const Vector3D& rotation);
26
     void setRotation(const Vector3D& rotation);
35
     void show();
35
     void show();
36
     void hide();
36
     void hide();
37
 
37
 
38
+    QColor getColor() const;
39
+    void setColor(const QColor &color);
40
+
38
     Vector3D getRealPoint(const Vector3D& pos);
41
     Vector3D getRealPoint(const Vector3D& pos);
39
     ColorVector3D getRealPoint(const ColorVector3D& pos);
42
     ColorVector3D getRealPoint(const ColorVector3D& pos);
40
     TextureVector3D getRealPoint(const TextureVector3D& pos);
43
     TextureVector3D getRealPoint(const TextureVector3D& pos);
49
 
52
 
50
     virtual void draw(AbstractRenderDevice* device) = 0;
53
     virtual void draw(AbstractRenderDevice* device) = 0;
51
 
54
 
55
+signals:
56
+    void positionChanged();
57
+    void positionChanged(const Vector3D& position);
58
+
59
+    void rotationChanged();
60
+    void rotationChanged(const Vector3D& rotation);
61
+
62
+    void scaleChanged();
63
+    void scaleChanged(const Vector3D& scale);
64
+
65
+    void visibilityChanged();
66
+    void visibilityChanged(bool visible);
67
+
68
+    void colorChanged();
69
+    void colorChanged(QColor color);
70
+
52
 private:
71
 private:
53
     Vector3D _position;
72
     Vector3D _position;
54
 
73
 
55
-    Vector3D _speed;
74
+//    Vector3D _speed;
56
 
75
 
57
     Vector3D _rotation;
76
     Vector3D _rotation;
58
 
77
 
60
 
79
 
61
     bool _visible;
80
     bool _visible;
62
 
81
 
82
+    QColor _color;
83
+
63
 };
84
 };
64
 
85
 
65
 #endif // UGEENTITY_H
86
 #endif // UGEENTITY_H

+ 73
- 45
UGameEngine/entities/ugeentitycube.cpp View File

4
     : UGEEntity(parent)
4
     : UGEEntity(parent)
5
     , _size(1.0)
5
     , _size(1.0)
6
 {
6
 {
7
+    updateFaces();
8
+    connect(this, SIGNAL(colorChanged()), this, SLOT(updateFaces()));
9
+    connect(this, SIGNAL(sizeChanged()), this, SLOT(updateFaces()));
10
+    connect(this, SIGNAL(textureChanged()), this, SLOT(updateFaces()));
7
 }
11
 }
8
 
12
 
9
-float UGEEntityCube::getSize() const
13
+double UGEEntityCube::getSize() const
10
 {
14
 {
11
     return _size;
15
     return _size;
12
 }
16
 }
13
 
17
 
14
 void UGEEntityCube::draw(AbstractRenderDevice *device)
18
 void UGEEntityCube::draw(AbstractRenderDevice *device)
15
 {
19
 {
16
-    float r = _size / 2;
17
-    if (_textureId.isNull()) {
18
-        QColor color = Qt::red;
19
-        QList<ColorVector3D> points;
20
-        points << ColorVector3D(color, -r, -r, r)  << ColorVector3D(color, -r, r, r)
21
-               << ColorVector3D(color, r, r, r)    << ColorVector3D(color, r, -r, r)
22
-               << ColorVector3D(color, -r, -r, -r) << ColorVector3D(color, -r, r, -r)
23
-               << ColorVector3D(color, r, r, -r)   << ColorVector3D(color, r, -r, -r);
24
-        drawPolygon(device, QList<ColorVector3D>() << points[3] << points[2] << points[1] << points[0]);
25
-        drawPolygon(device, QList<ColorVector3D>() << points[2] << points[3] << points[7] << points[6]);
26
-        drawPolygon(device, QList<ColorVector3D>() << points[6] << points[7] << points[4] << points[5]);
27
-        drawPolygon(device, QList<ColorVector3D>() << points[5] << points[4] << points[0] << points[1]);
28
-        drawPolygon(device, QList<ColorVector3D>() << points[1] << points[2] << points[6] << points[5]);
29
-        drawPolygon(device, QList<ColorVector3D>() << points[4] << points[7] << points[3] << points[0]);
20
+    if (!_facesColor.empty()) {
21
+        for (int i = 0; i < _facesColor.size(); ++i) {
22
+            drawPolygon(device, _facesColor[i]);
23
+        }
30
     }
24
     }
31
     else {
25
     else {
32
-        QColor color = Qt::white;
33
-        drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), color, r, -r, r)
34
-                           << TextureVector3D(Vector2D(0.25, 0.25), color, r, r, r)
35
-                           << TextureVector3D(Vector2D(0.00, 0.25), color, -r, r, r)
36
-                           << TextureVector3D(Vector2D(0.00, 0.50), color, -r, -r, r), _textureId);
37
-        drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), color, r, r, r)
38
-                           << TextureVector3D(Vector2D(0.25, 0.25), color, r, -r, r)
39
-                           << TextureVector3D(Vector2D(0.50, 0.25), color, r, -r, -r)
40
-                           << TextureVector3D(Vector2D(0.50, 0.50), color, r, r, -r), _textureId);
41
-        drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.25), color, r, r, -r)
42
-                           << TextureVector3D(Vector2D(0.50, 0.50), color, r, -r, -r)
43
-                           << TextureVector3D(Vector2D(0.75, 0.50), color, -r, -r, -r)
44
-                           << TextureVector3D(Vector2D(0.75, 0.25), color, -r, r, -r), _textureId);
45
-        drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.75, 0.25), color, -r, r, -r)
46
-                           << TextureVector3D(Vector2D(0.75, 0.50), color, -r, -r, -r)
47
-                           << TextureVector3D(Vector2D(1.00, 0.50), color, -r, -r, r)
48
-                           << TextureVector3D(Vector2D(1.00, 0.25), color, -r, r, r), _textureId);
49
-        drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.00), color, -r, r, r)
50
-                           << TextureVector3D(Vector2D(0.25, 0.25), color, r, r, r)
51
-                           << TextureVector3D(Vector2D(0.50, 0.25), color, r, r, -r)
52
-                           << TextureVector3D(Vector2D(0.50, 0.00), color, -r, r, -r), _textureId);
53
-        drawPolygonTexture(device, QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.75), color, -r, -r, -r)
54
-                           << TextureVector3D(Vector2D(0.50, 0.50), color, r, -r, -r)
55
-                           << TextureVector3D(Vector2D(0.25, 0.5), color, r, -r, r)
56
-                           << TextureVector3D(Vector2D(0.25, 0.75), color, -r, -r, r), _textureId);
26
+        for (int i = 0; i < _facesTexture.size(); ++i) {
27
+            drawPolygonTexture(device, _facesTexture[i], _textureId);
28
+        }
57
     }
29
     }
58
 }
30
 }
59
 
31
 
60
-QVariant UGEEntityCube::getTextureId() const
32
+void UGEEntityCube::setSize(double size)
61
 {
33
 {
62
-    return _textureId;
34
+    _size = size;
35
+    emit sizeChanged();
36
+    emit sizeChanged(_size);
63
 }
37
 }
64
 
38
 
65
-void UGEEntityCube::setSize(float size)
39
+void UGEEntityCube::increaseSize(double size)
66
 {
40
 {
67
-    _size = size;
41
+    _size += size;
42
+    emit sizeChanged();
43
+    emit sizeChanged(_size);
44
+}
45
+
46
+QVariant UGEEntityCube::getTextureId() const
47
+{
48
+    return _textureId;
68
 }
49
 }
69
 
50
 
70
 void UGEEntityCube::setTextureId(const QVariant &textureId)
51
 void UGEEntityCube::setTextureId(const QVariant &textureId)
71
 {
52
 {
72
     _textureId = textureId;
53
     _textureId = textureId;
54
+    setColor(Qt::white);
55
+    emit textureChanged();
56
+    emit textureChanged(_textureId);
73
 }
57
 }
74
 
58
 
75
-
59
+void UGEEntityCube::updateFaces()
60
+{
61
+    _facesColor.clear();
62
+    _facesTexture.clear();
63
+    double r = _size / 2;
64
+    if (_textureId.isNull()) {
65
+        QList<ColorVector3D> points;
66
+        points << ColorVector3D(getColor(), -r, -r, r)  << ColorVector3D(getColor(), -r, r, r)
67
+               << ColorVector3D(getColor(), r, r, r)    << ColorVector3D(getColor(), r, -r, r)
68
+               << ColorVector3D(getColor(), -r, -r, -r) << ColorVector3D(getColor(), -r, r, -r)
69
+               << ColorVector3D(getColor(), r, r, -r)   << ColorVector3D(getColor(), r, -r, -r);
70
+        _facesColor.append(QList<ColorVector3D>() << points[3] << points[2] << points[1] << points[0]);
71
+        _facesColor.append(QList<ColorVector3D>() << points[2] << points[3] << points[7] << points[6]);
72
+        _facesColor.append(QList<ColorVector3D>() << points[6] << points[7] << points[4] << points[5]);
73
+        _facesColor.append(QList<ColorVector3D>() << points[5] << points[4] << points[0] << points[1]);
74
+        _facesColor.append(QList<ColorVector3D>() << points[1] << points[2] << points[6] << points[5]);
75
+        _facesColor.append(QList<ColorVector3D>() << points[4] << points[7] << points[3] << points[0]);
76
+    }
77
+    else {
78
+        _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), getColor(), r, -r, r)
79
+                             << TextureVector3D(Vector2D(0.25, 0.25), getColor(), r, r, r)
80
+                             << TextureVector3D(Vector2D(0.00, 0.25), getColor(), -r, r, r)
81
+                             << TextureVector3D(Vector2D(0.00, 0.50), getColor(), -r, -r, r));
82
+        _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.50), getColor(), r, r, r)
83
+                             << TextureVector3D(Vector2D(0.25, 0.25), getColor(), r, -r, r)
84
+                             << TextureVector3D(Vector2D(0.50, 0.25), getColor(), r, -r, -r)
85
+                             << TextureVector3D(Vector2D(0.50, 0.50), getColor(), r, r, -r));
86
+        _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.25), getColor(), r, r, -r)
87
+                             << TextureVector3D(Vector2D(0.50, 0.50), getColor(), r, -r, -r)
88
+                             << TextureVector3D(Vector2D(0.75, 0.50), getColor(), -r, -r, -r)
89
+                             << TextureVector3D(Vector2D(0.75, 0.25), getColor(), -r, r, -r));
90
+        _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.75, 0.25), getColor(), -r, r, -r)
91
+                             << TextureVector3D(Vector2D(0.75, 0.50), getColor(), -r, -r, -r)
92
+                             << TextureVector3D(Vector2D(1.00, 0.50), getColor(), -r, -r, r)
93
+                             << TextureVector3D(Vector2D(1.00, 0.25), getColor(), -r, r, r));
94
+        _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.25, 0.00), getColor(), -r, r, r)
95
+                             << TextureVector3D(Vector2D(0.25, 0.25), getColor(), r, r, r)
96
+                             << TextureVector3D(Vector2D(0.50, 0.25), getColor(), r, r, -r)
97
+                             << TextureVector3D(Vector2D(0.50, 0.00), getColor(), -r, r, -r));
98
+        _facesTexture.append(QList<TextureVector3D>() << TextureVector3D(Vector2D(0.50, 0.75), getColor(), -r, -r, -r)
99
+                             << TextureVector3D(Vector2D(0.50, 0.50), getColor(), r, -r, -r)
100
+                             << TextureVector3D(Vector2D(0.25, 0.5), getColor(), r, -r, r)
101
+                             << TextureVector3D(Vector2D(0.25, 0.75), getColor(), -r, -r, r));
102
+    }
103
+}

+ 20
- 5
UGameEngine/entities/ugeentitycube.h View File

9
 public:
9
 public:
10
     explicit UGEEntityCube(QObject *parent = 0);
10
     explicit UGEEntityCube(QObject *parent = 0);
11
 
11
 
12
-    float getSize() const;
13
-
14
-    virtual void draw(AbstractRenderDevice* device);
12
+    double getSize() const;
15
 
13
 
16
     QVariant getTextureId() const;
14
     QVariant getTextureId() const;
17
 
15
 
16
+    virtual void draw(AbstractRenderDevice* device);
17
+
18
 signals:
18
 signals:
19
+    void sizeChanged();
20
+    void sizeChanged(double);
21
+
22
+    void textureChanged();
23
+    void textureChanged(const QVariant& textureId);
19
 
24
 
20
 public slots:
25
 public slots:
21
-    void setSize(float size);
26
+    void setSize(double size);
27
+    void increaseSize(double size);
28
+
22
     void setTextureId(const QVariant &textureId);
29
     void setTextureId(const QVariant &textureId);
23
 
30
 
31
+private slots:
32
+    void updateFaces();
33
+
24
 private:
34
 private:
25
-    float _size;
35
+    double _size;
36
+
26
     QVariant _textureId;
37
     QVariant _textureId;
27
 
38
 
39
+    QList<QList<TextureVector3D> > _facesTexture;
40
+
41
+    QList<QList<ColorVector3D> > _facesColor;
42
+
28
 };
43
 };
29
 
44
 
30
 #endif // UGEENTITYCUBE_H
45
 #endif // UGEENTITYCUBE_H

+ 3
- 1
UGameEngine/utils/vectorxd.h View File

28
     VectorXD<X>& sub(const VectorXD<X>& other);
28
     VectorXD<X>& sub(const VectorXD<X>& other);
29
 
29
 
30
     VectorXD<X>& mult(double k);
30
     VectorXD<X>& mult(double k);
31
+    VectorXD<X>& mult(const VectorXD<X>& k);
31
 
32
 
32
     VectorXD<X>& div(double k);
33
     VectorXD<X>& div(double k);
33
 
34
 
34
     double dotProduct(const VectorXD<X>& other) const;
35
     double dotProduct(const VectorXD<X>& other) const;
36
+    VectorXD<X>& crossProduct(const VectorXD<X>& other);
35
 
37
 
36
     double norm() const;
38
     double norm() const;
37
 
39
 
49
 
51
 
50
     VectorXD<X> operator*(const double& k) const;
52
     VectorXD<X> operator*(const double& k) const;
51
     VectorXD<X>& operator*=(const double& k);
53
     VectorXD<X>& operator*=(const double& k);
52
-    double operator*(const VectorXD<X>& other) const;
54
+    VectorXD<X> operator*(const VectorXD<X>& other) const;
53
     VectorXD<X>& operator*=(const VectorXD<X>& other);
55
     VectorXD<X>& operator*=(const VectorXD<X>& other);
54
 
56
 
55
     VectorXD<X> operator/(const double& k) const;
57
     VectorXD<X> operator/(const double& k) const;

+ 21
- 2
UGameEngine/utils/vectorxd.hxx View File

101
     return *this;
101
     return *this;
102
 }
102
 }
103
 
103
 
104
+tmpl VectorXD<X> &VectorXD<X>::mult(const VectorXD<X> &other)
105
+{
106
+    for (unsigned i = 0; i < X; ++i) {
107
+        _scalars[i] *= other._scalars[i];
108
+    }
109
+    return *this;
110
+}
111
+
104
 tmpl VectorXD<X> &VectorXD<X>::div(double k)
112
 tmpl VectorXD<X> &VectorXD<X>::div(double k)
105
 {
113
 {
106
     for (unsigned i = 0; i < X; ++i) {
114
     for (unsigned i = 0; i < X; ++i) {
118
     return total;
126
     return total;
119
 }
127
 }
120
 
128
 
129
+tmpl VectorXD<X>& VectorXD<X>::crossProduct(const VectorXD<X>& other)
130
+{
131
+    VectorXD<X> t = *this;
132
+    for (unsigned i = 0; i < X; ++i) {
133
+        unsigned j = (i + 1) % X;
134
+        unsigned k = (i + 2) % X;
135
+        _scalars[i] = (t._scalars[j] * other._scalars[k]) - (t._scalars[k] * other._scalars[j]);
136
+    }
137
+    return *this;
138
+}
139
+
121
 tmpl double VectorXD<X>::norm() const
140
 tmpl double VectorXD<X>::norm() const
122
 {
141
 {
123
     double total = 0;
142
     double total = 0;
191
     return mult(k);
210
     return mult(k);
192
 }
211
 }
193
 
212
 
194
-tmpl double VectorXD<X>::operator*(const VectorXD<X> &other) const
213
+tmpl VectorXD<X> VectorXD<X>::operator*(const VectorXD<X> &other) const
195
 {
214
 {
196
-    return VectorXD<X>(*this).dotProduct(other);
215
+    return VectorXD<X>(*this).mult(other);
197
 }
216
 }
198
 
217
 
199
 tmpl VectorXD<X> &VectorXD<X>::operator*=(const VectorXD<X> &other)
218
 tmpl VectorXD<X> &VectorXD<X>::operator*=(const VectorXD<X> &other)

+ 46
- 17
tests/testvector3d.cpp View File

35
     void sub3Op();
35
     void sub3Op();
36
 
36
 
37
     void mult();
37
     void mult();
38
-    void multOp();
38
+    void mult1Op();
39
+    void mult2Op();
40
+    void mult3Op();
39
 
41
 
40
     void div();
42
     void div();
41
     void divOp();
43
     void divOp();
42
 
44
 
43
     void dotProduct1();
45
     void dotProduct1();
44
-    void dotProduct1Op();
45
     void dotProduct2();
46
     void dotProduct2();
46
-    void dotProduct2Op();
47
+
48
+    void crossProduct1();
49
+    void crossProduct2();
47
 
50
 
48
     void norm1();
51
     void norm1();
49
     void norm2();
52
     void norm2();
294
     QCOMPARE(v.getZ(), z * m);
297
     QCOMPARE(v.getZ(), z * m);
295
 }
298
 }
296
 
299
 
297
-void TestVector3D::multOp()
300
+void TestVector3D::mult1Op()
298
 {
301
 {
299
     double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
302
     double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
300
     Vector3D v1(x, y, z);
303
     Vector3D v1(x, y, z);
304
     QCOMPARE(v.getZ(), z * m);
307
     QCOMPARE(v.getZ(), z * m);
305
 }
308
 }
306
 
309
 
310
+void TestVector3D::mult2Op()
311
+{
312
+    Vector3D v1(1.5, 2.0, 3.0);
313
+    Vector3D v2(42.0, 5.0, 7.0);
314
+    Vector3D v = v1 * v2;
315
+    QCOMPARE(v.getX(), v1.getX() * v2.getX());
316
+    QCOMPARE(v.getY(), v1.getY() * v2.getY());
317
+    QCOMPARE(v.getZ(), v1.getZ() * v2.getZ());
318
+}
319
+
320
+void TestVector3D::mult3Op()
321
+{
322
+    Vector3D v1(20.0, 42.0, 10.0);
323
+    Vector3D v2(42.0, 5.0, 7.0);
324
+    Vector3D v = v1 * v2;
325
+    QCOMPARE(v.getX(), v1.getX() * v2.getX());
326
+    QCOMPARE(v.getY(), v1.getY() * v2.getY());
327
+    QCOMPARE(v.getZ(), v1.getZ() * v2.getZ());
328
+}
329
+
307
 void TestVector3D::div()
330
 void TestVector3D::div()
308
 {
331
 {
309
     double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
332
     double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
331
     QCOMPARE(v1.dotProduct(v2), 94.0);
354
     QCOMPARE(v1.dotProduct(v2), 94.0);
332
 }
355
 }
333
 
356
 
334
-void TestVector3D::dotProduct1Op()
335
-{
336
-    Vector3D v1(1.5, 2.0, 3.0);
337
-    Vector3D v2(42.0, 5.0, 7.0);
338
-    QCOMPARE(v1 * v2, 94.0);
339
-}
340
-
341
 void TestVector3D::dotProduct2()
357
 void TestVector3D::dotProduct2()
342
 {
358
 {
343
     Vector3D v1(20, 42, 10);
359
     Vector3D v1(20, 42, 10);
345
     QCOMPARE(v1.dotProduct(v2), 1120.0);
361
     QCOMPARE(v1.dotProduct(v2), 1120.0);
346
 }
362
 }
347
 
363
 
348
-void TestVector3D::dotProduct2Op()
364
+void TestVector3D::crossProduct1()
349
 {
365
 {
350
-    Vector3D v1(20, 42, 10);
351
-    Vector3D v2(42.0, 5.0, 7.0);
352
-    QCOMPARE(v1 * v2, 1120.0);
366
+    Vector3D v(10.0, 42.0, 5.0);
367
+    Vector3D v2(9.0, 5.0, 4.0);
368
+    v.crossProduct(v2);
369
+    QCOMPARE(v.getX(), 143.0);
370
+    QCOMPARE(v.getY(), 5.0);
371
+    QCOMPARE(v.getZ(), -328.0);
372
+}
373
+
374
+void TestVector3D::crossProduct2()
375
+{
376
+    Vector3D v(10.0, 24.0, 8.0);
377
+    Vector3D v2(15.0, 5.0, 0.0);
378
+    v.crossProduct(v2);
379
+    QCOMPARE(v.getX(), -40.0);
380
+    QCOMPARE(v.getY(), 120.0);
381
+    QCOMPARE(v.getZ(), -310.0);
353
 }
382
 }
354
 
383
 
355
 void TestVector3D::norm1()
384
 void TestVector3D::norm1()
356
 {
385
 {
357
-    Vector3D v(3, 4, 0);;
386
+    Vector3D v(3.0, 4.0, 0.0);;
358
     QCOMPARE(v.norm(), 5.0);
387
     QCOMPARE(v.norm(), 5.0);
359
 }
388
 }
360
 
389
 
361
 void TestVector3D::norm2()
390
 void TestVector3D::norm2()
362
 {
391
 {
363
-    Vector3D v(0, 30, 40);;
392
+    Vector3D v(0.0, 30.0, 40.0);;
364
     QCOMPARE(v.norm(), 50.0);
393
     QCOMPARE(v.norm(), 50.0);
365
 }
394
 }
366
 
395
 

Loading…
Cancel
Save