From 55bce45d45a7f6f1c100e2695ee0e07f3c10a31e Mon Sep 17 00:00:00 2001 From: Seth Long Date: Mon, 2 Dec 2024 16:39:09 -0800 Subject: [PATCH] Added explode effect --- Makefile | 3 ++- geometric_objects.cpp | 1 - geometric_objects.h | 2 +- main.cpp | 3 ++- maze.cpp | 21 ++++++++++++++++++++- maze.h | 5 +++-- sphere_gs.glsl | 10 ++++++---- sphere_tes.glsl | 17 +++++++++++++++-- sphere_vs.glsl | 6 +++--- 9 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index c53694b..ac5ffc1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ OBJS = main.o stb_image.o helpers.o tiny_obj_loader.o baseclass.o old_objects.o geometric_objects.o hud.o door.o vehicle.o maze.o -CXXFLAGS = -g -Wall -std=c++20 +CXXFLAGS = -g -Wall -std=c++17 LDFLAGS = -lGL -lglfw -lGLEW -pthread -g # For FreeBSD (doesn't seem to hurt anything on Linux) @@ -16,4 +16,5 @@ test: all ./a.out ${OBJS} : game.h +maze.o : maze.h main.o : projectiles.h activation_area.h turret.h tile_floor.h old_objects.h moving_platform.h geometric_objects.h hud.h door.h vehicle.h maze.h diff --git a/geometric_objects.cpp b/geometric_objects.cpp index 01737b8..15af383 100644 --- a/geometric_objects.cpp +++ b/geometric_objects.cpp @@ -193,7 +193,6 @@ void sphere::draw(glm::mat4 vp){ glBufferData(GL_SHADER_STORAGE_BUFFER, radii.size() * sizeof(float), radii.data(), GL_STATIC_DRAW); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, radii_buffer); - data_mutex.unlock(); glEnableVertexAttribArray(v_attrib); diff --git a/geometric_objects.h b/geometric_objects.h index 4e5751c..1335d75 100644 --- a/geometric_objects.h +++ b/geometric_objects.h @@ -66,7 +66,7 @@ public: virtual void addsphere(glm::vec3 location, float radius, glm::vec3 up = glm::vec3(0, 1, 0), glm::vec3 forward = glm::vec3(0, 0, 1)); }; -class rollsphere : virtual public sphere, virtual public block_object { +class rollsphere : virtual public sphere { public: std::vector new_locations; std::vector speeds; diff --git a/main.cpp b/main.cpp index 01a06b4..2fca852 100644 --- a/main.cpp +++ b/main.cpp @@ -272,7 +272,8 @@ void pos_callback(GLFWwindow* window, double xpos, double ypos){ double diff_y = ypos - center_y; glfwSetCursorPos(window, center_x, center_y); player_heading -= diff_x / 1000.0; // Is this too fast or slow? - player_elevation -= diff_y / 1000.0; + if((diff_y > 0 && player_elevation - diff_y/1000.0 > -M_PI/2) || (diff_y < 0 && player_elevation - diff_y/1000.0 < M_PI/2)) + player_elevation -= diff_y / 1000.0; } void resize(GLFWwindow*, int new_width, int new_height){ diff --git a/maze.cpp b/maze.cpp index 1a03e0a..9a026a4 100644 --- a/maze.cpp +++ b/maze.cpp @@ -44,12 +44,19 @@ void maze_solver::launch(float maze_height){ void maze_solver::move(int elapsed_time) { for(size_t i = 0; i < locations.size(); i++){ + if(locations[i].z < 580 && locations[i].y <= -95){ // TODO: If the maze ends somewhere else, this would be wrong + ups[i].a -= 0.1 * solve_speed; + } + if(locations[i].z < 540 && locations[i].y <= -95){ + remove(i); + continue; + } bool found_next = false; if(speeds[i] < 0.001){ for(auto &n : intpoint(locations[i]).neighbors()){ if(!is_empty(n.vec3(), 0.0f)) continue; - if(visiteds[i].contains(n)) + if(visiteds[i].count(n)) continue; visiteds[i].insert(n); stacks[i].push_back(n); @@ -71,3 +78,15 @@ void maze_solver::move(int elapsed_time) { } rollsphere::move(elapsed_time); } + +void maze_solver::remove(size_t idx){ + locations.erase(locations.begin() + idx); + radii.erase(radii.begin() + idx); + ups.erase(ups.begin() + idx); + forwards.erase(forwards.begin() + idx); + new_locations.erase(new_locations.begin() + idx); + speeds.erase(speeds.begin() + idx); + rotation_matrices.erase(rotation_matrices.begin() + idx); + visiteds.erase(visiteds.begin() + idx); + stacks.erase(stacks.begin() + idx); +} diff --git a/maze.h b/maze.h index 1529c21..8ed6041 100644 --- a/maze.h +++ b/maze.h @@ -30,9 +30,9 @@ class maze_solver : public rollsphere { } std::vector neighbors(){ std::vector retval; + retval.push_back(intpoint(x, y, z - 8)); retval.push_back(intpoint(x - 8, y, z)); retval.push_back(intpoint(x + 8, y, z)); - retval.push_back(intpoint(x, y, z - 8)); retval.push_back(intpoint(x, y, z + 8)); return retval; } @@ -41,9 +41,10 @@ class maze_solver : public rollsphere { } }; public: - float solve_speed = 0.01f; + float solve_speed = 0.1f; std::vector> visiteds; std::vector> stacks; void launch(float maze_height); void move(int elapsed_time) override; + void remove(size_t idx); }; diff --git a/sphere_gs.glsl b/sphere_gs.glsl index f245b13..ac8accb 100644 --- a/sphere_gs.glsl +++ b/sphere_gs.glsl @@ -1,5 +1,7 @@ #version 450 +in mat4 mvp[]; +in vec4 normal[]; layout(triangles, invocations=1) in; in vec4 tes_colorout[]; layout(line_strip, max_vertices=6) out; @@ -7,16 +9,16 @@ out vec4 gs_colorout; void main(void) { - gl_Position = gl_in[0].gl_Position; + gl_Position = mvp[0] * (10 * normal[0] + gl_in[0].gl_Position); gs_colorout = tes_colorout[0]; EmitVertex(); - gl_Position = gl_in[1].gl_Position; + gl_Position = mvp[1] * (10 * normal[0] + gl_in[1].gl_Position); gs_colorout = tes_colorout[1]; EmitVertex(); - gl_Position = gl_in[2].gl_Position; + gl_Position = mvp[2] * (10 * normal[0] + gl_in[2].gl_Position); gs_colorout = tes_colorout[2]; EmitVertex(); - gl_Position = gl_in[0].gl_Position; + gl_Position = mvp[0] * (10 * normal[0] + gl_in[0].gl_Position); gs_colorout = tes_colorout[0]; EmitVertex(); EndPrimitive(); diff --git a/sphere_tes.glsl b/sphere_tes.glsl index 973f7aa..a2d0d32 100644 --- a/sphere_tes.glsl +++ b/sphere_tes.glsl @@ -6,7 +6,7 @@ layout(packed, binding=0) buffer model_list { mat4 models[]; }; layout(packed, binding=1) buffer up_list { - vec3 ups[]; + vec4 ups[]; }; layout(packed, binding=2) buffer forward_list { vec3 forwards[]; @@ -14,11 +14,16 @@ layout(packed, binding=2) buffer forward_list { layout(packed, binding=3) buffer radii_list { float radii[]; }; +layout(packed, binding=4) buffer explode_list { + float explode_factor[]; +}; uniform mat4 vp; in vec4 tcs_colorout[]; in int vs_id_tcs[]; out vec4 tes_colorout; +out vec4 normal; +out mat4 mvp; vec4 n4(vec4 p){ vec3 offset = p.xyz;// - cntr[0].xyz; @@ -31,7 +36,15 @@ void main(){ gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position; - gl_Position = vp * models[vs_id_tcs[0]] * n4(p); + float ef = ups[vs_id_tcs[0]].a; + if(ef > 0) + normal = vec4(0, 0, 0, 0); + else + normal = -ef * vec4(normalize(p.xyz), 0); + + mvp = vp * models[vs_id_tcs[0]]; + + gl_Position = n4(p); tes_colorout = gl_TessCoord.x * tcs_colorout[0] + diff --git a/sphere_vs.glsl b/sphere_vs.glsl index d1bd307..02534b4 100644 --- a/sphere_vs.glsl +++ b/sphere_vs.glsl @@ -5,7 +5,7 @@ layout(packed, binding=0) buffer model_list { mat4 models[]; }; layout(packed, binding=1) buffer up_list { - vec3 ups[]; + vec4 ups[]; }; layout(packed, binding=2) buffer forward_list { vec3 forwards[]; @@ -21,10 +21,10 @@ out vec4 v_colorout; out int vs_id; void main(void) { - vec3 sideways = normalize(cross(ups[gl_InstanceID], forwards[gl_InstanceID])); + vec3 sideways = normalize(cross(ups[gl_InstanceID].xyz, forwards[gl_InstanceID])); vec3 pos = in_vertex.x * sideways + in_vertex.y * forwards[gl_InstanceID] + - in_vertex.z * ups[gl_InstanceID]; + in_vertex.z * ups[gl_InstanceID].xyz; gl_Position = vec4(pos, 1.0); v_colorout = vec4(in_vertex, 1.0); -- 2.47.3