Skip to content

Commit

Permalink
Added rolling
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Aug 20, 2024
1 parent ea21fa5 commit 0b761da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions GUI/include/ImGuiCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace Prisma {
bool m_pressed = false;
bool m_save = false;

float m_totalVelocity = 0;

std::shared_ptr<Prisma::CallbackHandler> m_callback;

Node* m_currentSelect;
Expand Down
17 changes: 10 additions & 7 deletions GUI/src/ImGuiCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../include/PixelCapture.h"
#include "../../Engine/include/Helpers/SettingsLoader.h"
#include "../../Engine/include/SceneData/SceneExporter.h"
#include "../../Engine/include/engine.h"

Prisma::ImGuiCamera::ImGuiCamera()
{
Expand All @@ -19,6 +20,7 @@ void Prisma::ImGuiCamera::updateCamera(std::shared_ptr<Prisma::Camera> camera)
camera->center(m_position + m_front);
camera->up(m_up);
}
m_totalVelocity = m_velocity * 1.0f / (float)Prisma::Engine::getInstance().fps();
}

void Prisma::ImGuiCamera::keyboardUpdate(void* windowData)
Expand All @@ -33,26 +35,26 @@ void Prisma::ImGuiCamera::keyboardUpdate(void* windowData)
}

if (glfwGetKey(window, Prisma::KEY_W) == GLFW_PRESS) {
m_position += m_front * m_velocity;
m_position += m_front * m_totalVelocity;
}

if (glfwGetKey(window, Prisma::KEY_A) == GLFW_PRESS) {
m_position -= glm::normalize(glm::cross(m_front, m_up)) * m_velocity;
m_position -= glm::normalize(glm::cross(m_front, m_up)) * m_totalVelocity;
}

if (glfwGetKey(window, Prisma::KEY_S) == GLFW_PRESS && (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS) && !m_save) {
Prisma::Exporter::getInstance().exportScene();
m_save = true;
}else if (glfwGetKey(window, Prisma::KEY_S) == GLFW_PRESS && !(glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS || glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) {
m_position -= m_front * m_velocity;
m_position -= m_front * m_totalVelocity;
}

if(glfwGetKey(window, Prisma::KEY_S) == GLFW_RELEASE || glfwGetKey(window, GLFW_KEY_LEFT_CONTROL == GLFW_RELEASE) || glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL == GLFW_RELEASE)) {
m_save = false;
}

if (glfwGetKey(window, Prisma::KEY_D) == GLFW_PRESS) {
m_position += glm::normalize(glm::cross(m_front, m_up)) * m_velocity;
m_position += glm::normalize(glm::cross(m_front, m_up)) * m_totalVelocity;
}

if (glfwGetKey(window, Prisma::KEY_G) == GLFW_PRESS && !m_pressed) {
Expand Down Expand Up @@ -153,12 +155,13 @@ void Prisma::ImGuiCamera::mouseButtonCallback() {

m_callback->rollMouse = [this](double xOffset,double yOffset) {
if (yOffset > 0) {
m_velocity += 0.1f; // Increase velocity when scrolling up
m_velocity += 1.0f; // Increase velocity when scrolling up

}
else if (yOffset < 0) {
m_velocity -= 0.1f; // Decrease velocity when scrolling down
m_velocity -= 1.0f; // Decrease velocity when scrolling down
if (m_velocity < 0.1f) {
m_velocity = 0.1f; // Prevent velocity from becoming too small or negative
m_velocity = 1.0f; // Prevent velocity from becoming too small or negative
}
}
};
Expand Down
1 change: 0 additions & 1 deletion GUI/src/ImguiDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ void Prisma::ImguiDebug::close()
m_fps = 1.0f / static_cast<float>(currentFrameTime - m_lastFrameTime);
}
m_lastFrameTime = currentFrameTime;
m_imguiCamera.velocity(1.0f / fps());

m_imguiCamera.updateCamera(m_camera);
m_imguiCamera.keyboardUpdate(PrismaFunc::getInstance().window());
Expand Down

0 comments on commit 0b761da

Please sign in to comment.