diff --git a/src/Vector.cpp b/src/Vector.cpp index c656c21..767d55d 100644 --- a/src/Vector.cpp +++ b/src/Vector.cpp @@ -1,8 +1,13 @@ #include "Vector.h" +#include Vector::Vector(float x, float y) { this->x=x; this->y=y; } -Vector::Vector() {} \ No newline at end of file +Vector::Vector() {} + +int Vector::distanceTo(Vector vec) { + return sqrt(pow(abs(x - vec.x),2)+pow(abs(y - vec.y),2)); +} \ No newline at end of file diff --git a/src/Vector.h b/src/Vector.h index e6b5a54..533477e 100644 --- a/src/Vector.h +++ b/src/Vector.h @@ -5,5 +5,6 @@ class Vector { float x,y; Vector(); Vector(float x, float y); + int distanceTo(Vector vec); }; #endif \ No newline at end of file diff --git a/src/phys_obj.cpp b/src/phys_obj.cpp index 5347099..89871ad 100644 --- a/src/phys_obj.cpp +++ b/src/phys_obj.cpp @@ -1,29 +1,54 @@ #include "phys_obj.h" -#ifndef PI -#define PI 3.14159265359 -#endif - +/* phys_obj::phys_obj(Quad object, Vector init_vel) { this->obj=object; this->velocity=init_vel; this->bounds=BoundingBox(object); -} +}*/ void phys_obj::force(Vector vec) { this->velocity.x += vec.x; this->velocity.y += vec.y; } void phys_obj::render(SDL_Renderer *rend) { + /* + if(obj.isInitialized()) { + if(circle.isInitialized()) { + circle.render(rend); + } else { + fprintf(stderr,"[ERROR] Could not render object"); + } + } else { + obj.render(rend); + }*/ obj.render(rend); - bounds.render(rend); +} + +phys_obj::phys_obj(Circle c, Vector init_vel) { + this->obj = c; + this->velocity = init_vel; +} + +phys_obj::phys_obj(Circle c) { + this->obj = c; + this->velocity = Vector(0,0); } void phys_obj::translate(Vector vec) { obj.translate(vec); - bounds.update(); + //bounds.update(); +} + +int phys_obj::distanceTo(Circle c) { + return obj.center.distanceTo(c.center); } bool phys_obj::checkCollision(phys_obj o) { + if(distanceTo(o.obj) <= obj.radius) { + return true; + } else { + return false; + } } void phys_obj::calculate_vectors(std::vector objects) { diff --git a/src/phys_obj.h b/src/phys_obj.h index 7048a31..5371ea6 100644 --- a/src/phys_obj.h +++ b/src/phys_obj.h @@ -1,15 +1,22 @@ #include "BoundingBox.h" +#include "Circle.h" #include class phys_obj { public: Vector velocity; - Quad obj; + //Quad obj; + Circle obj; BoundingBox bounds; - phys_obj(Quad object, Vector init_vel); + 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); void translate(Vector vec); bool checkCollision(phys_obj o); + int distanceTo(Circle c); }; \ No newline at end of file