diff --git a/src/main.cpp b/src/main.cpp index 46c23de..bb8fc48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -193,13 +193,13 @@ int main() { int floor_dis; for(uint i=0; i= objs[i].obj.radius && i != 0) { objs[i].force(Vector(0,1)); objs[i].translate(objs[i].velocity); printf("velocity of object %i (%f,%f)\n",i,objs[i].velocity.x,objs[i].velocity.y); //objs[i].calculate_vectors(objs); - } else { + }/* else { if(objs[i].velocity.y != 0) { printf("Zeroing object %i\n",i); objs[i].velocity.y = 0; @@ -209,7 +209,7 @@ int main() { objs[i].obj.y = h-objs[i].obj.radius; printf("Moving %i off of border to (%i,%i)\n",i,objs[i].obj.x,objs[i].obj.y); } - } + }*/ objs[i].render(rend); } if(change_vector[0]) { diff --git a/src/phys_obj.cpp b/src/phys_obj.cpp index d55bea8..a413222 100644 --- a/src/phys_obj.cpp +++ b/src/phys_obj.cpp @@ -105,25 +105,57 @@ bool allEq(std::vector nums, float comp) { } } -void phys_obj::calculate_vectors(std::vector *objects) { +void phys_obj::calculate_vectors( + std::vector *objects, + Vector win_dim +) { for(uint i=0; i win_dim.x) {//right wall collision + objects[0][a].translate(Vector( + -1*(ac.xDif(Vector(win_dim.x,0))+ao.radius), + 0 + )); + } + if(ac.y+ao.radius < 0 ) {//top collision + //zero out the y component if it has collided + objects[0][a].translate(Vector( + 0, + ac.yDif(Vector(0,ac.y+ao.radius)) + )); + } else if (ac.y+ao.radius > win_dim.y) {//bottom collision + objects[0][a].contact_floor = true; + objects[0][a].translate(Vector( + 0, + -1*(ac.yDif(Vector(0,win_dim.y-ao.radius))) + )); + }/* else { + if(objects[0][a].contact_floor) { + objects[0][a].contact_floor = false; + } + }*/ } } /* diff --git a/src/phys_obj.h b/src/phys_obj.h index 648a0ce..ef1f274 100644 --- a/src/phys_obj.h +++ b/src/phys_obj.h @@ -5,17 +5,15 @@ class phys_obj { public: Vector velocity; - //Quad obj; Circle obj; BoundingBox bounds; + bool contact_floor; phys_obj(); - //phys_obj(Quad object); - //phys_obj(Quad object, Vector init_vel); phys_obj(Circle c); phys_obj(Circle c, Vector init_vel); void force(Vector vec); void render(SDL_Renderer *rend); - static void calculate_vectors(std::vector *objects); + static void calculate_vectors(std::vector *objects, Vector win_dim); void translate(Vector vec); bool checkCollision(phys_obj o); float angleTo(phys_obj o);