mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-04 11:35:06 +03:00
Serializing editor camera position and direction.
Editor camera should resume where it was
This commit is contained in:
@@ -42,5 +42,4 @@ class ISerializable
|
||||
public:
|
||||
virtual json Serialize() = 0;
|
||||
virtual bool Deserialize(const std::string& str) = 0;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -192,4 +192,47 @@ namespace Nuake
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
void EditorCamera::UpdateDirection()
|
||||
{
|
||||
Direction.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Direction.y = sin(glm::radians(Pitch));
|
||||
Direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Direction = glm::normalize(Direction);
|
||||
Right = glm::normalize(glm::cross(Up, Direction));
|
||||
}
|
||||
|
||||
void EditorCamera::SetYaw(float yaw)
|
||||
{
|
||||
Yaw = yaw;
|
||||
UpdateDirection();
|
||||
}
|
||||
|
||||
void EditorCamera::SetPitch(float pitch)
|
||||
{
|
||||
Pitch = pitch;
|
||||
UpdateDirection();
|
||||
}
|
||||
|
||||
json EditorCamera::Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
|
||||
SERIALIZE_VEC3(Translation);
|
||||
j["Yaw"] = Yaw;
|
||||
j["Pitch"] = Pitch;
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
bool EditorCamera::Deserialize(const std::string& str)
|
||||
{
|
||||
BEGIN_DESERIALIZE();
|
||||
|
||||
DESERIALIZE_VEC3(j["Translation"], Translation);
|
||||
SetYaw(j["Yaw"]);
|
||||
SetPitch(j["Pitch"]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,13 @@ namespace Nuake
|
||||
Vector3 TargetPos = Vector3(0, 0, 0);
|
||||
bool IsMoving = false;
|
||||
Ref<EditorCamera> Copy();
|
||||
|
||||
json Serialize();
|
||||
bool Deserialize(const std::string& str);
|
||||
|
||||
void SetYaw(float yaw);
|
||||
void SetPitch(float pitch);
|
||||
|
||||
private:
|
||||
bool controlled = false;
|
||||
bool firstMouse = false;
|
||||
@@ -28,5 +35,6 @@ namespace Nuake
|
||||
|
||||
float Yaw = -135.f;
|
||||
float Pitch = -45.f;
|
||||
void UpdateDirection();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -326,10 +326,14 @@ namespace Nuake {
|
||||
SERIALIZE_VAL(Name);
|
||||
SERIALIZE_OBJECT(m_Environement)
|
||||
SERIALIZE_VAL(Path)
|
||||
|
||||
std::vector<json> entities = std::vector<json>();
|
||||
for (Entity e : GetAllEntities())
|
||||
entities.push_back(e.Serialize());
|
||||
SERIALIZE_VAL_LBL("Entities", entities);
|
||||
|
||||
SERIALIZE_OBJECT(m_EditorCamera);
|
||||
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
@@ -371,6 +375,11 @@ namespace Nuake {
|
||||
ent.Deserialize(e.dump());
|
||||
}
|
||||
|
||||
if (j.contains("m_EditorCamera"))
|
||||
{
|
||||
m_EditorCamera->Deserialize(j["m_EditorCamera"].dump());
|
||||
}
|
||||
|
||||
auto view = m_Registry.view<ParentComponent>();
|
||||
for (auto e : view)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user