Files
lity3d/Demo/scene_test2.c
T

55 lines
2.2 KiB
C

// scene_test2.c - 最小化场景测试
#include "../Engine/Core/engine.h"
#include "../Engine/Core/logger.h"
#include "../Engine/Window/window.h"
#include "../Engine/Rendering/graphics_device.h"
#include "../Engine/Scene/scene_graph.h"
#include "../Engine/include/engine_api.h"
#include "../Engine/ASM/math_c_fallback.h"
static GraphicsDevice* g_dev = NULL;
static void on_render(Engine* engine) {
if (!g_dev) return;
ID3D11DeviceContext* ctx = g_dev->context;
float clear[4] = {0.2f, 0.3f, 0.5f, 1.0f};
g_dev->context->lpVtbl->ClearRenderTargetView(g_dev->context, g_dev->render_target, clear);
D3D11_VIEWPORT vp = {0};
vp.Width = (float)g_dev->width; vp.Height = (float)g_dev->height;
vp.MaxDepth = 1.0f;
ctx->lpVtbl->RSSetViewports(ctx, 1, &vp);
graphics_device_present(g_dev);
}
static void on_key(Engine* engine, int key) {
if (key == VK_ESCAPE) engine_request_quit(engine);
}
int WINAPI WinMain(HINSTANCE hI, HINSTANCE hP, LPSTR cmd, int nS) {
(void)hI;(void)hP;(void)cmd;(void)nS;
LOG_INFO("=== lity3d Scene Test ===");
EngineConfig cfg = engine_default_config();
cfg.app_name = "lity3d Scene Test";
Engine* engine = engine_create();
if (!engine_init(engine, &cfg)) return -1;
g_dev = graphics_device_create();
if (!graphics_device_init(g_dev, window_get_handle(engine->window), cfg.window_width, cfg.window_height, 1)) return -1;
LOG_INFO("D3D11 ready");
Scene scene; scene_init(&scene);
SceneNode* n1 = scene_create_node(&scene, "A");
scene_set_position(n1, 1, 0, 0);
SceneNode* n2 = scene_create_node(&scene, "B");
scene_set_parent(n2, n1);
scene_set_position(n2, 0, 2, 0);
scene_update(&scene);
LOG_INFO("A world pos: (%.1f,%.1f,%.1f)", scene.nodes[1].world_matrix.m[3][0], scene.nodes[1].world_matrix.m[3][1], scene.nodes[1].world_matrix.m[3][2]);
LOG_INFO("B world pos: (%.1f,%.1f,%.1f)", scene.nodes[2].world_matrix.m[3][0], scene.nodes[2].world_matrix.m[3][1], scene.nodes[2].world_matrix.m[3][2]);
engine_set_render_callback(engine, on_render);
engine_set_key_callback(engine, on_key);
engine_run(engine);
graphics_device_destroy(g_dev);
engine_shutdown(engine);
return 0;
}