diff options
author | chai <chaifix@163.com> | 2020-02-26 22:52:19 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-26 22:52:19 +0800 |
commit | 372d77e436d21312ef1a0df622964751716963a3 (patch) | |
tree | 1a71865fea6fb9f2f532422c4b83959fff17ea76 /src/main.c | |
parent | 27687536844ed3b045bba1abd1aae8bb3692f6cb (diff) |
*misc
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 66 |
1 files changed, 48 insertions, 18 deletions
@@ -7,10 +7,26 @@ #include "extern/wog.h" #include "shaders/common.h" #include "extend/camera.h" +#include "extend/scene.h" + +#define TITLE "Soft Shade Room" #define SCREEN_WIDTH 600.f #define SCREEN_HEIGHT 480.f +static char* instruction = +"/*********************************************/\n" +"/* SoftShadeRoom */\n" +"/* chai */\n" +"/*********************************************/\n" +"Instructions:\n" +"RightMouseButton+MouseMove: look around\n" +"MiddleMouseButton+MouseMove: move around\n" +"MouseScroll: zoom in\\zoom out\n" +"Shift+Above Operation: speed up\n" +"key-g: show\\hide grid\n" +"----------------------------------------------\n"; + typedef void(*F)(void*); F onload; @@ -18,20 +34,21 @@ F onupdate; F onevent; F ondraw; -/*https://stackoverflow.com/questions/1489932/how-to-concatenate-twice-with-the-c-preprocessor-and-expand-a-macro-as-in-arg*/ -#define SETEXAMPLEF(f, e) \ +#define SET_EXAMPLE_FUNC(f, e) \ f = f##_##e; -#define SETEXAMPLE(i) \ - SETEXAMPLEF(onload, i)\ - SETEXAMPLEF(ondraw, i)\ - SETEXAMPLEF(onevent, i)\ - SETEXAMPLEF(onupdate, i) +#define SET_EXAMPLE(i) \ + SET_EXAMPLE_FUNC(onload, i)\ + SET_EXAMPLE_FUNC(ondraw, i)\ + SET_EXAMPLE_FUNC(onevent, i)\ + SET_EXAMPLE_FUNC(onupdate, i) int main(int argc, char* argv[]) { - wog_Window* wnd = wog_createWindow("Soft Shade Room", SCREEN_WIDTH, SCREEN_HEIGHT, 500, 500, 0); + printf(instruction); + + SET_EXAMPLE(CURRENT_EXAMPLE); + wog_Window* wnd = wog_createWindow(TITLE, SCREEN_WIDTH, SCREEN_HEIGHT, 500, 500, 0); wog_Surface* surface = wog_getsurface(wnd); // ARGB format - Camera* camera; /* init ssr */ ssr_Config config = { SCREEN_WIDTH, SCREEN_HEIGHT, @@ -39,19 +56,24 @@ int main(int argc, char* argv[]) { surface->buffer }; ssr_init(&config); - SETEXAMPLE(EXAMPLECUR); /*set up global camera*/ - CameraConfig cam_config = { /*default camera setting*/ - {0, 0, 800}, + CameraConfig cam_config = { + {0, 10, 800}, {0, 0, 0}, - 60, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1, 1500, + 60, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1, 100000, {5, 5}, {150, 150}, 4000, }; onload(&cam_config); - camera = camera_create(wnd, &cam_config); + scene.main_camera = camera_create(wnd, &cam_config); + gizmo_init(); wog_show(wnd); + _screen_params.x = SCREEN_WIDTH; + _screen_params.y = SCREEN_HEIGHT; + _screen_params.z = 1 / SCREEN_WIDTH; + _screen_params.w = 1 / SCREEN_HEIGHT; + /* main loop */ uint prev = wog_tick(); uint dt = 0; @@ -62,9 +84,15 @@ int main(int argc, char* argv[]) { while (1) { /*handle events*/ while (wog_pollEvent(wnd, &e)) { - camera_onevent(camera, &e, _dt); + camera_onevent(scene.main_camera, &e, _dt); + gizmo_onevent(&e, _dt); if (e.type == WOG_ECLOSE) { goto quit; + } + else if (e.type == WOG_EKEYDOWN) { + if (e.key == VK_ESCAPE) { + goto quit; + } } else { onevent(&e); } @@ -86,12 +114,14 @@ int main(int argc, char* argv[]) { /*update*/ _dt = dt / 1000.f; - camera_onupdate(camera, _dt); + camera_onupdate(scene.main_camera, _dt); + gizmo_onupdate(_dt); onupdate(&_dt); /*draw*/ - camera_ondraw(camera); + camera_ondraw(scene.main_camera); ondraw(NULL); + gizmo_ondraw(); ssr_present(); wog_updateSurface(wnd); @@ -99,7 +129,7 @@ int main(int argc, char* argv[]) { } quit: - camera_destroy(camera); + camera_destroy(scene.main_camera); wog_destroyWindow(wnd); return 0; |