63 lines
1.3 KiB
C++
63 lines
1.3 KiB
C++
#include "Vector.hpp"
|
|
|
|
#include "Game/SaveMap/SaveMap.hpp"
|
|
|
|
Vector2D::Vector2D(double x, double y) : x(x), y(y)
|
|
{}
|
|
|
|
Vector2D::Vector2D(const Vector3D& vec3D) : x(vec3D.x), y(vec3D.y)
|
|
{}
|
|
|
|
Vector2D Vector2D::operator+(const Vector2D& v) const
|
|
{
|
|
return Vector2D{ x + v.x, y + v.y };
|
|
}
|
|
|
|
Vector2D Vector2D::operator-(const Vector2D& v) const
|
|
{
|
|
return Vector2D{ x - v.x, y - v.y };
|
|
}
|
|
|
|
std::shared_ptr<SaveMap> Vector2D::save()
|
|
{
|
|
std::unique_ptr<SaveMap> save = std::make_unique<SaveMap>("Vector2D");
|
|
save->SaveDouble("x", x)->SaveDouble("y", y);
|
|
return save;
|
|
}
|
|
|
|
void Vector2D::load(std::shared_ptr<SaveMap> save)
|
|
{
|
|
x = save->GetDouble("x");
|
|
y = save->GetDouble("y");
|
|
}
|
|
|
|
Vector3D::Vector3D(double x, double y, double z) : x(x), y(y), z(z)
|
|
{}
|
|
|
|
Vector3D::Vector3D(const Vector2D& vec2D) : x(vec2D.x), y(vec2D.y)
|
|
{}
|
|
|
|
Vector3D Vector3D::operator+(const Vector3D& v) const
|
|
{
|
|
return Vector3D{x + v.x, y + v.y, z + v.z};
|
|
}
|
|
|
|
Vector3D Vector3D::operator-(const Vector3D& v) const
|
|
{
|
|
return Vector3D{ x - v.x, y - v.y, z - v.z };
|
|
}
|
|
|
|
std::shared_ptr<SaveMap> Vector3D::save()
|
|
{
|
|
std::unique_ptr<SaveMap> save = std::make_unique<SaveMap>("Vector3D");
|
|
save->SaveDouble("x", x)->SaveDouble("y", y)->SaveDouble("z", z);
|
|
return save;
|
|
}
|
|
|
|
void Vector3D::load(std::shared_ptr<SaveMap> save)
|
|
{
|
|
x = save->GetDouble("x");
|
|
y = save->GetDouble("y");
|
|
z = save->GetDouble("z");
|
|
}
|