create spaceship class
This commit is contained in:
parent
4bdf8d5e8b
commit
5ee26a6c64
50
grk/project/Spaceship.h
Normal file
50
grk/project/Spaceship.h
Normal file
@ -0,0 +1,50 @@
|
||||
#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));
|
||||
}
|
||||
};
|
@ -23,6 +23,7 @@
|
||||
<ClCompile Include="src\Texture.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Spaceship.h" />
|
||||
<ClInclude Include="src\Camera.h" />
|
||||
<ClInclude Include="src\ex_9_1.hpp" />
|
||||
<ClInclude Include="src\objload.h" />
|
||||
|
@ -92,6 +92,9 @@
|
||||
<ClInclude Include="Sun.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Spaceship.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader_8_sun.vert">
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <assimp/postprocess.h>
|
||||
#include <string>
|
||||
#include "../Sun.h"
|
||||
#include "../Spaceship.h"
|
||||
|
||||
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
||||
|
||||
@ -55,9 +56,7 @@ Sun sun;
|
||||
glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f);
|
||||
glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f);
|
||||
|
||||
|
||||
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
|
||||
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
|
||||
Spaceship spaceship;
|
||||
GLuint VAO,VBO;
|
||||
|
||||
float aspectRatio = 1.f;
|
||||
@ -205,28 +204,18 @@ void renderScene(GLFWwindow* window)
|
||||
drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(0.9f, 0.9f, 0.9f), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::windowContext, glm::mat4(), glm::vec3(0.402978f, 0.120509f, 0.057729f), 0.2f, 0.0f);
|
||||
|
||||
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.,
|
||||
});
|
||||
|
||||
|
||||
//drawObjectColor(shipContext,
|
||||
// glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()),
|
||||
// glm::vec3(0.3, 0.3, 0.5)
|
||||
// );
|
||||
drawObjectPBR(shipContext,
|
||||
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
|
||||
spaceship.calculateModelMatrix(),
|
||||
glm::vec3(0.3, 0.3, 0.5),
|
||||
0.2,1.0
|
||||
);
|
||||
|
||||
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
|
||||
spotlightConeDir = spaceshipDir;
|
||||
spotlightPos = spaceship.spaceshipPos + 0.2 * spaceship.spaceshipDir;
|
||||
spotlightConeDir = spaceship.spaceshipDir;
|
||||
|
||||
|
||||
|
||||
@ -298,32 +287,11 @@ void shutdown(GLFWwindow* window)
|
||||
//obsluga wejscia
|
||||
void processInput(GLFWwindow* window)
|
||||
{
|
||||
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));
|
||||
spaceship.processInput(window, deltaTime);
|
||||
|
||||
|
||||
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
||||
cameraDir = spaceshipDir;
|
||||
cameraPos = spaceship.spaceshipPos - 0.5 * spaceship.spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
||||
cameraDir = spaceship.spaceshipDir;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
||||
exposition -= 0.05;
|
||||
@ -331,8 +299,8 @@ void processInput(GLFWwindow* window)
|
||||
exposition += 0.05;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
||||
printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceshipPos.x, spaceshipPos.y, spaceshipPos.z);
|
||||
printf("spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", spaceshipDir.x, spaceshipDir.y, spaceshipDir.z);
|
||||
printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceship.spaceshipPos.x, spaceship.spaceshipPos.y, spaceship.spaceshipPos.z);
|
||||
printf("spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", spaceship.spaceshipDir.x, spaceship.spaceshipDir.y, spaceship.spaceshipDir.z);
|
||||
}
|
||||
|
||||
//cameraDir = glm::normalize(-cameraPos);
|
||||
|
Loading…
Reference in New Issue
Block a user