/* ── missNavigator.glb 测试 ──
 *  鼠标拖拽旋转/滚轮缩放 */

#include "eduwin.h"

static dx_mesh *g_model;
static dx_camera g_cam;
static dx_orbit  g_orbit;

/* ──── 帧回调 ──── */
static void on_frame(void)
{
    dx_orbit_update(&g_orbit, &g_cam);

    dx_begin(0.12f, 0.12f, 0.18f, 1);

    dx_set_ambient_light(0.5f, 0.5f, 0.5f, 1);
    dx_set_directional_light(0.5f, -0.7f, 0.5f, 1, 1, 1, 2.0f);

    if (g_model)
        dx_mesh_draw(g_model);

    dx_end();
}

int main(void)
{
    if (init_app() != 0) return 1;

    HWND win = create_window(L"missNavigator - 鼠标拖拽旋转/滚轮缩放", 1600, 1200);
    show_window(win);
    if (!dx_init(win, 1600, 1200)) {
        log_error(L"D3D11 初始化失败");
        return 1;
    }

    g_model = dx_load_gltf("readyplayer.me.glb");
    if (!g_model) {
        log_error(L"readyplayer.me.glb 加载失败");
        return 1;
    }
    dx_mesh_set_scale(g_model, 1.3f, 1.3f, 1.3f);
    log_error(L"readyplayer.me.glb 加载成功");

    dx_orbit_init(&g_orbit, win, 0, 0, 0, 3);
    dx_camera_init(&g_cam, 0, 1.5f, 3.0f, 1600.0f / 1200.0f);  /* RH: 相机在+Z看原点，模型面朝+Z=正面 */

    run_app_frame(on_frame);

    dx_orbit_destroy(&g_orbit);
    if (g_model) dx_free_mesh(g_model);
    dx_shutdown();
    return 0;
}
