// 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.
//

// clang-format off
#include "UsdPCH.h"
// clang-format on

#include <OgnSetCameraPositionDatabase.h>

#include "CameraState.h"
#include "NodeUtils.h"

#include <pxr/base/gf/vec3d.h>


namespace omni
{
namespace graph
{
namespace ui_nodes
{

class OgnSetCameraPosition
{
public:
    static bool compute(OgnSetCameraPositionDatabase& db)
    {
        PXR_NS::UsdPrim prim = getPrimFromPathOrRelationship(db, OgnSetCameraPositionAttributes::inputs::prim.m_token);
        if (!prim)
            return false;

        auto position = db.inputs.position();
        auto rotate = db.inputs.rotate();

        auto camera = PXR_NS::UsdGeomCamera(prim);
        if (!camera)
            return false;

        CameraState cameraState(std::move(camera));
        bool ok = cameraState.setCameraPosition({ position[0], position[1], position[2] }, rotate);
        if (!ok)
        {
            db.logError("Could not set position for camera %s", prim.GetPath().GetText());
        }

        db.outputs.execOut() = kExecutionAttributeStateEnabled;

        return true;
    }
};

REGISTER_OGN_NODE()
}
}
}
