Starting basic physics, nothing fancy

This commit is contained in:
2023-02-20 00:29:28 -08:00
parent 4bfec16ba7
commit 9606b4dc9b
32 changed files with 779 additions and 286 deletions

View File

@ -66,6 +66,9 @@ int32_t DawnHost::init(DawnGame *game) {
game->inputManager.bind(INPUT_BIND_NEGATIVE_Y, GLFW_KEY_S);
game->inputManager.bind(INPUT_BIND_POSITIVE_Y, GLFW_KEY_W);
game->inputManager.bind(INPUT_BIND_MOUSE_X, INPUT_MANAGER_AXIS_MOUSE_X);
game->inputManager.bind(INPUT_BIND_MOUSE_Y, INPUT_MANAGER_AXIS_MOUSE_Y);
// Initialize the game
auto result = game->init();
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
@ -81,6 +84,7 @@ int32_t DawnHost::init(DawnGame *game) {
// Set up event listeners
glfwSetFramebufferSizeCallback(this->data->window, &glfwOnResize);
glfwSetKeyCallback(this->data->window, &glfwOnKey);
glfwSetCursorPosCallback(this->data->window, &glfwOnCursor);
return DAWN_HOST_INIT_RESULT_SUCCESS;
}
@ -178,4 +182,17 @@ void glfwOnKey(
// Determine the input axis
DAWN_HOST->game->inputManager.rawInputValues[key] = value;
}
void glfwOnCursor(GLFWwindow* window, double xpos, double ypos) {
if(DAWN_HOST == nullptr) return;
DAWN_HOST->game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_X] = mathClamp<float_t>(
(float_t)(xpos / DAWN_HOST->game->renderManager.backBuffer.getWidth()),
0, 1
);
DAWN_HOST->game->inputManager.rawInputValues[INPUT_MANAGER_AXIS_MOUSE_Y] = mathClamp<float_t>(
(float_t)(ypos / DAWN_HOST->game->renderManager.backBuffer.getHeight()),
0, 1
);
}

View File

@ -1,33 +1,34 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "host/DawnHost.hpp"
#define DAWN_GLFW_WINDOW_WIDTH_DEFAULT 1280
#define DAWN_GLFW_WINDOW_HEIGHT_DEFAULT 720
#define DAWN_GLFW_INIT_RESULT_INIT_FAILED -1
#define DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED -2
#define DAWN_GLFW_START_RESULT_UPDATE_FAILED -1
namespace Dawn {
class DawnHostData {
public:
GLFWwindow *window;
};
}
// GLFW Callbacks
void glfwOnError(int error, const char* description);
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
void glfwOnKey(
GLFWwindow *window,
int32_t key, int32_t scancode, int32_t action, int32_t mods
);
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "host/DawnHost.hpp"
#define DAWN_GLFW_WINDOW_WIDTH_DEFAULT 1280
#define DAWN_GLFW_WINDOW_HEIGHT_DEFAULT 720
#define DAWN_GLFW_INIT_RESULT_INIT_FAILED -1
#define DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED -2
#define DAWN_GLFW_START_RESULT_UPDATE_FAILED -1
namespace Dawn {
class DawnHostData {
public:
GLFWwindow *window;
};
}
// GLFW Callbacks
void glfwOnError(int error, const char* description);
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
void glfwOnKey(
GLFWwindow *window,
int32_t key, int32_t scancode, int32_t action, int32_t mods
);
void glfwOnCursor(GLFWwindow* window, double xpos, double ypos);

View File

@ -6,6 +6,9 @@
#pragma once
#include "input/_InputManager.hpp"
#define INPUT_MANAGER_AXIS_MOUSE_X -580000
#define INPUT_MANAGER_AXIS_MOUSE_Y -580001
namespace Dawn {
class InputManager : public IInputManager<int32_t> {
protected: