-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallbacks.cpp
82 lines (72 loc) · 1.86 KB
/
callbacks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Copyright (c) RELEX Oy
All rights reserved.
Source made public only to facilitate research and bug reproduction in WASM, Esmcripten, C# Runtimes such as Blazor, Angular and WebGL.
*/
#include "renderer.h"
#include "callbacks.h"
#include "window.h"
#include <iostream>
#include <emscripten/key_codes.h>
EM_BOOL key_callback(int eventType, const EmscriptenKeyboardEvent* e, void* userData) {
if (eventType == EMSCRIPTEN_EVENT_KEYPRESS) {
int env = -1;
switch (e->keyCode)
{
case DOM_VK_ESCAPE:
emscripten_cancel_main_loop();
return 1;
case DOM_VK_5: //change the background to load a cubemap texture. clicking it again toggles texture
env = 5;
break;
case DOM_VK_4: //change background to black and white gradient
env = 4;
break;
case DOM_VK_3: //change background to procedural desert
env = 3;
break;
case DOM_VK_2: //change background to procedural 4 pointlight scene
env = 2;
break;
case DOM_VK_1: //change background to none
env = 1;
break;
default:
break;
}
if (env != -1) {
Window* window = (Window*)userData;
Renderer* renderer = window->getRenderer();
renderer->Set_iEnv(env);
if (env == 5)
renderer->change_cubemap();
std::cout << "Changed background to " << env << std::endl;
return 1;
}
}
return 0;
}
EM_BOOL mouse_callback(int eventType, const EmscriptenMouseEvent* e, void* userData) {
Window* window = (Window*)userData;
if (eventType == EMSCRIPTEN_EVENT_MOUSEDOWN)
{
if (e->button == 0) {
std::cout << "Mouse down" << std::endl;
window->m_mouse_down = true;
return 1;
}
}
else if (eventType == EMSCRIPTEN_EVENT_MOUSEUP) {
if (e->button == 0) {
std::cout << "Mouse up" << std::endl;
window->m_mouse_down = false;
return 1;
}
}
else if (eventType == EMSCRIPTEN_EVENT_MOUSEMOVE)
{
window->onMouseDrag(e->clientX, e->clientY);
return 1;
}
return 0;
}