mirror of
https://github.com/PoetryInCode/simple-rigid-sim.git
synced 2025-06-11 19:53:09 -04:00
distance checking and cleaning
This commit is contained in:
parent
c65ae423f3
commit
5969248278
@ -1,8 +1,13 @@
|
||||
#include "Vector.h"
|
||||
#include <math.h>
|
||||
|
||||
Vector::Vector(float x, float y) {
|
||||
this->x=x;
|
||||
this->y=y;
|
||||
}
|
||||
|
||||
Vector::Vector() {}
|
||||
Vector::Vector() {}
|
||||
|
||||
int Vector::distanceTo(Vector vec) {
|
||||
return sqrt(pow(abs(x - vec.x),2)+pow(abs(y - vec.y),2));
|
||||
}
|
@ -5,5 +5,6 @@ class Vector {
|
||||
float x,y;
|
||||
Vector();
|
||||
Vector(float x, float y);
|
||||
int distanceTo(Vector vec);
|
||||
};
|
||||
#endif
|
@ -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<phys_obj> objects) {
|
||||
|
@ -1,15 +1,22 @@
|
||||
#include "BoundingBox.h"
|
||||
#include "Circle.h"
|
||||
#include <vector>
|
||||
|
||||
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<phys_obj> objects);
|
||||
void translate(Vector vec);
|
||||
bool checkCollision(phys_obj o);
|
||||
int distanceTo(Circle c);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user