浏览代码

added vector2d

develop
Robin Thoni 8 年前
父节点
当前提交
e2af2b999f
共有 3 个文件被更改,包括 97 次插入2 次删除
  1. 4
    2
      UGameEngine/UGameEngine.pro
  2. 63
    0
      UGameEngine/utils/vector2d.cpp
  3. 30
    0
      UGameEngine/utils/vector2d.h

+ 4
- 2
UGameEngine/UGameEngine.pro 查看文件

@@ -20,7 +20,8 @@ SOURCES += engine/ugameengine.cpp \
20 20
     entities/ugeentityaxes.cpp \
21 21
     utils/wavefrontobj.cpp \
22 22
     entities/ugeentitywavefrontobj.cpp \
23
-    utils/texturevector3d.cpp
23
+    utils/texturevector3d.cpp \
24
+    utils/vector2d.cpp
24 25
 
25 26
 HEADERS += engine/ugameengine.h\
26 27
     engine/abstractrenderdevice.h \
@@ -33,7 +34,8 @@ HEADERS += engine/ugameengine.h\
33 34
     entities/ugeentitywavefrontobj.h \
34 35
     utils/texturevector3d.h \
35 36
     utils/vectorxd.h \
36
-    utils/vectorxd.hxx
37
+    utils/vectorxd.hxx \
38
+    utils/vector2d.h
37 39
 
38 40
 
39 41
 # FLEX && BISON

+ 63
- 0
UGameEngine/utils/vector2d.cpp 查看文件

@@ -0,0 +1,63 @@
1
+#include "vector2d.h"
2
+
3
+
4
+Vector2D::Vector2D(double x, double y)
5
+    : VectorXD<2>()
6
+{
7
+    _scalars[0] = x;
8
+    _scalars[1] = y;
9
+}
10
+
11
+Vector2D::Vector2D(const Vector2D &other)
12
+    : VectorXD<2>(other)
13
+{
14
+}
15
+
16
+Vector2D::Vector2D(const VectorXD<2> &other)
17
+    : VectorXD<2>(other)
18
+{
19
+}
20
+
21
+Vector2D::~Vector2D()
22
+{
23
+}
24
+
25
+double Vector2D::getX() const
26
+{
27
+    return _scalars[0];
28
+}
29
+
30
+Vector2D& Vector2D::setX(double x)
31
+{
32
+    _scalars[0] = x;
33
+    return *this;
34
+}
35
+double Vector2D::getY() const
36
+{
37
+    return _scalars[1];
38
+}
39
+
40
+Vector2D& Vector2D::setY(double y)
41
+{
42
+    _scalars[1] = y;
43
+    return *this;
44
+}
45
+
46
+Vector2D &Vector2D::add(double x, double y)
47
+{
48
+    _scalars[0] += x;
49
+    _scalars[1] += y;
50
+    return *this;
51
+}
52
+
53
+Vector2D &Vector2D::sub(double x, double y)
54
+{
55
+    _scalars[0] -= x;
56
+    _scalars[1] -= y;
57
+    return *this;
58
+}
59
+
60
+double Vector2D::dotProduct(double x, double y) const
61
+{
62
+    return dotProduct(Vector2D(x, y));
63
+}

+ 30
- 0
UGameEngine/utils/vector2d.h 查看文件

@@ -0,0 +1,30 @@
1
+#ifndef VECTOR2D_H
2
+#define VECTOR2D_H
3
+
4
+#include "vectorxd.h"
5
+
6
+class Vector2D : public VectorXD<2>
7
+{
8
+public:
9
+    explicit Vector2D(double x = 0.0, double y = 0.0);
10
+    Vector2D(const Vector2D& other);
11
+    Vector2D(const VectorXD<2>& other);
12
+    virtual ~Vector2D();
13
+
14
+    double getX() const;
15
+    Vector2D& setX(double x);
16
+
17
+    double getY() const;
18
+    Vector2D& setY(double y);
19
+
20
+    using VectorXD<2>::add;
21
+    Vector2D& add(double x, double y);
22
+
23
+    using VectorXD<2>::sub;
24
+    Vector2D& sub(double x, double y);
25
+
26
+    using VectorXD<2>::dotProduct;
27
+    double dotProduct(double x, double y) const;
28
+};
29
+
30
+#endif // VECTOR2D_H

正在加载...
取消
保存