Basic input handling, Editor camera Movement

This commit is contained in:
2023-01-04 19:01:58 +01:00
parent d5a6ddb9d5
commit 13f67a7cdb
15 changed files with 382 additions and 152 deletions

View File

@ -22,9 +22,10 @@ RendererConfig EditorSceneRendererConfig{
glm::vec3{0,0,0}, // Clear Color
true // Depth testing
};
glm::vec3 temp = glm::vec3(0);
Camera cam = Camera(glm::vec3(14.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90);
class Editor : public Application {
public:
Editor()
@ -35,6 +36,8 @@ public:
EditorGUIRenderer(AppWindow),
Selected((entt::entity)-1)
{
init_inputSystem(&AppWindow);
viewportRenderer.setCurrentFrameBuffer(*framebuffer);
}
@ -71,6 +74,74 @@ public:
{
Viewport sceneview = Viewport(*framebuffer, viewportRenderer.getCamera());
if (sceneview.isFocused)
{
const float movement_speed = 0.1f;
static float lastX = 400, lastY = 300;
const float sensitivity = 0.1;
static bool firstMouse = true;
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_MIDDLE) ){
auto newX = getCursorPosX(&AppWindow);
auto newY = getCursorPosY(&AppWindow);
if (firstMouse)
{
lastX = newX;
lastY = newY;
firstMouse = false;
}
float xoffset = newX - lastX;
float yoffset = newY - lastY;
lastX = newX;
lastY = newY;
xoffset *= sensitivity;
yoffset *= sensitivity;
cam.yaw += xoffset;
cam.pitch += yoffset;
if (cam.pitch > 89.0f)
cam.pitch = 89.0f;
if (cam.pitch < -89.0f)
cam.pitch = -89.0f;
}
// Check for Camara movement input here!
if (keyIsPressed(YOGGIE_KEY_W)) {
cam.Position += cam.Front * movement_speed;
}
if (keyIsPressed(YOGGIE_KEY_A))
{
cam.Position -= cam.Right * movement_speed;
}
if (keyIsPressed(YOGGIE_KEY_S)) {
cam.Position -= cam.Front * movement_speed;
}
if (keyIsPressed(YOGGIE_KEY_D)) {
cam.Position += cam.Right * movement_speed;
}
}
}
{
@ -136,7 +207,7 @@ public:
lag += elapsed;
AppWindow.Poll();
cam.Update();
Physics.Step(elapsed);
ActiveScene.Update();
@ -170,6 +241,8 @@ private:
bool SimulatePhysics = true;
entt::entity Selected;
std::unique_ptr<Project> CurrentProject;
Scene ActiveScene;