-
Notifications
You must be signed in to change notification settings - Fork 0
Add basic input handling #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rasmushugosson
wants to merge
1
commit into
main
Choose a base branch
from
input
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include "keyboard.h" | ||
|
|
||
| static keyboard_data s_data; | ||
|
|
||
| void keyboard_init(GLFWwindow* window) | ||
| { | ||
| glfwSetKeyCallback(window, keyboard_callback); | ||
| } | ||
|
|
||
| bool keyboard_is_pressed(int key) | ||
| { | ||
| return s_data.keys[key]; | ||
| } | ||
|
|
||
| void keyboard_state_set(int key, bool state) | ||
| { | ||
| s_data.keys[key] = state; | ||
| } | ||
|
|
||
| void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods) | ||
| { | ||
| if (action == GLFW_PRESS) | ||
| { | ||
| keyboard_state_set(key, true); | ||
| } | ||
|
|
||
| else if (action == GLFW_RELEASE) | ||
| { | ||
| keyboard_state_set(key, false); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #pragma once | ||
|
|
||
| #include <GLFW/glfw3.h> | ||
| #include <bitset> | ||
|
|
||
| struct keyboard_data | ||
| { | ||
| GLFWwindow* window; | ||
| std::bitset<1024> keys; | ||
| }; | ||
|
|
||
| void keyboard_init(GLFWwindow* window); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. camelCase för funktioner |
||
| bool keyboard_is_pressed(int key); | ||
| void keyboard_state_set(int key, bool state); | ||
|
|
||
| void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include "mouse.h" | ||
|
|
||
| static mouse_data s_data; | ||
|
|
||
| void mouse_init(GLFWwindow* window) | ||
| { | ||
| s_data.window = window; | ||
| glfwSetInputMode(s_data.window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); | ||
| s_data.position_x = 0.0f; | ||
| s_data.position_y = 0.0f; | ||
| } | ||
|
|
||
| float mouse_position_get_x() | ||
| { | ||
| double x, y; | ||
| glfwGetCursorPos(s_data.window, &x, &y); | ||
|
|
||
| return (float)x; | ||
| } | ||
|
|
||
| float mouse_position_get_y() | ||
| { | ||
| double x, y; | ||
| glfwGetCursorPos(s_data.window, &x, &y); | ||
|
|
||
| return (float)y; | ||
| } | ||
|
|
||
| void mouse_position_set(float x, float y) | ||
| { | ||
| s_data.position_x = x; | ||
| s_data.position_y = y; | ||
| glfwSetCursorPos(s_data.window, (double)x, (double)y); | ||
| } | ||
|
|
||
| bool mouse_is_left() | ||
| { | ||
| int state = glfwGetMouseButton(s_data.window, GLFW_MOUSE_BUTTON_LEFT); | ||
| return state == GLFW_PRESS; | ||
| } | ||
|
|
||
| bool mouse_is_right() | ||
| { | ||
| int state = glfwGetMouseButton(s_data.window, GLFW_MOUSE_BUTTON_RIGHT); | ||
| return state == GLFW_PRESS; | ||
| } | ||
|
|
||
| bool mouse_is_middle() | ||
| { | ||
| int state = glfwGetMouseButton(s_data.window, GLFW_MOUSE_BUTTON_MIDDLE); | ||
| return state == GLFW_PRESS; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #pragma once | ||
|
|
||
| #include <GLFW/glfw3.h> | ||
|
|
||
| struct mouse_data | ||
| { | ||
| GLFWwindow* window; | ||
| float position_x; | ||
| float position_y; | ||
| }; | ||
|
|
||
| void mouse_init(GLFWwindow* window); | ||
| float mouse_position_get_x(); | ||
| float mouse_position_get_y(); | ||
|
|
||
| void mouse_position_set(float x, float y); | ||
|
|
||
| bool mouse_is_left(); | ||
| bool mouse_is_right(); | ||
| bool mouse_is_middle(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| std::string ReadFile(const char *path); | ||
| GLuint CreateProgram(const char* VertexPath, const char* FragPath); | ||
| void DeleteProgram(GLuint *id); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PascalCase för structs är conventions som jag har jobbat med