]> isoptera.lcsc.edu Git - example_engine/.git/commitdiff
Added explode effect
authorSeth Long <sslong@lcsc.edu>
Tue, 3 Dec 2024 00:39:09 +0000 (16:39 -0800)
committerSeth Long <sslong@lcsc.edu>
Tue, 3 Dec 2024 00:39:09 +0000 (16:39 -0800)
Makefile
geometric_objects.cpp
geometric_objects.h
main.cpp
maze.cpp
maze.h
sphere_gs.glsl
sphere_tes.glsl
sphere_vs.glsl

index c53694ba8af0defb3a24b461a13ddd08b520b396..ac5ffc1369d69271b4b68cfc414118d3a059e678 100644 (file)
--- 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
index 01737b8aec2df3dfd57636a06b04251be9b7f77e..15af383ff37dbf67e09557318a0a08f41c2926b1 100644 (file)
@@ -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);
index 4e5751c060059a1f7a3720930b44933009b5a5f2..1335d7577d113763ec454a9447ed155e85370107 100644 (file)
@@ -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<glm::vec3> new_locations;
        std::vector<float> speeds;
index 01a06b45b0a136070f9f583e296732c427b8c8d7..2fca852fb0428c563b345ec158101b7de1edd61d 100644 (file)
--- 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){
index 1a03e0aa64aeb476b7fcc6245c23dc246529b66d..9a026a46930354ccc802fb9f68824b915cc21a48 100644 (file)
--- 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 1529c21e17aaa1808cf0bf52965f332f510976df..8ed6041bc366d1f76e1594f78c655b98229da43e 100644 (file)
--- a/maze.h
+++ b/maze.h
@@ -30,9 +30,9 @@ class maze_solver : public rollsphere {
                }
                std::vector<intpoint> neighbors(){
                        std::vector<intpoint> 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<std::set<intpoint>> visiteds;
        std::vector<std::vector<intpoint>> stacks;
        void launch(float maze_height);
        void move(int elapsed_time) override;
+       void remove(size_t idx);
 };
index f245b1381e84f008dc7548dd4f906c1c267d6e0b..ac8accbbf5a4f45e3a8106a90f58019b5bed9f99 100644 (file)
@@ -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();
index 973f7aa4da37424383a822c3bc304ae166e00742..a2d0d32d5f0b10b9e6fd6b842011802eb8e5d1e4 100644 (file)
@@ -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] +
index d1bd30772c60f3c7ea6b4181c131ceb40c05970d..02534b4a83976bdf6747f00292a985f0aea6ac5b 100644 (file)
@@ -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);