Fixed quaternion serializing

This commit is contained in:
antopilo
2023-03-06 16:57:35 -05:00
parent 0df434282d
commit 10baf5271a
2 changed files with 13 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ using json = nlohmann::json;
#define SERIALIZE_VEC4(v) \
SERIALIZE_VEC3(v) \
j[#v]["w"] = this->v.z;
j[#v]["w"] = this->v.w;
#define DESERIALIZE_VEC3(v, p) \
p = Vector3(v["x"], v["y"], v["z"]);

View File

@@ -46,6 +46,7 @@ namespace Nuake
json Serialize()
{
Rotation = glm::normalize(Rotation);
BEGIN_SERIALIZE();
SERIALIZE_VAL_LBL("Type", "TransformComponent");
SERIALIZE_VEC3(Translation);
@@ -58,12 +59,21 @@ namespace Nuake
{
BEGIN_DESERIALIZE();
this->Translation = Vector3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]);
if(j.contains("Rotation"))
this->Rotation = Quat(j["Rotation"]["w"], j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]);
if (j.contains("Rotation"))
{
float w = j["Rotation"]["w"];
float x = j["Rotation"]["x"];
float y = j["Rotation"]["y"];
float z = j["Rotation"]["z"];
this->Rotation = Quat(w, x, y, z);
}
this->Scale = Vector3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]);
LocalTransform = Matrix4(1);
GlobalTransform = Matrix4(1);
Dirty = true;
return true;
}
};