#include "ModelWorld.h" #include ModelWorld::ModelWorld() { light.lightDirection = glm::normalize(glm::vec3((cos(lightPitch) * cos(lightYaw)), (sin(lightPitch)), (cos(lightPitch) * sin(lightYaw)))); light.radiance = 3.f * lightColor; RenderingSystem::instance().exposure = 0.45f; model = std::make_shared("Models/David_Brown_25D_tractor_SF/David_Brown_25D_tractor_SF.obj"); model->setPosition({ 0,0,0 }); model->setScale(glm::vec3(0.5)); addActor(model); camera.Position = { 0,5,10 }; } void ModelWorld::logicalTick(float deltaTime) { World::logicalTick(deltaTime); } void ModelWorld::rendererTick(float deltaTime) { World::rendererTick(deltaTime); } void ModelWorld::cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { static bool firstMouse = true; static float lastX; static float lastY; float xoffset = xpos - lastX; float yoffset = lastY - ypos; lastX = xpos; lastY = ypos; if (firstMouse) { firstMouse = false; return; } if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) camera.processMouseMovement(xoffset, yoffset); if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) { float speed = 0.2f; model->setRotaion(glm::rotate(glm::quat(1, 0, 0, 0), glm::radians(glm::length(glm::vec2(xoffset, yoffset)) * speed), glm::vec3(glm::vec2(-yoffset, xoffset), 0.0)) * model->getRotation()); } } void ModelWorld::scrollCallback(GLFWwindow* window, double xoffset, double yoffset) { camera.processMouseScroll(yoffset); } void ModelWorld::processInput(GLFWwindow* window, float deltaTime) { if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) camera.processKeyboard(FORWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) camera.processKeyboard(BACKWARD, deltaTime); if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) camera.processKeyboard(LEFT, deltaTime); if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) camera.processKeyboard(RIGHT, deltaTime); if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) camera.processKeyboard(UP, deltaTime); if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) camera.processKeyboard(DOWN, deltaTime); float speed = 0.1; if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) model->setPosition(model->getPosition() + glm::vec3(0, 0, -speed)); if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) model->setPosition(model->getPosition() + glm::vec3(0, 0, speed)); if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) model->setPosition(model->getPosition() + glm::vec3(-speed, 0, 0)); if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) model->setPosition(model->getPosition() + glm::vec3(speed, 0, 0)); }