dodanie funkcji zmieniania tekstur planety i słońca oraz siły światła

This commit is contained in:
K4RP4T 2024-01-20 23:37:51 +01:00
parent 54689b0edf
commit 0c10ffa5ac
27 changed files with 57 additions and 44 deletions

View File

@ -14,8 +14,9 @@
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <string> #include <string>
/*
namespace texturePlanets { namespace texturePlanets {
GLuint blank;
GLuint earth; GLuint earth;
GLuint planet; GLuint planet;
GLuint mercury; GLuint mercury;
@ -55,7 +56,7 @@ namespace textureMoons {
namespace textureMaterials { namespace textureMaterials {
GLuint clouds; GLuint clouds;
} }
*/
GLuint program; GLuint program;
GLuint programSun; GLuint programSun;
GLuint programDepth; GLuint programDepth;
@ -65,13 +66,25 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext sphereContext; Core::RenderContext sphereContext;
glm::vec3 sunPos = glm::vec3(12.f, 0.f, 12.f); const char* const planetTexPaths[] = { "./textures/planets/earth.png", "./textures/planets/mercury.png", "./textures/planets/venus.jpg", "./textures/planets/mars.jpg",
float sunSize = 0.04f; "./textures/planets/jupiter.jpg", "./textures/planets/saturn.jpg", "./textures/planets/uranus.jpg", "./textures/planets/neptune.jpg", "./textures/planets/icy.png",
"./textures/planets/volcanic.png", "./textures/planets/desert.png", "./textures/planets/tropical.png", "./textures/planets/toxic.jpg", "./textures/planets/swamp.png",
"./textures/planets/savannah.png", "./textures/planets/alpine.png", "./textures/planets/ceres.jpg", "./textures/planets/eris.jpg", "./textures/planets/haumea.jpg",
"./textures/planets/makemake.jpg" };
int planetTexIndex = 80;
GLuint planetTex;
glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f); glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f);
float planetSize = 0.005f; float planetSize = 0.005f;
float planetRot = 0.f; float planetRot = 0.f;
const char* const sunTexPaths[] = { "./textures/suns/sol.jpg", "./textures/suns/orange.jpg", "./textures/suns/lava.png", "./textures/suns/star.png", "./textures/suns/sun.jpg" };
int sunTexIndex = 20;
GLuint sunTex;
glm::vec3 sunPos = glm::vec3(12.f, 0.f, 12.f);
float sunSize = 0.04f;
glm::vec3 cameraPos = glm::vec3(-2.f, 0.f, 0.f); glm::vec3 cameraPos = glm::vec3(-2.f, 0.f, 0.f);
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f); glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
@ -87,7 +100,8 @@ unsigned int depthMapFBO;
int HDR_WIDTH = 1024; int HDR_WIDTH = 1024;
int HDR_HEIGHT = 1024; int HDR_HEIGHT = 1024;
glm::vec3 lightColor = glm::vec3(50, 50, 50); float lightPower = 50.f;
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
glm::mat4 createCameraMatrix() { glm::mat4 createCameraMatrix() {
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f))); glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
@ -228,16 +242,16 @@ void renderScene(GLFWwindow* window) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime(); float time = glfwGetTime();
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
glm::mat4 sunTranslate = glm::translate(sunPos);
drawSun(sphereContext, sunTranslate * sunScale, textureSuns::sun1);
glm::mat4 planetScale = glm::scale(glm::vec3(planetSize)); glm::mat4 planetScale = glm::scale(glm::vec3(planetSize));
glm::mat4 planetRotate = glm::rotate(time * planetRot, glm::vec3(0, 1, 0)); glm::mat4 planetRotate = glm::rotate(time * planetRot, glm::vec3(0, 1, 0));
glm::mat4 planetTranslate = glm::translate(planetPos); glm::mat4 planetTranslate = glm::translate(planetPos);
drawObjectTexture(sphereContext, planetTranslate * planetRotate * planetScale, texturePlanets::earth); drawObjectTexture(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
glm::mat4 sunTranslate = glm::translate(sunPos);
drawSun(sphereContext, sunTranslate * sunScale, sunTex);
glfwSwapBuffers(window); glfwSwapBuffers(window);
} }
@ -273,34 +287,8 @@ void init(GLFWwindow* window) {
loadModelToContext("./models/sphere.obj", sphereContext); loadModelToContext("./models/sphere.obj", sphereContext);
texturePlanets::earth = Core::LoadTexture("./textures/planets/earth2.png"); planetTex = Core::LoadTexture(planetTexPaths[std::abs(planetTexIndex % 20)]);
/*texturePlanets::planet = Core::LoadTexture("./textures/planets/planet.png"); sunTex = Core::LoadTexture(sunTexPaths[std::abs(sunTexIndex % 5)]);
texturePlanets::mercury = Core::LoadTexture("./textures/planets/mercury1.jpg");
texturePlanets::venus = Core::LoadTexture("./textures/planets/earth2.png");
texturePlanets::mars = Core::LoadTexture("./textures/planets/mars.jpg");
texturePlanets::alpine = Core::LoadTexture("./textures/planets/Alpine.png");
texturePlanets::ceres = Core::LoadTexture("./textures/planets/ceres_fictional.jpg");
texturePlanets::eris = Core::LoadTexture("./textures/planets/eris_fictional.jpg");
texturePlanets::haumea = Core::LoadTexture("./textures/planets/haumea_fictional.jpg");
texturePlanets::icy = Core::LoadTexture("./textures/planets/Icy.png");
texturePlanets::jupiter = Core::LoadTexture("./textures/planets/jupiter.jpg");
texturePlanets::makemake = Core::LoadTexture("./textures/planets/makemake_fictional.jpg");
texturePlanets::martian = Core::LoadTexture("./textures/planets/Martian.png");
texturePlanets::neptune = Core::LoadTexture("./textures/planets/neptune.jpg");
texturePlanets::saturn = Core::LoadTexture("./textures/planets/saturn.jpg");
texturePlanets::savannah = Core::LoadTexture("./textures/planets/Savannah.png");
texturePlanets::swamp = Core::LoadTexture("./textures/planets/Swamp.png");
texturePlanets::tropical = Core::LoadTexture("./textures/planets/Tropical.png");
texturePlanets::uranus = Core::LoadTexture("./textures/planets/uranus.jpg");
texturePlanets::venusian = Core::LoadTexture("./textures/planets/Venusian.png");
texturePlanets::volcanic = Core::LoadTexture("./textures/planets/Volcanic.png");*/
textureSuns::sun1 = Core::LoadTexture("./textures/suns/sun1.jpg");
/*textureSuns::sun2 = Core::LoadTexture("./textures/suns/sun2.jpg");
textureSuns::sun3 = Core::LoadTexture("./textures/suns/sun3.jpg");
textureSuns::sun4 = Core::LoadTexture("./textures/suns/sun4.jpg");*/
textureMaterials::clouds = Core::LoadTexture("./textures/planets/clouds.jpg");
} }
void shutdown(GLFWwindow* window) { void shutdown(GLFWwindow* window) {
@ -318,7 +306,7 @@ void processInput(GLFWwindow* window)
//ruch kamerą //ruch kamerą
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f))); glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
float cameraSpeed = 0.01f; float cameraSpeed = 0.02f;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS && glm::length(planetPos - cameraPos) > 0.01f * 150) if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS && glm::length(planetPos - cameraPos) > 0.01f * 150)
cameraPos += cameraDir * cameraSpeed; cameraPos += cameraDir * cameraSpeed;
@ -347,10 +335,35 @@ void processInput(GLFWwindow* window)
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.f) if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.f)
planetRot -= rotationSpeed; planetRot -= rotationSpeed;
//if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) //zmiana tekstury planety
// cameraDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(cameraDir, 0)); if (glfwGetKey(window, GLFW_KEY_T) == GLFW_PRESS) {
//if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) planetTex = Core::LoadTexture(planetTexPaths[std::abs(++planetTexIndex % 20)]);
// cameraDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(cameraDir, 0)); Sleep(200);
}
if (glfwGetKey(window, GLFW_KEY_Y) == GLFW_PRESS && planetTexIndex > 0) {
planetTex = Core::LoadTexture(planetTexPaths[std::abs(--planetTexIndex % 20)]);
Sleep(200);
}
//zmiana tekstury słońca
if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) {
sunTex = Core::LoadTexture(sunTexPaths[std::abs(++sunTexIndex % 5)]);
Sleep(200);
}
if (glfwGetKey(window, GLFW_KEY_I) == GLFW_PRESS && sunTexIndex > 0) {
sunTex = Core::LoadTexture(sunTexPaths[std::abs(--sunTexIndex % 5)]);
Sleep(200);
}
//siła światła
float powerSpeed = 0.5f;
if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS && lightPower < 250.f)
lightPower += powerSpeed;
if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS && lightPower > 0.5f)
lightPower -= powerSpeed;
lightColor = glm::vec3(lightPower, lightPower, lightPower);
} }
// funkcja jest glowna petla // funkcja jest glowna petla

View File

Before

Width:  |  Height:  |  Size: 9.2 MiB

After

Width:  |  Height:  |  Size: 9.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

Before

Width:  |  Height:  |  Size: 879 KiB

After

Width:  |  Height:  |  Size: 879 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 852 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

View File

Before

Width:  |  Height:  |  Size: 803 KiB

After

Width:  |  Height:  |  Size: 803 KiB

View File

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

Before

Width:  |  Height:  |  Size: 183 KiB

After

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 465 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB