Commit 9243a16c authored by Alexey Hohlov's avatar Alexey Hohlov
Browse files

У объектов теперь есть описывающие их многоугольники.

Коллизии теперь обсчитываются между многоугольниками.
parent 9b3f63e5
......@@ -2,26 +2,28 @@
IObjectDynamic::IObjectDynamic(CVector p, CBox b)
{
this->_pos = p;
this->_size = b;
this->_speed = 0;
this->_mass = 0;
this->_maxspeed = 0;
this->_accel = 0;
this->_rot_speed = 0;
this->_prev_pos = _pos;
this->_prev_angle = 0;
_pos = p;
_size = b;
_speed = 0;
_mass = 0;
_maxspeed = 0;
_accel = 0;
_rot_speed = 0;
_prev_pos = _pos;
_prev_angle = 0;
is_static = false;
}
float IObjectDynamic::speed()
{
return this->_speed;
return _speed;
}
void IObjectDynamic::speed(float speed)
{
this->_speed = speed;
_speed = speed;
}
float IObjectDynamic::rot_speed()
......@@ -31,20 +33,37 @@ float IObjectDynamic::rot_speed()
void IObjectDynamic::process()
{
this->_prev_pos = this->_pos;
this->_pos += CVector(_speed * Sin(-this->_angle), _speed * Cos(this->_angle));
if (_speed != 0) {
_prev_pos = _pos;
_pos += CVector(_speed * Sin(-_angle), _speed * Cos(_angle));
if (bounds) {
bounds->move(_pos);
}
}
if (_rot_speed != 0) {
_prev_angle = _angle;
this->_prev_angle = this->_angle;
this->_angle += this->_rot_speed;
if (_angle > 360) _angle -=360;
if (_angle < 0) _angle += 360;
if (this->_angle > 360) this->_angle -=360;
if (this->_angle < 0) this->_angle += 360;
_angle += _rot_speed;
if (bounds) {
bounds->rotate(_angle);
}
}
}
void IObjectDynamic::prev_pos()
{
this->_pos = this->_prev_pos;
this->_angle = this->_prev_angle;
_pos = _prev_pos;
_angle = _prev_angle;
if (bounds) {
bounds->move(_pos);
bounds->rotate(_angle);
}
}
IObjectDynamic::~IObjectDynamic()
......
......@@ -11,6 +11,8 @@ IObjectStatic::IObjectStatic()
_alpha = 1.0f;
bounds = NULL;
is_static = true;
}
IObjectStatic::IObjectStatic(CVector p, CBox b)
......@@ -21,6 +23,8 @@ IObjectStatic::IObjectStatic(CVector p, CBox b)
_destroyed = false;
bounds = NULL;
is_static = true;
}
void IObjectStatic::process(void)
......@@ -33,6 +37,32 @@ void IObjectStatic::process(void)
}
}
void IObjectStatic::pos(CVector p)
{
_pos = p;
if (bounds != nullptr) {
bounds->move(p);
}
}
CVector IObjectStatic::pos()
{
return _pos;
}
void IObjectStatic::angle(float a)
{
_angle = a;
if (bounds != nullptr) {
bounds->rotate(a);
}
}
float IObjectStatic::angle()
{
return _angle;
}
void IObjectStatic::LoadConfig(std::string name)
{
CXMLConfig& config = CXMLConfig::GetInstance();
......@@ -69,15 +99,25 @@ void IObjectStatic::LoadConfig(std::string name)
bool IObjectStatic::checkCollide(IObjectStatic *coll)
{
uint32_t i, j;
if (coll == NULL) {
return false;
}
if (coll->solid) {
if (colliderectA(this->pos().to_point(), this->size(), this->angle(),
coll->pos().to_point(), coll->size(), coll->angle())) {
return true;
if (bounds == nullptr || coll->bounds == nullptr) {
return false;
}
for (i = 0; i < bounds->vertex_count; i++) {
for (j = 0; j < coll->bounds->vertex_count; j++) {
if (IsLinesCross(bounds->vertex_arr_t[i], bounds->vertex_arr_t[(i + 1) % bounds->vertex_count],
coll->bounds->vertex_arr_t[j], coll->bounds->vertex_arr_t[(j + 1) % coll->bounds->vertex_count]))
return true;
}
}
}
return false;
......
......@@ -21,14 +21,14 @@ public:
IObject2D();
CVector pos();
float angle();
CBox size();
float alpha();
virtual CVector pos(void);
float angle(void);
CBox size(void);
float alpha(void);
void size(CBox s);
void angle(float a);
void pos(CVector p);
virtual void angle(float a);
virtual void pos(CVector p);
void alpha(float a);
virtual bool draw(void) { return false; }
......
......@@ -16,15 +16,19 @@ public:
IObjectStatic();
IObjectStatic(CVector pos, CBox b);
void setpos(CVector pos);
void process(void);
bool solid;
bool flat;
bool is_static;
CPoly * bounds;
void angle(float a);
float angle(void);
void pos(CVector p);
CVector pos(void);
virtual void collide(IObjectStatic *) {}
virtual void step(void) {}
virtual void destroy(void) { _destroyed = true; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment