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

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

namespace omni
{
namespace graph
{
namespace ui
{

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

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

        CameraState cameraState(std::move(camera));

        carb::Double3 position;
        cameraState.getCameraPosition(position);

        carb::Double3& positionAttrib = reinterpret_cast<carb::Double3&>(db.outputs.position());
        positionAttrib = position;

        return true;
    }
};

REGISTER_OGN_NODE()
}
}
}
