From 90f3b394a8e747ecb29cf1e7ffa389c38f22fbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Brammer?= Date: Sun, 26 Sep 2010 20:46:13 +0200 Subject: [PATCH] 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. --- src/game/landscape/C4Sky.cpp | 4 ++-- src/game/object/C4Object.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/game/landscape/C4Sky.cpp b/src/game/landscape/C4Sky.cpp index bd1488506..6ee1d590c 100644 --- a/src/game/landscape/C4Sky.cpp +++ b/src/game/landscape/C4Sky.cpp @@ -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; diff --git a/src/game/object/C4Object.cpp b/src/game/object/C4Object.cpp index 726fbc0c5..ada79e9a1 100644 --- a/src/game/object/C4Object.cpp +++ b/src/game/object/C4Object.cpp @@ -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)