forked from Mirrors/openclonk
Object Draw: Fix parallax object positions when zoomed
Previously, the object position was used as if it represented the position in the landscape when viewed from 0/0 with the current Zoom, but it actually represents the position when viewed from 0/0 with Zoom 1.floating-point
parent
aa5db73404
commit
90f3b394a8
|
@ -231,8 +231,8 @@ void C4Sky::Draw(C4TargetFacet &cgo)
|
|||
// Step 1: project to landscape coordinates
|
||||
float resultzoom = 1.0 / (1.0 - (par - par/zoom));
|
||||
|
||||
float rx = ((1 - parx) * targetx) * resultzoom + fixtof(x);
|
||||
float ry = ((1 - pary) * targety) * resultzoom + fixtof(y);
|
||||
float rx = ((1 - parx) * targetx) * resultzoom + fixtof(x) / (parx + zoom - parx * zoom);
|
||||
float ry = ((1 - pary) * targety) * resultzoom + fixtof(y) / (pary + zoom - pary * zoom);
|
||||
|
||||
// Step 2: convert to screen coordinates
|
||||
float resultx = (rx - targetx) * zoom / resultzoom;
|
||||
|
|
|
@ -5161,11 +5161,12 @@ bool C4Object::GetDrawPosition(const C4TargetFacet & cgo, float objx, float objy
|
|||
|
||||
// Step 1: project to landscape coordinates
|
||||
resultzoom = 1.0 / (1.0 - (par - par/zoom));
|
||||
// it would be par / (1.0 - (par - par/zoom)) if objects would get smaller farther away
|
||||
if (resultzoom <= 0 || resultzoom > 100) // FIXME: optimize treshhold
|
||||
return false;
|
||||
|
||||
float rx = ((1 - parx) * targetx) * resultzoom + objx;
|
||||
float ry = ((1 - pary) * targety) * resultzoom + objy;
|
||||
float rx = ((1 - parx) * targetx) * resultzoom + objx / (parx + zoom - parx * zoom);
|
||||
float ry = ((1 - pary) * targety) * resultzoom + objy / (pary + zoom - pary * zoom);
|
||||
|
||||
// Step 2: convert to screen coordinates
|
||||
if(parx == 0 && fix_x < 0)
|
||||
|
|
Loading…
Reference in New Issue