MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / computeMatricesFromInputs

Method computeMatricesFromInputs

src/Scene/Camera.cpp:140–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140void Camera::computeMatricesFromInputs(bool &window_active, ImGuiIO &io, float deltaTime) {
141 if (!window_active)
142 return;
143 // Bail on the window active status if we hit the escape key
144 window_active = (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS);
145 io.MouseDrawCursor = true;
146
147 // Get mouse position and compute new orientation with it
148 horizontalAngle += mouseSpeed * (Config::get().resX / 2 - io.MousePos.x);
149 verticalAngle += mouseSpeed * (Config::get().resY / 2 - io.MousePos.y);
150
151 // Reset mouse position for next frame
152 glfwSetCursorPos(window, Config::get().resX / 2, Config::get().resY / 2);
153
154 // Direction : Spherical coordinates to Cartesian coordinates conversion
155 glm::vec3 direction(
156 cos(verticalAngle) * sin(horizontalAngle),
157 sin(verticalAngle),
158 cos(verticalAngle) * cos(horizontalAngle)
159 );
160
161 // Right vector
162 glm::vec3 right = glm::vec3(
163 sin(horizontalAngle - 3.14f / 2.0f),
164 0,
165 cos(horizontalAngle - 3.14f / 2.0f)
166 );
167
168 // Up vector
169 glm::vec3 up = glm::cross(right, direction);
170
171 // Speed boost
172 if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
173 speed = 100.0f;
174 } else {
175 speed = 3.0f;
176 }
177
178 if (ImGui::GetIO().MouseDown[1]) {
179 // Move forward
180 if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
181 position += direction * deltaTime * speed;
182 }
183 // Move backward
184 if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
185 position -= direction * deltaTime * speed;
186 }
187 // Strafe right
188 if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
189 position += right * deltaTime * speed;
190 }
191 // Strafe left
192 if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
193 position -= right * deltaTime * speed;
194 }
195 }
196
197 // Camera matrix

Callers 1

RenderMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected