50 lines
2.0 KiB
C++
50 lines
2.0 KiB
C++
#include "glm.hpp"
|
|
#include "ext.hpp"
|
|
|
|
#pragma once
|
|
class Spaceship
|
|
{
|
|
public:
|
|
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
|
|
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
|
|
|
|
glm::mat4 calculateModelMatrix() {
|
|
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
|
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
|
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
|
|
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
|
|
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
|
|
-spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
|
|
0.,0.,0.,1.,
|
|
});
|
|
|
|
return glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f));
|
|
}
|
|
|
|
void processInput(GLFWwindow* window, float deltaTime) {
|
|
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
|
glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
|
|
float angleSpeed = 0.05f * deltaTime * 60;
|
|
float moveSpeed = 0.05f * deltaTime * 60;
|
|
|
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
|
glfwSetWindowShouldClose(window, true);
|
|
}
|
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
|
spaceshipPos += spaceshipDir * moveSpeed;
|
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
|
spaceshipPos -= spaceshipDir * moveSpeed;
|
|
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
|
|
spaceshipPos += spaceshipSide * moveSpeed;
|
|
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
|
spaceshipPos -= spaceshipSide * moveSpeed;
|
|
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
|
spaceshipPos += spaceshipUp * moveSpeed;
|
|
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
|
spaceshipPos -= spaceshipUp * moveSpeed;
|
|
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
|
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
|
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
|
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
|
}
|
|
}; |