Make the global camera move I guess
This commit is contained in:
parent
f56d1e558e
commit
adb7f45052
|
@ -1,7 +1,7 @@
|
|||
#include <chrono>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
|
@ -111,12 +111,45 @@ int main(int argc, char** argv)
|
|||
messager.registerCallback(&debug_messagebus_callback);
|
||||
int window_height, window_width;
|
||||
glm::mat4 projection;
|
||||
glm::mat4 view = glm::lookAt(glm::vec3(4,3,3), glm::vec3(0,0,0), glm::vec3(0,1,0));
|
||||
glm::vec3 camera_position = glm::vec3(4.f, 3.f, 3.f);
|
||||
glm::mat4 view = glm::lookAt(camera_position, glm::vec3(0,0,0), glm::vec3(0,1,0));
|
||||
glm::mat4 model_matrix = glm::mat4(1.0f);
|
||||
glm::mat4 model_default = glm::mat4(1.0f);
|
||||
// The model matrix should eventually be translation * rotation * scale
|
||||
glm::mat4 mvp_matrix;
|
||||
|
||||
// "Global" camera input controls
|
||||
double camera_velocity = 1.0;
|
||||
glm::vec3 camera_translation;
|
||||
// Tick timer
|
||||
std::chrono::time_point start = std::chrono::high_resolution_clock::now();
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
// Tick timer
|
||||
auto dt = ((std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - start)).count()) / 100000000.f;
|
||||
start = std::chrono::high_resolution_clock::now();
|
||||
// Process input.
|
||||
glfwPollEvents();
|
||||
|
||||
// Camera movement?
|
||||
double cv_x = 0.f;
|
||||
double cv_y = 0.f;
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
|
||||
cv_x += camera_velocity * dt;
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
||||
cv_x -= camera_velocity * dt;
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
|
||||
cv_y += camera_velocity * dt;
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
|
||||
cv_y -= camera_velocity * dt;
|
||||
}
|
||||
camera_translation = glm::vec3(cv_x, cv_y, 0.f);
|
||||
auto ctm = glm::translate(glm::mat4(1.0f), camera_translation);
|
||||
auto ncp = ctm * glm::vec4(camera_position[0], camera_position[1], camera_position[2], 1.0f);
|
||||
camera_position = glm::vec3(ncp[0], ncp[1], ncp[2]);
|
||||
view = glm::lookAt(camera_position, glm::vec3(0,0,0), glm::vec3(0,1,0));
|
||||
|
||||
// Process messages
|
||||
int messages_treated = messager.processAll();
|
||||
|
@ -133,7 +166,6 @@ int main(int argc, char** argv)
|
|||
|
||||
// Render game geometries
|
||||
glfwGetWindowSize(window, &window_width, &window_height);
|
||||
// 45d FoV
|
||||
projection = glm::perspective(glm::radians(fov), (float) window_width / (float) window_height,
|
||||
0.1f, 100.0f);
|
||||
mvp_matrix = projection * view * model_default;
|
||||
|
|
Loading…
Reference in New Issue