Prześlij pliki do 'src'
This commit is contained in:
parent
159ea35614
commit
6ad07de5dd
@ -19,12 +19,13 @@
|
|||||||
|
|
||||||
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
||||||
|
|
||||||
int WIDTH = 500, HEIGHT = 500;
|
int WIDTH = 900, HEIGHT = 900;
|
||||||
|
|
||||||
namespace models {
|
namespace models {
|
||||||
Core::RenderContext spaceshipContext;
|
Core::RenderContext spaceshipContext;
|
||||||
Core::RenderContext sphereContext;
|
Core::RenderContext sphereContext;
|
||||||
|
|
||||||
|
Core::RenderContext windowFrame;
|
||||||
Core::RenderContext bookShelf;
|
Core::RenderContext bookShelf;
|
||||||
Core::RenderContext window;
|
Core::RenderContext window;
|
||||||
Core::RenderContext potPlant;
|
Core::RenderContext potPlant;
|
||||||
@ -37,7 +38,7 @@ namespace models {
|
|||||||
}
|
}
|
||||||
namespace textures {
|
namespace textures {
|
||||||
GLuint sunTexture;
|
GLuint sunTexture;
|
||||||
GLuint windowUkTexture;
|
GLuint windowFrameTexture;
|
||||||
GLuint bookShelfTexture;
|
GLuint bookShelfTexture;
|
||||||
GLuint potPlantTexture;
|
GLuint potPlantTexture;
|
||||||
GLuint officeChariTexture;
|
GLuint officeChariTexture;
|
||||||
@ -60,6 +61,21 @@ GLuint programSkybox;
|
|||||||
|
|
||||||
bool flashOff = false;
|
bool flashOff = false;
|
||||||
|
|
||||||
|
double prevTime = 0.0;
|
||||||
|
double currTime = 0.0;
|
||||||
|
double timeDiff;
|
||||||
|
unsigned int counter = 0;
|
||||||
|
|
||||||
|
glm::vec3 position = glm::vec3(0, 0, 5);
|
||||||
|
float horizontalAngle = 3.14f;
|
||||||
|
float verticalAngle = 0.0f;
|
||||||
|
float speed = 0.1f;
|
||||||
|
float sensitivity = 100.0f;
|
||||||
|
double xpos, ypos;
|
||||||
|
glm::vec3 Position;
|
||||||
|
glm::vec3 Orientation = glm::vec3(0.0f, 0.0f, -1.0f);
|
||||||
|
glm::vec3 Up = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
|
|
||||||
Core::RenderContext shipContext;
|
Core::RenderContext shipContext;
|
||||||
@ -197,12 +213,12 @@ void renderShadowapSun() {
|
|||||||
|
|
||||||
glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
|
glm::mat4 lightVP = glm::ortho(-3.f, 2.3f, -1.3f, 3.f, -1.0f, 40.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
|
||||||
|
|
||||||
//drawObjectDepth(sphereContext,
|
drawObjectDepth(sphereContext,
|
||||||
// lightVP,
|
lightVP,
|
||||||
// glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)));
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)));
|
||||||
//drawObjectDepth(sphereContext,
|
drawObjectDepth(sphereContext,
|
||||||
// lightVP,
|
lightVP,
|
||||||
// glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)));
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)));
|
||||||
//drawObjectDepth(models::bedContext,
|
//drawObjectDepth(models::bedContext,
|
||||||
// lightVP,
|
// lightVP,
|
||||||
// glm::mat4());
|
// glm::mat4());
|
||||||
@ -263,11 +279,11 @@ void renderScene(GLFWwindow* window)
|
|||||||
|
|
||||||
|
|
||||||
drawObjectPBR(models::window, glm::mat4(),
|
drawObjectPBR(models::window, glm::mat4(),
|
||||||
textures::windowUkTexture,
|
textures::windowFrameTexture,
|
||||||
0.2,
|
0.2,
|
||||||
0.1
|
0.1
|
||||||
);
|
);
|
||||||
drawObjectPBR(models::potPlant, glm::mat4() * glm::scale(glm::vec3(0.2f)) * glm::translate(glm::vec3(-5.0f, 3.0f, -6.0f)),
|
drawObjectPBR(models::potPlant, glm::mat4() * glm::scale(glm::vec3(0.2f)) * glm::translate(glm::vec3(-5.0f, 55.0f, -6.0f)),
|
||||||
textures::potPlantTexture,
|
textures::potPlantTexture,
|
||||||
1.0f,
|
1.0f,
|
||||||
0.2f
|
0.2f
|
||||||
@ -287,7 +303,7 @@ void renderScene(GLFWwindow* window)
|
|||||||
0.4f,
|
0.4f,
|
||||||
0.0f
|
0.0f
|
||||||
);
|
);
|
||||||
drawObjectPBR(models::desk, glm::mat4() * glm::translate(glm::vec3(-3.0, 0.0, -3.0f)),
|
drawObjectPBR(models::desk, glm::mat4(),
|
||||||
textures::deskTexture,
|
textures::deskTexture,
|
||||||
0.4f,
|
0.4f,
|
||||||
0.0f
|
0.0f
|
||||||
@ -302,6 +318,10 @@ void renderScene(GLFWwindow* window)
|
|||||||
0.3f,
|
0.3f,
|
||||||
0.0f
|
0.0f
|
||||||
);
|
);
|
||||||
|
drawObjectPBR(models::windowFrame, glm::mat4(),
|
||||||
|
textures::windowFrameTexture,
|
||||||
|
0.2f,
|
||||||
|
0.0f);
|
||||||
drawObjectPBR(models::bookShelf, glm::mat4() * glm::scale(glm::vec3(0.01)),
|
drawObjectPBR(models::bookShelf, glm::mat4() * glm::scale(glm::vec3(0.01)),
|
||||||
textures::bookShelfTexture,
|
textures::bookShelfTexture,
|
||||||
0.4f,
|
0.4f,
|
||||||
@ -392,26 +412,19 @@ void init(GLFWwindow* window)
|
|||||||
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
|
||||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||||
|
|
||||||
|
loadModelToContext("./models2/Frame/Frame.obj", models::windowFrame);
|
||||||
loadModelToContext("./models2/bookshelf/shelf.obj", models::bookShelf);
|
loadModelToContext("./models2/bookshelf/shelf.obj", models::bookShelf);
|
||||||
loadModelToContext("./models2/potplant/Pot.obj", models::potPlant);
|
loadModelToContext("./models2/potplant/Pot.obj", models::potPlant);
|
||||||
loadModelToContext("./models2/lamp/Lamp_LOVMANAD_OBJ.obj", models::lamp);
|
loadModelToContext("./models2/lamp/Lamp_LOVMANAD_OBJ.obj", models::lamp);
|
||||||
loadModelToContext("./models2/door/source/door.obj", models::door);
|
loadModelToContext("./models2/door/source/door.obj", models::door);
|
||||||
loadModelToContext("./models2/bed/untitled.obj", models::bed);
|
|
||||||
loadModelToContext("./models2/ceiling_lamp/ceilinglamp.obj", models::ceilingLamp);
|
|
||||||
loadModelToContext("./models2/desk/Desk0.5.obj", models::desk);
|
|
||||||
//loadModelToContext("./models2/chair/Office_chair.obj", models::officeChair);
|
|
||||||
//loadModelToContext("./models2/window/WindowUK.obj", models::window);
|
|
||||||
|
|
||||||
|
|
||||||
textures::flashlightTexture = Core::LoadTexture("./models/FlashlightTexture.png");
|
textures::flashlightTexture = Core::LoadTexture("./models/FlashlightTexture.png");
|
||||||
textures::sunTexture = Core::LoadTexture("./models/sun.jpeg");
|
textures::sunTexture = Core::LoadTexture("./models/sun.jpeg");
|
||||||
|
textures::windowFrameTexture = Core::LoadTexture("./models2/Frame/frame.png");
|
||||||
textures::bookShelfTexture = Core::LoadTexture("./models2/bookshelf/SHELF_TEXTURE.bmp");
|
textures::bookShelfTexture = Core::LoadTexture("./models2/bookshelf/SHELF_TEXTURE.bmp");
|
||||||
textures::potPlantTexture = Core::LoadTexture("./models2/potplant/b3.bmp");
|
textures::potPlantTexture = Core::LoadTexture("./models2/potplant/b3.bmp");
|
||||||
textures::lampTexture = Core::LoadTexture("./models2/lamp/_Base_color.png");
|
textures::lampTexture = Core::LoadTexture("./models2/lamp/_Base_color.png");
|
||||||
textures::doorTexture = Core::LoadTexture("./models2/door/textures/Door_albedo.bmp");
|
textures::doorTexture = Core::LoadTexture("./models2/door/textures/Door_albedo.bmp");
|
||||||
textures::bedTexture = Core::LoadTexture("./models2/bed/bed.png");
|
|
||||||
textures::ceilingLampTexture = Core::LoadTexture("./models2/ceiling_lamp/ceilingLamp.png");
|
|
||||||
textures::deskTexture = Core::LoadTexture("./models2/desk/defsk.png");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown(GLFWwindow* window)
|
void shutdown(GLFWwindow* window)
|
||||||
@ -449,6 +462,29 @@ void processInput(GLFWwindow* window)
|
|||||||
flashOff = false;
|
flashOff = false;
|
||||||
if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS)
|
||||||
flashOff = true;
|
flashOff = true;
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_6) == GLFW_RELEASE)
|
||||||
|
{
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
|
glfwGetCursorPos(window, &xpos, &ypos);
|
||||||
|
|
||||||
|
float rotX = sensitivity * (float)(xpos - (WIDTH / 2)) / HEIGHT;
|
||||||
|
float rotY = sensitivity * (float)(ypos - (HEIGHT / 2)) / WIDTH;
|
||||||
|
|
||||||
|
glm::vec3 newOrientation = glm::rotate(spaceshipDir, glm::radians(-rotY), glm::normalize(glm::cross(spaceshipDir, spaceshipUp)));
|
||||||
|
|
||||||
|
|
||||||
|
// Decides whether or not the next vertical Orientation is legal or not
|
||||||
|
if (abs(glm::angle(newOrientation, spaceshipUp) - glm::radians(90.0f)) <= glm::radians(85.0f))
|
||||||
|
{
|
||||||
|
spaceshipDir = newOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rotates the Orientation left and right
|
||||||
|
spaceshipDir = glm::rotate(spaceshipDir, glm::radians(-rotX), spaceshipUp);
|
||||||
|
|
||||||
|
glfwSetCursorPos(window, WIDTH/2, HEIGHT/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cameraPos = spaceshipPos - 0.6 * spaceshipDir + glm::vec3(0, 1, 0) * 0.26f;
|
cameraPos = spaceshipPos - 0.6 * spaceshipDir + glm::vec3(0, 1, 0) * 0.26f;
|
||||||
@ -472,6 +508,20 @@ void processInput(GLFWwindow* window)
|
|||||||
void renderLoop(GLFWwindow* window) {
|
void renderLoop(GLFWwindow* window) {
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
currTime = glfwGetTime();
|
||||||
|
timeDiff = currTime - prevTime;
|
||||||
|
counter++;
|
||||||
|
|
||||||
|
if (timeDiff >= 1.0 / 30.0)
|
||||||
|
{
|
||||||
|
std::string FPS = std::to_string((1.0 / timeDiff) * counter);
|
||||||
|
std::string newTitle = "Super Gra - " + FPS + " FPS";
|
||||||
|
glfwSetWindowTitle(window, newTitle.c_str());
|
||||||
|
|
||||||
|
prevTime = currTime;
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
processInput(window);
|
processInput(window);
|
||||||
|
|
||||||
renderScene(window);
|
renderScene(window);
|
||||||
|
@ -17,13 +17,15 @@ int main(int argc, char** argv)
|
|||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
//glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// tworzenie okna za pomoca glfw
|
// tworzenie okna za pomoca glfw
|
||||||
GLFWwindow* window = glfwCreateWindow(500, 500, "FirstWindow", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(900, 900, "FirstWindow", NULL, NULL);
|
||||||
|
glfwSetWindowPos(window, 500, 30);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create GLFW window" << std::endl;
|
std::cout << "Failed to create GLFW window" << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user