-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMassiveObject.cpp
117 lines (95 loc) · 2.15 KB
/
MassiveObject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// MassiveObject.cpp //
#include "MassiveObject.h"
namespace dw
{
// Initialize static variable
int MassiveObject::objectsInstantiated = 0;
// Constructors
MassiveObject::MassiveObject() : position(Vector3()), velocity(Vector3()), mass(0.0), volume(0.0)
{
++objectsInstantiated;
id = objectsInstantiated;
}
MassiveObject::MassiveObject(long double mass, long double volume, Vector3 pos, Vector3 vel) : position(pos), velocity(vel), mass(mass), volume(volume)
{
++objectsInstantiated;
id = objectsInstantiated;
}
MassiveObject::MassiveObject(MassiveObject& otherObject)
{
mass = otherObject.mass;
volume = otherObject.volume;
position = otherObject.position;
velocity = otherObject.velocity;
++objectsInstantiated;
id = objectsInstantiated;
}
MassiveObject::MassiveObject(MassiveObject&& rhs) noexcept
{
mass = std::move(rhs.mass);
volume = std::move(rhs.mass);
position = std::move(rhs.position);
velocity = std::move(rhs.velocity);
// Although it was moved, the rhs still exists and this is a new MassiveObject
++objectsInstantiated;
id = objectsInstantiated;
rhs.reset();
}
void MassiveObject::swap(MassiveObject& other)
{
std::swap(mass, other.mass);
std::swap(volume, other.volume);
std::swap(position, other.position);
std::swap(velocity, other.velocity);
}
MassiveObject& MassiveObject::operator = (MassiveObject rhs)
{
swap(rhs);
return *this;
}
void MassiveObject::reset()
{
mass = 0.0;
volume = 0.0;
position = Vector3();
velocity = Vector3();
}
// Getters
int MassiveObject::getId()
{
return id;
}
long double MassiveObject::getMass()
{
return mass;
}
long double MassiveObject::getVolume()
{
return volume;
}
Vector3 MassiveObject::getPosition()
{
return position;
}
Vector3 MassiveObject::getVelocity()
{
return velocity;
}
// Setters
void MassiveObject::setMass(long double mass)
{
this->mass = mass;
}
void MassiveObject::setVolume(long double volume)
{
this->volume = volume;
}
void MassiveObject::setPosition(Vector3 position)
{
this->position = position;
}
void MassiveObject::setVelocity(Vector3 velocity)
{
this->velocity = velocity;
}
}