Improve parallax mirroring algorithm

Replaces the iterative approach currently used by an equivalent direct computation.
Also fixes infinite looping that happens when the mirroring value is negative.
This commit is contained in:
Pedro J. Estébanez 2016-06-27 10:32:14 +02:00
parent 2c59f77885
commit 6ce47d9b51

View file

@ -123,26 +123,15 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2& p_offset,float p_sca
Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale+motion_offset; Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale+motion_offset;
if (mirroring.x) { if (mirroring.x) {
double den = mirroring.x*p_scale;
while( new_ofs.x>=0) { new_ofs.x -= den*ceil(new_ofs.x/den);
new_ofs.x -= mirroring.x*p_scale;
}
while(new_ofs.x < -mirroring.x*p_scale) {
new_ofs.x += mirroring.x*p_scale;
}
} }
if (mirroring.y) { if (mirroring.y) {
double den = mirroring.y*p_scale;
while( new_ofs.y>=0) { new_ofs.y -= den*ceil(new_ofs.y/den);
new_ofs.y -= mirroring.y*p_scale;
}
while(new_ofs.y < -mirroring.y*p_scale) {
new_ofs.y += mirroring.y*p_scale;
}
} }
set_pos(new_ofs); set_pos(new_ofs);
set_scale(Vector2(1,1)*p_scale); set_scale(Vector2(1,1)*p_scale);