// Copyright (c) 2021-2021, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto.  Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//

#include <OgnMakeTransformDatabase.h>

#include <omni/math/linalg/quat.h>
#include <omni/math/linalg/matrix.h>

using omni::math::linalg::quatd;
using omni::math::linalg::matrix4d;

namespace omni
{
namespace graph
{
namespace nodes
{

class OgnMakeTransform
{
public:
    static bool compute(OgnMakeTransformDatabase& db)
    {
        auto& translation = db.inputs.translation();
        auto& orientation = db.inputs.rotationXYZ();
        auto& scale = db.inputs.scale();

        const quatd q = omni::math::linalg::eulerAnglesToQuaternion(GfDegreesToRadians(orientation), omni::math::linalg::EulerRotationOrder::XYZ).GetNormalized();
        db.outputs.transform() = matrix4d().SetScale(scale) * matrix4d().SetRotate(q) * matrix4d().SetTranslate(translation);
        return true;
    }
};

REGISTER_OGN_NODE()
}
}
}
