Skip to content

Commit

Permalink
Added keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
denis authored and denis committed Jul 31, 2024
1 parent a0f36f3 commit a77c020
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions UserEngine/include/UserEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ class UserEngine : public Prisma::UserData {

std::shared_ptr<Prisma::Scene> m_root;

GLFWwindow* m_window;

};
17 changes: 17 additions & 0 deletions UserEngine/src/UserEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void UserEngine::start()
Prisma::Physics::getInstance().physicsWorld()->dynamicsWorld->setGravity(btVector3(0.0, -10.0, 0.0));
m_handler = std::make_shared<Prisma::CallbackHandler>();
createCamera();
m_window = Prisma::PrismaFunc::getInstance().window();
}

void UserEngine::update()
Expand All @@ -61,13 +62,29 @@ std::shared_ptr<Prisma::CallbackHandler> UserEngine::callbacks()

void UserEngine::updateCamera()
{
m_velocity = 1 * 1.0f/(float)Prisma::Engine::getInstance().fps();
updateKeyboard();
m_root->camera->position(m_position);
m_root->camera->center(m_position + m_front);
m_root->camera->up(m_up);
}

void UserEngine::updateKeyboard()
{

if (glfwGetKey(m_window, Prisma::KEY_W) == GLFW_PRESS) {
m_position += m_front * m_velocity;
}
if (glfwGetKey(m_window, Prisma::KEY_A) == GLFW_PRESS) {
m_position -= glm::normalize(glm::cross(m_front, m_up)) * m_velocity;
}
if (glfwGetKey(m_window, Prisma::KEY_S) == GLFW_PRESS) {
m_position -= m_front * m_velocity;
}

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

void UserEngine::createCamera()
Expand Down

0 comments on commit a77c020

Please sign in to comment.