diff options
author | chai <chaifix@163.com> | 2020-07-12 01:55:45 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-07-12 01:55:45 +0800 |
commit | ec7aa42781a9108901fbde7210d8285bbbeaf5fc (patch) | |
tree | 9a17690248cf855c0bb31c057f24159d4f81eafe /src/extend/camera.c | |
parent | e849a07762a2feb3f124a08d50adeed52f085d5b (diff) |
*capture
Diffstat (limited to 'src/extend/camera.c')
-rw-r--r-- | src/extend/camera.c | 85 |
1 files changed, 65 insertions, 20 deletions
diff --git a/src/extend/camera.c b/src/extend/camera.c index 2e66afc..016b1d5 100644 --- a/src/extend/camera.c +++ b/src/extend/camera.c @@ -4,10 +4,17 @@ typedef enum { CursorType_Arrow = 0, - CursorType_Hand = 1, - CursorType_Eye = 2 + CursorType_Hand, + CursorType_Eye, + CursorType_ZoomIn, + CursorType_ZoomOut, }CursorType; +static Wog_Cursor cursor_hand; +static Wog_Cursor cursor_eye; +static Wog_Cursor cursor_zoomIn; +static Wog_Cursor cursor_zoomOut; + // A unity editor style camera typedef struct Camera { Transform transform; @@ -30,6 +37,8 @@ typedef struct Camera { /*window*/ wog_Window* wnd; CursorType cursor; + /*wheel scroll icon*/ + float wheel_scroll; } Camera; Camera* camera_create(wog_Window* wnd, CameraConfig* config) { @@ -58,6 +67,13 @@ Camera* camera_create(wog_Window* wnd, CameraConfig* config) { cam->euler = config->euler; cam->wnd = wnd; + cam->wheel_scroll = 0; + + cursor_hand = LoadImageA(NULL, "PanView.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + cursor_eye = LoadImageA(NULL, "OrbitView.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + cursor_zoomIn = LoadImageA(NULL, "ZoomIn.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + cursor_zoomOut = LoadImageA(NULL, "ZoomOut.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + return cam; } @@ -92,7 +108,8 @@ void camera_getprojmatrix(Camera* cam, Mat4* out) { } static void _onwheelscroll(Camera* cam, int wheel, float dt) { - Quat rot; transform_getrotation(&cam->transform, &rot); + Quat rot; + transform_getrotation(&cam->transform, &rot); Vec3 forward = {0,0,-1}; internal_quat_applytovec3(&rot, &forward, &forward); internal_vec3_scale(&forward, cam->zoom_speed * wheel * dt * (cam->speedup ? cam->speedupv : 1), &forward); @@ -131,9 +148,39 @@ static void _onmovearound(Camera* cam, float dt) { cam->is_viewdirty = TRUE; } +#define setMouseCursor(enumValue, icon)\ + if (cam->cursor != enumValue) \ + { \ + wog_setcursorImage(cam->wnd, icon); \ + cam->cursor = enumValue; \ + } + +#define setMouseArrow()\ + if (cam->cursor != CursorType_Arrow) \ + { \ + wog_setcursor(cam->wnd, IDC_ARROW); \ + cam->cursor = CursorType_Arrow; \ + } + + void camera_onevent(Camera* cam, wog_Event* e, float dt) { - if(e == NULL) return ; - if (e->type == WOG_EMOUSEWHEEL) {//zoom in\zoom out + if(e == NULL || e->type == WOG_EUNKNOWN) + return ; + if(e->type == WOG_EMOUSEMOTION) + return ; + //printf("%d\n",e->type); + if (e->type == WOG_EMOUSEWHEEL) { + if (e->wheel > 0) + { + setMouseCursor(CursorType_ZoomIn, cursor_zoomIn); + } + else if (e->wheel < 0) + { + setMouseCursor(CursorType_ZoomOut, cursor_zoomOut); + } + if(cam->wheel_scroll <= 0) + wog_setMouseCapture(cam->wnd); + cam->wheel_scroll = 0.3; _onwheelscroll(cam, e->wheel, dt); } else if (e->type == WOG_EMOUSEBUTTONDOWN) { @@ -141,21 +188,13 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) { cam->look_around = TRUE; cam->mouse_prev.x = e->pos.x; cam->mouse_prev.y = e->pos.y; - if (cam->cursor != CursorType_Eye) - { - wog_setcursorImage(cam->wnd, "OrbitView.ico"); - cam->cursor = CursorType_Eye; - } + setMouseCursor(CursorType_Eye, cursor_eye); } if (!cam->move_around && e->button == WOG_MOUSE_MIDDLE) { cam->move_around = TRUE; cam->mouse_prev.x = e->pos.x; cam->mouse_prev.y = e->pos.y; - if (cam->cursor != CursorType_Hand) - { - wog_setcursorImage(cam->wnd, "PanView.ico"); - cam->cursor = CursorType_Hand; - } + setMouseCursor(CursorType_Hand, cursor_hand); } } else if (e->type == WOG_EMOUSEBUTTONUP) { @@ -163,11 +202,7 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) { cam->look_around = FALSE; if (e->button == WOG_MOUSE_MIDDLE) cam->move_around = FALSE; - if (cam->cursor != CursorType_Arrow) - { - wog_setcursor(cam->wnd, IDC_ARROW); - cam->cursor = CursorType_Arrow; - } + setMouseArrow(); } else if (e->type == WOG_EKEYDOWN) { if (!cam->speedup && e->key == VK_SHIFT) @@ -177,9 +212,19 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) { if (e->key == VK_SHIFT) cam->speedup = FALSE; } + else + { + } } void camera_onupdate(Camera* cam, float dt) { + cam->wheel_scroll -= dt; + if (cam->wheel_scroll + dt > 0 && cam->wheel_scroll <= 0) + { + setMouseArrow(); + wog_releaseMouseCapture(cam->wnd); + } + if (cam->look_around) _onlookaround(cam, dt); if (cam->move_around) |