mirror of
https://github.com/PoetryInCode/simple-rigid-sim.git
synced 2025-06-08 02:23:10 -04:00
working on collision detection
This commit is contained in:
parent
16181aa737
commit
21e373d1ec
@ -1,5 +1,9 @@
|
||||
#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;
|
||||
@ -12,4 +16,47 @@ void phys_obj::force(Vector vec) {
|
||||
void phys_obj::render(SDL_Renderer *rend) {
|
||||
obj.render(rend);
|
||||
bounds.render(rend);
|
||||
}
|
||||
|
||||
void phys_obj::translate(Vector vec) {
|
||||
obj.translate(vec);
|
||||
bounds.update();
|
||||
}
|
||||
|
||||
bool phys_obj::checkCollision(phys_obj o) {
|
||||
}
|
||||
|
||||
void phys_obj::calculate_vectors(std::vector<phys_obj> objects) {
|
||||
for(int i=0; i<objects.size(); i++) {
|
||||
Vector step;
|
||||
int xvel = objects[i].velocity.x;
|
||||
int yvel = objects[i].velocity.y;
|
||||
if(xvel != 0) {
|
||||
if(xvel < 0) {
|
||||
objects[i].velocity.x++;
|
||||
step.x = -1;
|
||||
} else {
|
||||
if(xvel > 0) {
|
||||
objects[i].velocity.x--;
|
||||
step.x = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(yvel != 0) {
|
||||
if(yvel < 0) {
|
||||
objects[i].velocity.y++;
|
||||
step.y = -1;
|
||||
} else {
|
||||
if(yvel > 0) {
|
||||
objects[i].velocity.y--;
|
||||
step.y = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
objects[i].translate(step);
|
||||
for(int y=0; y<objects.size(); y++) {
|
||||
if(y != i) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#include "BoundingBox.h"
|
||||
#include <vector>
|
||||
|
||||
class phys_obj {
|
||||
public:
|
||||
@ -8,4 +9,7 @@ class phys_obj {
|
||||
phys_obj(Quad object, 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);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user