Added isometric projection

This commit is contained in:
OLEGSHA 2021-03-26 02:15:29 +03:00
parent 1759b2257a
commit 00e110acb7
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A

View File

@ -160,6 +160,9 @@ GLFWwindow *window;
enum MODE {
BLOCK, PLANE
} currentMode = BLOCK;
enum CAMERA {
ANIMATED, ISOMETRIC
} currentCamera = ANIMATED;
int selection = 0;
bool light_theme = true;
@ -214,6 +217,7 @@ void glfw_shutdown_hook() {
}
void switch_mode();
void switch_camera();
void switch_theme();
void change_texture(int direction);
void close_texture();
@ -238,6 +242,9 @@ void on_key(GLFWwindow*, int key, int, int action, int mods) {
case GLFW_KEY_DELETE:
close_texture();
return;
case GLFW_KEY_TAB:
switch_camera();
return;
default:
// Do nothing
break;
@ -252,8 +259,6 @@ void on_drop(GLFWwindow*, int count, const char** paths) {
void switch_mode() {
if (LOADED_TEXTURES.empty()) return;
switch (currentMode) {
case BLOCK:
currentMode = PLANE;
@ -265,6 +270,18 @@ void switch_mode() {
}
void switch_camera() {
switch (currentCamera) {
case ANIMATED:
currentCamera = ISOMETRIC;
break;
case ISOMETRIC:
currentCamera = ANIMATED;
break;
}
}
void switch_theme() {
light_theme = !light_theme;
}
@ -716,11 +733,31 @@ void draw_block() {
1.0f
));
switch (currentCamera) {
case ANIMATED:
{
float t = static_cast<float>(glfwGetTime()) / 20;
transform = glm::rotate(transform, t * 3, glm::vec3(1, 0, 0));
transform = glm::rotate(transform, t * 7, glm::vec3(0, 1, 0));
transform = glm::rotate(transform, t * 11, glm::vec3(0, 0, 1));
}
break;
case ISOMETRIC:
constexpr const float SQRT_2 = 1.41421356237309504880168872420969808;
constexpr const float SQRT_3 = 1.73205080756887729352744634150587236;
constexpr const float SQRT_6 = SQRT_2 * SQRT_3;
transform *= glm::mat4(
1 / SQRT_2, 0, -1 / SQRT_2, 0,
1 / SQRT_6, SQRT_2 / SQRT_3, 1 / SQRT_6, 0,
1 / SQRT_3, -1 / SQRT_3, 1 / SQRT_3, 0,
0, 0, 0, 1
);
break;
}
transform = glm::scale(transform, glm::vec3(0.5));