Improve parallax mirroring algorithm
Replaces the iterative approach currently used by the standard fmod() function. Also fixes infinite looping that happens when the mirroring value is negative.
This commit is contained in:
parent
9e0b6057e7
commit
fbddc0b747
@ -92,23 +92,13 @@ 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;
|
||||
|
||||
if (mirroring.x) {
|
||||
|
||||
while( new_ofs.x>=0) {
|
||||
new_ofs.x -= mirroring.x*p_scale;
|
||||
}
|
||||
while(new_ofs.x < -mirroring.x*p_scale) {
|
||||
new_ofs.x += mirroring.x*p_scale;
|
||||
}
|
||||
double den = mirroring.x*p_scale;
|
||||
new_ofs.x = fmod(new_ofs.x,den) - (mirroring.x > 0 ? den : 0);
|
||||
}
|
||||
|
||||
if (mirroring.y) {
|
||||
|
||||
while( new_ofs.y>=0) {
|
||||
new_ofs.y -= mirroring.y*p_scale;
|
||||
}
|
||||
while(new_ofs.y < -mirroring.y*p_scale) {
|
||||
new_ofs.y += mirroring.y*p_scale;
|
||||
}
|
||||
double den = mirroring.y*p_scale;
|
||||
new_ofs.y = fmod(new_ofs.y,den) - (mirroring.y > 0 ? den : 0);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user