/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. // This header extends serialization to support common geometrical types. // It allows serialization of mentioned below types simple passing them to archive. // For example: // // #include // #include // // Serialization::IArchive& ar; // // Vec3 v; // ar(v, "v"); // // QuatT q; // ar(q, "q"); // #ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATH_H #define CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATH_H #pragma once namespace Serialization { class IArchive; } template bool Serialize(Serialization::IArchive& ar, struct Vec2_tpl& v, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, struct Vec3_tpl& v, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, struct Vec4_tpl& v, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, struct Quat_tpl& q, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, struct QuatT_tpl& qt, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, struct Ang3_tpl& a, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, struct Matrix34_tpl& value, const char* name, const char* label); bool Serialize(Serialization::IArchive& ar, struct AABB& aabb, const char* name, const char* label); // --------------------------------------------------------------------------- // RadiansAsDeg allows to present radian values as degrees to the user in the // editor. // // Example: // ... // float radians; // ar(RadiansAsDeg(radians), "degrees", "Degrees"); // // Ang3 euler; // ar(RadiansAsDeg(euler), "eulerDegrees", "Euler Degrees"); // namespace Serialization { template struct SRadianAng3AsDeg { Ang3_tpl* ang3; SRadianAng3AsDeg(Ang3_tpl* _ang3) : ang3(_ang3) {} }; template SRadianAng3AsDeg RadiansAsDeg(Ang3_tpl& radians) { return SRadianAng3AsDeg(&radians); } template struct SRadiansAsDeg { T* radians; SRadiansAsDeg(T* _radians) : radians(_radians) {} }; template SRadiansAsDeg RadiansAsDeg(T& radians) { return SRadiansAsDeg(&radians); } template bool Serialize(Serialization::IArchive& ar, Serialization::SRadiansAsDeg& value, const char* name, const char* label); template bool Serialize(Serialization::IArchive& ar, Serialization::SRadianAng3AsDeg& value, const char* name, const char* label); // --------------------------------------------------------------------------- // QuatAsAng3 provides a wrapper that allows editing of quaternions as Ang3 (in degrees). // // Example: // ... // Quat q; // ar(QuatAsAng3(q), "orientation", "Orientation"); // template struct QuatAsAng3 { Quat_tpl* quat; QuatAsAng3(Quat_tpl& _quat) : quat(&_quat) {} }; template bool Serialize(Serialization::IArchive& ar, Serialization::QuatAsAng3& value, const char* name, const char* label); // --------------------------------------------------------------------------- // QuatTAsVec3Ang3 provides a wrapper that allows editing of transforms as Vec3 and Ang3 (in degrees). // // Example: // ... // QuatT trans; // ar(QuatTAsVec3Ang3(trans), "transform", "Transform"); // template struct QuatTAsVec3Ang3 { QuatT_tpl* trans; QuatTAsVec3Ang3(QuatT_tpl& _trans) : trans(&_trans) {} }; template bool Serialize(Serialization::IArchive& ar, Serialization::QuatTAsVec3Ang3& value, const char* name, const char* label); // --------------------------------------------------------------------------- // Helper functions for Ang3 // // Example: // ... // Quat q; // QuatT trans; // ar(AsAng3(q),"orientation","Orientation"); // ar(AsAnge(trans),"transform", "Transform"); // template inline QuatAsAng3 AsAng3(Quat_tpl& q){ return QuatAsAng3(q); } template inline QuatTAsVec3Ang3 AsAng3(QuatT_tpl& trans){ return QuatTAsVec3Ang3(trans); } } #include "MathImpl.h" #endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATH_H