Mouse click input
This commit is contained in:
parent
31cd55cf1f
commit
232494cc46
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "Renderer.h"
|
||||
#include "Win32AssetManager.h"
|
||||
#include "TouchInput.h"
|
||||
#include "Position.h"
|
||||
|
||||
#undef APIENTRY
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
@ -44,22 +46,65 @@ int main()
|
|||
|
||||
Renderer::create();
|
||||
|
||||
// BEISPIELCODE
|
||||
Position smiley_pos = {512, 384};
|
||||
StringHandle smiley = StringRepository::global->internString("smiley_PNG42.png");
|
||||
// ENDE BEISPIELCODE
|
||||
|
||||
glfwSwapInterval(1);
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
Renderer::ptr->addRect(100,
|
||||
100,
|
||||
500,
|
||||
500,
|
||||
0.3,
|
||||
0.3,
|
||||
0.3,
|
||||
1.0f,
|
||||
StringRepository::global->internString("smiley_PNG42.png"));
|
||||
/* Gather keyboard input */
|
||||
|
||||
/* Gather mouse input */
|
||||
TouchInputEvent touch_event = {};
|
||||
int input_event_count = 0;
|
||||
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) {
|
||||
double x, y;
|
||||
glfwGetCursorPos(window, &x, &y);
|
||||
touch_event.kind = TouchInputEventKind::Tap;
|
||||
touch_event.start = {static_cast<float>(x), static_cast<float>(y)};
|
||||
touch_event.end = touch_event.start;
|
||||
input_event_count = 1;
|
||||
}
|
||||
|
||||
int w, h;
|
||||
glfwGetFramebufferSize(window, &w, &h);
|
||||
|
||||
// INTEGRATION Rufe hier deine "gameloop"/"update" funktion auf, die als Parameter
|
||||
// den GameState, input_events und input_event_count und die Displaygröße bekommen sollte:
|
||||
//
|
||||
// kUpdate(&m_state, input_events, input_event_count, m_display_width, m_display_height)
|
||||
//
|
||||
//
|
||||
// Die Funktion könnte folgende Definition haben:
|
||||
// void kUpdate(GameState* state,
|
||||
// const TouchInputEvent* touch_events,
|
||||
// unsigned int touch_event_count,
|
||||
// float display_width,
|
||||
// float display_height)
|
||||
// ENDE INTEGRATION
|
||||
|
||||
// BEISPIELCODE
|
||||
static float x = 1.f;
|
||||
static float d = -0.01f;
|
||||
x += d;
|
||||
if (x <= 0.f)
|
||||
d *= -1.f;
|
||||
else if (x >= 1.f)
|
||||
d *= -1.f;
|
||||
|
||||
if (input_event_count > 0) {
|
||||
smiley_pos = touch_event.end;
|
||||
smiley_pos.x -= 250;
|
||||
smiley_pos.y -= 250;
|
||||
}
|
||||
|
||||
Renderer::ptr->addRect(100, 100, 500, 500, 0.3f, 0.3f, 0.3f, 1.f);
|
||||
Renderer::ptr->addRect(smiley_pos.x, smiley_pos.y, 500, 500, 0.f, x * x, 1.f - x * x, 1.f, smiley);
|
||||
// ENDE BEISPIELCODE
|
||||
|
||||
Renderer::ptr->renderFrame(static_cast<float>(w), static_cast<float>(h));
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
|
|
Loading…
Reference in New Issue
Block a user