Browse Source

added static cross product; tests

develop
Robin Thoni 7 years ago
parent
commit
7862666b44
3 changed files with 18 additions and 0 deletions
  1. 2
    0
      UGameEngine/utils/vectorxd.h
  2. 5
    0
      UGameEngine/utils/vectorxd.hxx
  3. 11
    0
      tests/testvector3d.cpp

+ 2
- 0
UGameEngine/utils/vectorxd.h View File

33
     VectorXD<X>& div(double k);
33
     VectorXD<X>& div(double k);
34
 
34
 
35
     double dotProduct(const VectorXD<X>& other) const;
35
     double dotProduct(const VectorXD<X>& other) const;
36
+
36
     VectorXD<X>& crossProduct(const VectorXD<X>& other);
37
     VectorXD<X>& crossProduct(const VectorXD<X>& other);
38
+    static VectorXD<X> crossProduct(const VectorXD<X> &v1, const VectorXD<X> &v2);
37
 
39
 
38
     double norm() const;
40
     double norm() const;
39
 
41
 

+ 5
- 0
UGameEngine/utils/vectorxd.hxx View File

137
     return *this;
137
     return *this;
138
 }
138
 }
139
 
139
 
140
+tmpl VectorXD<X> VectorXD<X>::crossProduct(const VectorXD<X> &v1, const VectorXD<X> &v2)
141
+{
142
+    return VectorXD<X>(v1).crossProduct(v2);
143
+}
144
+
140
 tmpl double VectorXD<X>::norm() const
145
 tmpl double VectorXD<X>::norm() const
141
 {
146
 {
142
     double total = 0;
147
     double total = 0;

+ 11
- 0
tests/testvector3d.cpp View File

47
 
47
 
48
     void crossProduct1();
48
     void crossProduct1();
49
     void crossProduct2();
49
     void crossProduct2();
50
+    void crossProduct3();
50
 
51
 
51
     void norm1();
52
     void norm1();
52
     void norm2();
53
     void norm2();
381
     QCOMPARE(v.getZ(), -310.0);
382
     QCOMPARE(v.getZ(), -310.0);
382
 }
383
 }
383
 
384
 
385
+void TestVector3D::crossProduct3()
386
+{
387
+    Vector3D v1(10.0, 24.0, 8.0);
388
+    Vector3D v2(15.0, 5.0, 0.0);
389
+    Vector3D v = Vector3D::crossProduct(v1, v2);
390
+    QCOMPARE(v.getX(), -40.0);
391
+    QCOMPARE(v.getY(), 120.0);
392
+    QCOMPARE(v.getZ(), -310.0);
393
+}
394
+
384
 void TestVector3D::norm1()
395
 void TestVector3D::norm1()
385
 {
396
 {
386
     Vector3D v(3.0, 4.0, 0.0);;
397
     Vector3D v(3.0, 4.0, 0.0);;

Loading…
Cancel
Save