Improve lights

This commit is contained in:
MrLetsplay 2023-09-16 20:59:07 +02:00
parent fa41614783
commit 5ecab3b668
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
2 changed files with 28 additions and 18 deletions

@ -1 +1 @@
Subproject commit 656603f4396872afd07565a02f5d73bb66885ec2 Subproject commit 4026a0992857b70bf5bcd0dda14ebe9af9251ffe

View File

@ -32,7 +32,7 @@ using namespace kek;
#define CHUNK_RADIUS 2 #define CHUNK_RADIUS 2
#define WALLS_PER_CHUNK 20 #define WALLS_PER_CHUNK 20
#define WALL_HEIGHT 9 #define WALL_HEIGHT 9
#define LIGHT_SPACING 8 #define LIGHT_SPACING 16
static ButtonElement *buttonPlay; static ButtonElement *buttonPlay;
@ -49,8 +49,7 @@ struct Chunk {
std::map<long int, Chunk> loadedChunks; std::map<long int, Chunk> loadedChunks;
Mesh *floorMesh; Mesh *floorMesh;
TextElement *debugText; TextElement *debugText;
std::shared_ptr<Texture> red; std::shared_ptr<Texture> red, gray, white, wallpaper;
std::shared_ptr<Texture> gray;
void gameLoop(GLFWwindow *window, void *) { void gameLoop(GLFWwindow *window, void *) {
Player *player = Engine::getPlayer(); Player *player = Engine::getPlayer();
@ -70,11 +69,16 @@ void gameLoop(GLFWwindow *window, void *) {
const Chunk *ch = &it->second; const Chunk *ch = &it->second;
if(std::abs(ch->x - chunkX) > CHUNK_RADIUS || abs(ch->z - chunkZ) > CHUNK_RADIUS) { if(std::abs(ch->x - chunkX) > CHUNK_RADIUS || abs(ch->z - chunkZ) > CHUNK_RADIUS) {
scene->removeObject(ch->floor); scene->removeObject(ch->floor);
scene->removeObject(ch->ceiling);
for(auto w : ch->walls) { for(auto w : ch->walls) {
scene->removeObject(w); scene->removeObject(w);
} }
for(auto l : ch->lights) {
scene->lights->remove(l);
}
it = loadedChunks.erase(it); it = loadedChunks.erase(it);
continue; continue;
} }
@ -82,8 +86,6 @@ void gameLoop(GLFWwindow *window, void *) {
it = std::next(it); it = std::next(it);
} }
std::shared_ptr<Texture> wallpaper = Texture::load("image/wallpaper.png");
for(int x = chunkX - CHUNK_RADIUS; x <= chunkX + CHUNK_RADIUS; x++) { for(int x = chunkX - CHUNK_RADIUS; x <= chunkX + CHUNK_RADIUS; x++) {
for(int z = chunkZ - CHUNK_RADIUS; z <= chunkZ + CHUNK_RADIUS; z++) { for(int z = chunkZ - CHUNK_RADIUS; z <= chunkZ + CHUNK_RADIUS; z++) {
long int chunkID = ((long int) x & 0xFFFF) << 16 | ((long int) z & 0xFFFF); long int chunkID = ((long int) x & 0xFFFF) << 16 | ((long int) z & 0xFFFF);
@ -97,7 +99,7 @@ void gameLoop(GLFWwindow *window, void *) {
GameObject *ceiling = new GameObject(); GameObject *ceiling = new GameObject();
ceiling->addMesh(genCubeMesh(CHUNK_SIZE, 2, CHUNK_SIZE, gray, gray, gray)); ceiling->addMesh(genCubeMesh(CHUNK_SIZE, 2, CHUNK_SIZE, gray, gray, gray));
ceiling->addPhysics(new btBoxShape(btVector3(CHUNK_SIZE / 2, 1, CHUNK_SIZE / 2)), 0, btCollisionObject::CF_STATIC_OBJECT); // ceiling->addPhysics(new btBoxShape(btVector3(CHUNK_SIZE / 2, 1, CHUNK_SIZE / 2)), 0, btCollisionObject::CF_STATIC_OBJECT);
ceiling->moveTo(glm::vec3(x * CHUNK_SIZE, WALL_HEIGHT, z * CHUNK_SIZE)); ceiling->moveTo(glm::vec3(x * CHUNK_SIZE, WALL_HEIGHT, z * CHUNK_SIZE));
scene->addObject(ceiling); scene->addObject(ceiling);
@ -120,15 +122,23 @@ void gameLoop(GLFWwindow *window, void *) {
} }
std::vector<PointLight *> lights; std::vector<PointLight *> lights;
// for(int lx = 0; lx < CHUNK_SIZE / LIGHT_SPACING; lx++) { for(int lx = 0; lx < CHUNK_SIZE / LIGHT_SPACING; lx++) {
// for(int ly = 0; ly < CHUNK_SIZE / LIGHT_SPACING; ly++) { for(int ly = 0; ly < CHUNK_SIZE / LIGHT_SPACING; ly++) {
// SpotLight *light = new SpotLight(glm::vec3(1), glm::vec3(0, -1, 0), 1, 1, 1, 0.5, 0.6); // SpotLight *light = new SpotLight(glm::vec3(1), glm::vec3(0, -1, 0), 1, 1, 1, 0.5, 0.6);
PointLight *light = new PointLight(glm::vec3(1), 1, 1, 1); glm::vec3 lightPos(x * CHUNK_SIZE + lx * LIGHT_SPACING, WALL_HEIGHT - 1, z * CHUNK_SIZE + ly * LIGHT_SPACING);
light->moveTo(glm::vec3(x * CHUNK_SIZE, WALL_HEIGHT - 1, z * CHUNK_SIZE));
scene->lights->add(light); PointLight *light = new PointLight(glm::vec3(1), 1, 1, 1);
lights.push_back(light); light->moveTo(glm::vec3(x * CHUNK_SIZE + lx * LIGHT_SPACING, WALL_HEIGHT - 1, z * CHUNK_SIZE + ly * LIGHT_SPACING));
// } scene->lights->add(light);
//} lights.push_back(light);
GameObject *lamp = new GameObject();
lamp->addMesh(genCubeMesh(2, 0.5, 2, white, white, white));
lamp->moveTo(lightPos);
walls.push_back(lamp);
scene->addObject(lamp);
}
}
Chunk newChunk{x, z, floor, ceiling, walls, lights}; Chunk newChunk{x, z, floor, ceiling, walls, lights};
loadedChunks.emplace(chunkID, newChunk); loadedChunks.emplace(chunkID, newChunk);
@ -142,8 +152,8 @@ void startGame(void *) {
Scene *scene = new Scene(); Scene *scene = new Scene();
std::shared_ptr<Texture> wallpaper = Texture::load("image/wallpaper.png"); wallpaper = Texture::load("image/wallpaper.png");
std::shared_ptr<Texture> white = Texture::generateColor(glm::vec3(1)); white = Texture::generateColor(glm::vec3(1));
red = Texture::generateColor(glm::vec3(1, 0, 0)); red = Texture::generateColor(glm::vec3(1, 0, 0));
gray = Texture::generateColor(glm::vec3(0.2, 0.2, 0.2)); gray = Texture::generateColor(glm::vec3(0.2, 0.2, 0.2));