master
Nicole Collings 2020-05-31 15:18:47 -07:00
parent e4b3a42cb6
commit 043014a805
4 changed files with 77 additions and 3 deletions

View File

@ -70,9 +70,9 @@ void Camera::createMatrices() {
void Camera::update() {
front = glm::normalize(glm::vec3 {
static_cast<float>(cos(glm::radians(yaw)) * cos(glm::radians(pitch))),
static_cast<float>(sin(glm::radians(pitch))),
static_cast<float>(sin(glm::radians(yaw)) * cos(glm::radians(pitch)))});
static_cast<float>(cos(yaw) * cos(pitch)),
static_cast<float>(sin(pitch)),
static_cast<float>(sin(yaw) * cos(pitch))});
right = glm::normalize(glm::cross(front, worldUp));
up = glm::normalize(glm::cross(right, front));
}

View File

@ -0,0 +1,50 @@
//
// Created by aurailus on 2020-05-31.
//
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <cmath>
#include <glm/glm.hpp>
#include <iostream>
#include "ViewportControl.h"
#include "../graph/Camera.h"
#include "Input.h"
ViewportControl::ViewportControl(Input &input, Camera &camera) :
input(input),
camera(camera) {}
void ViewportControl::update() {
if (input.keyDown(GLFW_MOUSE_BUTTON_LEFT)) {
yaw += -input.mouseDelta().x * panFactor;
pitch += -input.mouseDelta().y * panFactor;
}
float camAngleX = yaw;
float camAngleY = pitch;
camera.setPos({
distance * -sinf(camAngleX) * cosf(camAngleY),
distance * -sinf(camAngleY),
-distance * cosf(camAngleX) * cosf(camAngleY)
});
std::cout << camera.getPos().x << ", " << camera.getPos().y << ", " << camera.getPos().z << std::endl;
glm::vec3 cp = -camera.getPos();
// camera.setPitch(asin(-cp.y));
// camera.setYaw(atan2(cp.x, cp.z));
camera.setPitch(asin(cp.y / glm::length(cp)));
camera.setYaw(asin(cp.z / (cos(asin(cp.y / glm::length(cp))) * glm::length(cp))));
// camera.setPos({sin(yaw) * distance * sin(pitch), sin(pitch) * distance, cos(yaw) * distance * sin(pitch)});
// camera.setYaw(-yaw);
// camera.setPitch(-pitch);
}

View File

@ -0,0 +1,24 @@
//
// Created by aurailus on 2020-05-31.
//
#pragma once
class Input;
class Camera;
class ViewportControl {
public:
ViewportControl(Input& input, Camera& camera);
void update();
private:
Input& input;
Camera& camera;
double panFactor = 0.01;
double distance = 60;
double pitch, yaw;
};