/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#include "libgltf.h"
#include "RenderScene.h"
class RenderScene* cameraScene;

extern "C"
glTFHandle* gltf_renderer_init(const glTFFile* jsonfile)
{
    class RenderScene* renderScene = new RenderScene();
    glTFHandle* gltf_result = renderScene->initScene(jsonfile);
    gltf_result->renderer = renderScene;
    cameraScene = renderScene;
    return gltf_result;
}

extern "C"
void gltf_renderer_set_content(glTFHandle *handle)
{
    class RenderScene* renderScene = (RenderScene*)handle->renderer;
    renderScene->initRender(handle);
    return;
}

extern "C"
void gltf_renderer(glTFHandle* handle)
{
    class RenderScene* renderScene = (RenderScene*)handle->renderer;
    renderScene->render(&(handle->viewport));
    return;
}

extern "C"
void gltf_renderer_release(glTFHandle* handle)
{
    class RenderScene* renderScene = (RenderScene*)handle->renderer;
    renderScene->releaseRender(NULL);
    delete renderScene;
    //if(handle != NULL) free(handle);
    return;
}

extern "C"
    void gltf_get_camera_pos(glm::vec3 *pos,glm::vec3 *view,glm::vec3 *up)
{
    cameraScene->getCameraPos(pos, view, up);
    return;
}


extern "C"
void gltf_renderer_move_camera(double x, double y, double z,double time)
{
    cameraScene->getCamera()->moveCamera(x, y, z, time);
    return;
}

extern "C"
void gltf_renderer_rotate_camera(double horizontal, double vertical,
   double planar, double time)
{
    cameraScene->getCamera()->rotateCamera(horizontal, vertical, planar, time);
    return;
}
   
extern "C"
void gltf_renderer_get_bitmap(glTFHandle *handle, double time,
    char* buffer, long width, long height)
{
    class RenderScene* renderScene = (RenderScene*)handle->renderer;
    renderScene->renderToBuffer(&(handle->viewport), (unsigned char*)buffer);
    return;
}

extern "C"
void gltf_animation_start(glTFHandle *handle)
{
    return;
}

extern "C"
void gltf_animation_stop(glTFHandle *handle)
{
    return;
}

extern "C"
int gltf_animation_is_playing(glTFHandle *handle)
{
    return 0;
}

extern "C"
void gltf_animation_set_looping(glTFHandle *handle, int loop)
{
    return;
}

extern "C"
int gltf_animation_get_looping(glTFHandle *handle)
{
    return 0;
}

extern "C"
double gltf_animation_get_duration(glTFHandle *handle)
{
    return 0.0;
}

extern "C"
void gltf_animation_set_time(glTFHandle *handle, double time)
{
    return;
}

extern "C"
double gltf_animation_get_time(glTFHandle *handle)
{
    return 0.0;
}

