35 glfwGetWindowSize(
renderer.getWindow(), &width, &height);
38 aspect =
static_cast<float>(width) /
static_cast<float>(height);
48 transform.rotation.y += input.look.x * cam.mouseSensitivity;
49 transform.rotation.x += input.look.y * cam.mouseSensitivity;
50 transform.rotation.x = glm::clamp(transform.rotation.x, -89.f, 89.f);
54 forward.x = cos(glm::radians(transform.rotation.x)) * cos(glm::radians(transform.rotation.y));
55 forward.y = sin(glm::radians(transform.rotation.x));
56 forward.z = cos(glm::radians(transform.rotation.x)) * sin(glm::radians(transform.rotation.y));
58 float forwardLen = glm::length(forward);
59 forward = (forwardLen > 1e-4f) ? glm::normalize(forward) : glm::vec3(0.0f, 0.0f, -1.0f);
61 glm::vec3 crossProduct = glm::cross(forward, glm::vec3(0, 1, 0));
62 glm::vec3 right = glm::vec3(1, 0, 0);
63 if (glm::length(crossProduct) > 1e-4f) {
64 right = glm::normalize(crossProduct);
67 glm::vec3 upCross = glm::cross(right, forward);
68 glm::vec3 up = glm::vec3(0, 1, 0);
69 if (glm::length(upCross) > 1e-4f) {
70 up = glm::normalize(upCross);
74 forward * input.movement.z +
75 right * input.movement.x +
76 up * input.movement.y;
78 transform.position += move * cam.moveSpeed * dt;
79 renderer.setActiveCamera(cam.projection(), transform.position, cam.view(transform));
90 glm::mat4 vp = cam.projection() * cam.view(transform);
91 renderer.setActiveCamera(cam.projection(), transform.position, cam.view(transform));
92 renderer.setGameplayCamera(vp, transform.position);
103 if (cam && transform) {
104 cam->aspect = aspect;
105 glm::mat4 vp = cam->projection() * cam->view(*transform);
106 renderer.setActiveCamera(cam->projection(), transform->position, cam->
view(*transform));
107 renderer.setGameplayCamera(vp, transform->position);