hey, just looking for a bit of advice on code readability, i've figured out a new and i hope better way to handle collisions but the when reviewing the code it all just blurrs together for me so is there some format teckneuqies i can use so its easier for me to read?
void b_Physics::Collision(const s_Polygon& Obstruct)
{
//store the new delta time to calculate the new speed
float Ntime = 0.0f;
//copy of this objects polygon for growing, only want to modify the speed
//not the polygon itself
s_Polygon Polygon = this->Object.Polygon;
//grow the copy of polygon in the direction that the object is moving then
//find the time of collision, move the object speed back in time so the object
//moves to the point of collision.
//
//to calculate the new speed i first need to get the time:
//polygon - object / speed or object - polygon / speed gets the time,
//which one depends on which returns a positive number because time can never be negative.
//
//then:
//object - polygon / time gets the new speed, positive or negative doesn't matter
//because it will return the correct speed depending on the direction, left or up
//will be negative and to move left or up needs a negative result.
//right or down will be positive and to move right or down needs a positive result
switch(this->Object.Motion.HorizDir){
case s_Motion::LEFT : Polygon.MinX = Polygon.MinX + this->Object.Motion.Xvel; break;
case s_Motion::RIGHT : Polygon.MaxX = Polygon.MaxX + this->Object.Motion.Xvel; break;
default : break;
}
if(this->Object.Polygon.MinY < Obstruct.MaxY && this->Object.Polygon.MaxY > Obstruct.MinY){
if(this->Object.Motion.HorizDir == s_Motion::LEFT && Polygon.MinX < Obstruct.MaxX){
Ntime = this->Object.Polygon.MinX - Obstruct.MaxX / this->Object.Motion.Xvel;
this->Object.Motion.Xvel = Obstruct.MaxX - this->Object.Polygon.MinX / Ntime;
}else if(this->Object.Motion.HorizDir == s_Motion::RIGHT && Polygon.MaxX > Obstruct.MinX){
Ntime = Obstruct.MinX - this->Object.Polygon.MaxX / this->Object.Motion.Xvel;
this->Object.Motion.Xvel = Obstruct.MinX - this->Object.Polygon.MaxX / Ntime;
}
}
switch(this->Object.Motion.VerticDir){
case s_Motion::UP : Polygon.MinY = Polygon.MinY + this->Object.Motion.Yvel; break;
case s_Motion::DOWN : Polygon.MaxY = Polygon.MaxY + this->Object.Motion.Yvel; break;
default : break;
}
if(this->Object.Polygon.MinX < Obstruct.MaxX && this->Object.Polygon.MaxX > Obstruct.MinX){
if(this->Object.Motion.VerticDir == s_Motion::UP && Polygon.MinY < Obstruct.MaxY){
Ntime = this->Object.Polygon.MinY - Obstruct.MaxY / this->Object.Motion.Yvel;
this->Object.Motion.Yvel = Obstruct.MaxY - this->Object.Polygon.MinY / Ntime;
}else if(this->Object.Motion.VerticDir == s_Motion::DOWN && Polygon.MaxY > Obstruct.MinY){
Ntime = Obstruct.MinY - this->Object.Polygon.MaxY / this->Object.Motion.Yvel;
this->Object.Motion.Yvel = Obstruct.MaxY - this->Object.Polygon.MinY / Ntime;
}
}
}
thats the function, its all one big blurr for my eyes and i have to strain them to read it.