namespace {
constexpr GLfloat vtx_coords[] = {
- -1.0f, -1.0f, -5.0f,
- 1.0f, -1.0f, -5.0f,
- 0.0f, 1.0f, -5.0f,
+ -1.0f, -1.0f, 0.0f,
+ 1.0f, -1.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
};
}
, ctx(window.CreateContext())
, init_glew()
, program()
+, pitch_sensitivity(-0.0025f)
+, yaw_sensitivity(-0.001f)
, cam()
+, model()
, vtx_buf(0)
, mvp_handle(0)
, running(false) {
glBindBuffer(GL_ARRAY_BUFFER, vtx_buf);
glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_coords), vtx_coords, GL_STATIC_DRAW);
+ model.Position(glm::vec3(0, 0, -4));
+ cam.Position(glm::vec3(0, 0, 4));
+
mvp_handle = program.UniformLocation("MVP");
glClearColor(0.0, 0.0, 0.0, 1.0);
void Application::Run() {
running = true;
Uint32 last = SDL_GetTicks();
+ window.GrabMouse();
while (running) {
Uint32 now = SDL_GetTicks();
int delta = now - last;
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
+ case SDL_MOUSEMOTION:
+ cam.RotateYaw(event.motion.xrel * yaw_sensitivity);
+ cam.RotatePitch(event.motion.yrel * pitch_sensitivity);
+ std::cout << "x: " << event.motion.xrel << ", y: " << event.motion.yrel
+ << ", pitch: " << cam.Pitch() << ", yaw: " << cam.Yaw() << std::endl;
+ break;
case SDL_QUIT:
running = false;
break;
program.Use();
- glm::mat4 model(1.0f); // identity: no transformation
- glm::mat4 mvp(cam.MakeMVP(model));
+ glm::mat4 mvp(cam.MakeMVP(model.Transform()));
glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]);
glEnableVertexAttribArray(0);