|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
#include <string>
|
|
|
|
|
#include "../Sun.h"
|
|
|
|
|
#include "../Spaceship.h"
|
|
|
|
|
#include "../GameUtils.h"
|
|
|
|
|
|
|
|
|
|
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
|
|
|
|
|
|
|
|
@ -52,12 +53,8 @@ Core::RenderContext shipContext;
|
|
|
|
|
Core::RenderContext sphereContext;
|
|
|
|
|
|
|
|
|
|
Sun sun;
|
|
|
|
|
|
|
|
|
|
Spaceship spaceship;
|
|
|
|
|
GLuint VAO,VBO;
|
|
|
|
|
|
|
|
|
|
float aspectRatio = 1.f;
|
|
|
|
|
|
|
|
|
|
float exposition = 1.f;
|
|
|
|
|
|
|
|
|
|
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
|
|
|
|
@ -77,30 +74,9 @@ void updateDeltaTime(float time) {
|
|
|
|
|
lastTime = time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glm::mat4 createPerspectiveMatrix()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
glm::mat4 perspectiveMatrix;
|
|
|
|
|
float n = 0.05;
|
|
|
|
|
float f = 20.;
|
|
|
|
|
float a1 = glm::min(aspectRatio, 1.f);
|
|
|
|
|
float a2 = glm::min(1 / aspectRatio, 1.f);
|
|
|
|
|
perspectiveMatrix = glm::mat4({
|
|
|
|
|
1,0.,0.,0.,
|
|
|
|
|
0.,aspectRatio,0.,0.,
|
|
|
|
|
0.,0.,(f+n) / (n - f),2*f * n / (n - f),
|
|
|
|
|
0.,0.,-1.,0.,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
perspectiveMatrix=glm::transpose(perspectiveMatrix);
|
|
|
|
|
|
|
|
|
|
return perspectiveMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
|
|
|
|
|
|
|
|
|
|
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * spaceship.createCameraMatrix();
|
|
|
|
|
glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance().createCameraMatrix();
|
|
|
|
|
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
|
|
|
|
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
|
|
|
|
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
|
|
|
@ -112,7 +88,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "cameraPos"), spaceship.cameraPos.x, spaceship.cameraPos.y, spaceship.cameraPos.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "cameraPos"), Spaceship::getInstance().cameraPos.x, Spaceship::getInstance().cameraPos.y, Spaceship::getInstance().cameraPos.z);
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "sunDir"), sun.sunDir.x, sun.sunDir.y, sun.sunDir.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "sunColor"), sun.sunColor.x, sun.sunColor.y, sun.sunColor.z);
|
|
|
|
@ -120,10 +96,10 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "lightPos"), pointlightPos.x, pointlightPos.y, pointlightPos.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "lightColor"), pointlightColor.x, pointlightColor.y, pointlightColor.z);
|
|
|
|
|
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), spaceship.spotlightConeDir.x, spaceship.spotlightConeDir.y, spaceship.spotlightConeDir.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spaceship.spotlightPos.x, spaceship.spotlightPos.y, spaceship.spotlightPos.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spaceship.spotlightColor.x, spaceship.spotlightColor.y, spaceship.spotlightColor.z);
|
|
|
|
|
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spaceship.spotlightPhi);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightConeDir"), Spaceship::getInstance().spotlightConeDir.x, Spaceship::getInstance().spotlightConeDir.y, Spaceship::getInstance().spotlightConeDir.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightPos"), Spaceship::getInstance().spotlightPos.x, Spaceship::getInstance().spotlightPos.y, Spaceship::getInstance().spotlightPos.z);
|
|
|
|
|
glUniform3f(glGetUniformLocation(program, "spotlightColor"), Spaceship::getInstance().spotlightColor.x, Spaceship::getInstance().spotlightColor.y, Spaceship::getInstance().spotlightColor.z);
|
|
|
|
|
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), Spaceship::getInstance().spotlightPhi);
|
|
|
|
|
Core::DrawContext(context);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -152,19 +128,7 @@ void renderScene(GLFWwindow* window)
|
|
|
|
|
|
|
|
|
|
//space lamp
|
|
|
|
|
glUseProgram(programSun);
|
|
|
|
|
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * spaceship.createCameraMatrix();
|
|
|
|
|
glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1));
|
|
|
|
|
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
|
|
|
|
glUniform3f(glGetUniformLocation(programSun, "color"), sun.sunColor.x / 2, sun.sunColor.y / 2, sun.sunColor.z / 2);
|
|
|
|
|
glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition);
|
|
|
|
|
Core::DrawContext(sphereContext);
|
|
|
|
|
|
|
|
|
|
glm::mat4 viewProjectionMatrix2 = createPerspectiveMatrix() * spaceship.createCameraMatrix();
|
|
|
|
|
glm::mat4 transformation2 = viewProjectionMatrix2 * glm::translate(pointlightPos + glm::vec3(1, 1, 1)) * glm::scale(glm::vec3(0.1));
|
|
|
|
|
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation2);
|
|
|
|
|
glUniform3f(glGetUniformLocation(programSun, "color"), sun.sunColor.x / 2, sun.sunColor.y / 2, sun.sunColor.z / 2);
|
|
|
|
|
glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition);
|
|
|
|
|
Core::DrawContext(sphereContext);
|
|
|
|
|
sun.draw();
|
|
|
|
|
|
|
|
|
|
glUseProgram(program);
|
|
|
|
|
|
|
|
|
@ -191,7 +155,7 @@ void renderScene(GLFWwindow* window)
|
|
|
|
|
// glm::vec3(0.3, 0.3, 0.5)
|
|
|
|
|
// );
|
|
|
|
|
drawObjectPBR(shipContext,
|
|
|
|
|
spaceship.calculateModelMatrix(),
|
|
|
|
|
Spaceship::getInstance().calculateModelMatrix(),
|
|
|
|
|
glm::vec3(0.3, 0.3, 0.5),
|
|
|
|
|
0.2,1.0
|
|
|
|
|
);
|
|
|
|
@ -208,7 +172,7 @@ void renderScene(GLFWwindow* window)
|
|
|
|
|
}
|
|
|
|
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
aspectRatio = width / float(height);
|
|
|
|
|
GameUtils::getInstance().aspectRatio = width / float(height);
|
|
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
WIDTH = width;
|
|
|
|
|
HEIGHT = height;
|
|
|
|
@ -249,11 +213,12 @@ void init(GLFWwindow* window)
|
|
|
|
|
loadModelToContext("./models/pencils.obj", models::pencilsContext);
|
|
|
|
|
loadModelToContext("./models/plane.obj", models::planeContext);
|
|
|
|
|
loadModelToContext("./models/room.obj", models::roomContext);
|
|
|
|
|
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
|
|
|
|
loadModelToContext("./models/GameUtils::spaceship.obj", models::spaceshipContext);
|
|
|
|
|
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
|
|
|
|
loadModelToContext("./models/window.obj", models::windowContext);
|
|
|
|
|
loadModelToContext("./models/test.obj", models::testContext);
|
|
|
|
|
|
|
|
|
|
sun = Sun(programSun, models::sphereContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void shutdown(GLFWwindow* window)
|
|
|
|
@ -264,17 +229,16 @@ void shutdown(GLFWwindow* window)
|
|
|
|
|
//obsluga wejscia
|
|
|
|
|
void processInput(GLFWwindow* window)
|
|
|
|
|
{
|
|
|
|
|
spaceship.processInput(window, deltaTime);
|
|
|
|
|
Spaceship::getInstance().processInput(window, deltaTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
|
|
|
|
/*if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
|
|
|
|
exposition -= 0.05;
|
|
|
|
|
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
|
|
|
|
|
exposition += 0.05;
|
|
|
|
|
exposition += 0.05;*/
|
|
|
|
|
|
|
|
|
|
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
|
|
|
|
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);
|
|
|
|
|
printf("GameUtils::spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", Spaceship::getInstance().spaceshipPos.x, Spaceship::getInstance().spaceshipPos.y, Spaceship::getInstance().spaceshipPos.z);
|
|
|
|
|
printf("GameUtils::spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", Spaceship::getInstance().spaceshipDir.x, Spaceship::getInstance().spaceshipDir.y, Spaceship::getInstance().spaceshipDir.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//cameraDir = glm::normalize(-cameraPos);
|
|
|
|
|