Serializing editor camera position and direction.

Editor camera should resume where it was
This commit is contained in:
Antoine Pilote
2023-07-01 11:49:38 -04:00
parent 076ac59283
commit 93d007680b
4 changed files with 61 additions and 2 deletions

View File

@@ -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;
}
}